2 #include "mpmc-queue.h"
4 template <typename t_element>
5 t_element * mpmc_boundq_1_alt<t_element>::read_fetch() {
6 // FIXME: We can have a relaxed for sure here since the next CAS
7 // will fix the problem
8 unsigned int rdwr = m_rdwr.load(mo_acquire);
11 rd = (rdwr>>16) & 0xFFFF;
14 if ( wr == rd ) // empty
17 if ( m_rdwr.compare_exchange_weak(rdwr,rdwr+(1<<16),mo_acq_rel) )
25 /********** Detected Admissibility (testcase1) **********/
26 while ( (m_written.load(mo_acquire) & 0xFFFF) != wr ) {
29 /** @OPDefine: true */
31 t_element * p = & ( m_array[ rd % t_size ] );
37 template <typename t_element>
38 void mpmc_boundq_1_alt<t_element>::read_consume(t_element *bin) {
39 /********** Detected Admissibility (testcase2) **********/
41 m_read.fetch_add(1,mo_release);
42 /** @OPDefine: true */
46 template <typename t_element>
47 t_element * mpmc_boundq_1_alt<t_element>::write_prepare() {
48 // FIXME: We can have a relaxed for sure here since the next CAS
49 // will fix the problem
50 unsigned int rdwr = m_rdwr.load(mo_acquire);
53 rd = (rdwr>>16) & 0xFFFF;
56 if ( wr == ((rd + t_size)&0xFFFF) ) // full
59 if ( m_rdwr.compare_exchange_weak(rdwr,(rd<<16) | ((wr+1)&0xFFFF),mo_acq_rel) )
67 /********** Detected Admissibility (testcase2) **********/
69 while ( (m_read.load(mo_acquire) & 0xFFFF) != rd ) {
72 /** @OPDefine: true */
74 t_element * p = & ( m_array[ wr % t_size ] );
79 template <typename t_element>
80 void mpmc_boundq_1_alt<t_element>::write_publish(t_element *bin)
82 /********** Detected Admissibility (testcase1) **********/
83 m_written.fetch_add(1,mo_release);
84 /** @OPDefine: true */
88 @Commutativity: write_prepare <-> write_publish (M1->C_RET == M2->bin)
89 @Commutativity: write_publish <-> read_fetch (M1->bin == M2->C_RET)
90 @Commutativity: read_fetch <-> read_consume (M1->C_RET == M2->bin)
91 @Commutativity: read_consume <-> write_prepare (M1->bin == M2->C_RET) */
94 mpmc_boundq_1_alt<int32_t>* createMPMC(int size) {
95 return new mpmc_boundq_1_alt<int32_t>(size);
98 void destroyMPMC(mpmc_boundq_1_alt<int32_t> *q) {
102 /** @PreCondition: */
103 int32_t * read_fetch(mpmc_boundq_1_alt<int32_t> *q) {
104 return q->read_fetch();
107 /** @PreCondition: */
108 void read_consume(mpmc_boundq_1_alt<int32_t> *q, int32_t *bin) {
109 q->read_consume(bin);
112 /** @PreCondition: */
113 int32_t * write_prepare(mpmc_boundq_1_alt<int32_t> *q) {
114 return q->write_prepare();
117 /** @PreCondition: */
118 void write_publish(mpmc_boundq_1_alt<int32_t> *q, int32_t *bin) {
119 q->write_publish(bin);