X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=mpmc-queue%2Fmpmc-queue.h;h=918415fa99278e0a8cc3d47622f84de00749445c;hp=fdfbb365164a0ab8ef0ab87e75b044b62cae6388;hb=77847ecd3fa6a643302770491928787ba143cde1;hpb=3f557d137e70ca9da76ce84ec663da53e266e272;ds=sidebyside diff --git a/mpmc-queue/mpmc-queue.h b/mpmc-queue/mpmc-queue.h index fdfbb36..918415f 100644 --- a/mpmc-queue/mpmc-queue.h +++ b/mpmc-queue/mpmc-queue.h @@ -36,14 +36,16 @@ public: if ( wr == rd ) // empty return false; - if ( m_rdwr.compare_exchange(rdwr,rdwr+(1<<16),mo_acq_rel) ) + if ( m_rdwr.compare_exchange_weak(rdwr,rdwr+(1<<16),mo_acq_rel) ) break; + else + thrd_yield(); } // (*1) rl::backoff bo; while ( (m_written.load(mo_acquire) & 0xFFFF) != wr ) { - bo.yield(); + thrd_yield(); } t_element * p = & ( m_array[ rd % t_size ] ); @@ -67,14 +69,16 @@ public: if ( wr == ((rd + t_size)&0xFFFF) ) // full return NULL; - if ( m_rdwr.compare_exchange(rdwr,(rd<<16) | ((wr+1)&0xFFFF),mo_acq_rel) ) + if ( m_rdwr.compare_exchange_weak(rdwr,(rd<<16) | ((wr+1)&0xFFFF),mo_acq_rel) ) break; + else + thrd_yield(); } // (*1) rl::backoff bo; while ( (m_read.load(mo_acquire) & 0xFFFF) != rd ) { - bo.yield(); + thrd_yield(); } t_element * p = & ( m_array[ wr % t_size ] );