From: Kyle Hegeman Date: Wed, 13 May 2015 11:54:30 +0000 (-0400) Subject: implement emplace using equeue_with X-Git-Tag: v2.1.0~241^2 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c0319def4567356f6f4e286bd0eefd6f372023c1;p=libcds.git implement emplace using equeue_with --- diff --git a/cds/container/vyukov_mpmc_cycle_queue.h b/cds/container/vyukov_mpmc_cycle_queue.h index 0244e360..7e5dc889 100644 --- a/cds/container/vyukov_mpmc_cycle_queue.h +++ b/cds/container/vyukov_mpmc_cycle_queue.h @@ -266,33 +266,13 @@ namespace cds { namespace container { /// Enqueues data of type \ref value_type constructed with std::forward(args)... template bool emplace( Args&&... args ) - { - cell_type* cell; - size_t pos = m_posEnqueue.load(memory_model::memory_order_relaxed); - - for (;;) - { - cell = &m_buffer[pos & m_nBufferMask]; - size_t seq = cell->sequence.load(memory_model::memory_order_acquire); - - intptr_t dif = static_cast(seq) - static_cast(pos); - - if (dif == 0) { - if ( m_posEnqueue.compare_exchange_weak(pos, pos + 1, memory_model::memory_order_relaxed, atomics::memory_order_relaxed)) - break; - } - else if (dif < 0) - return false; - else - pos = m_posEnqueue.load(memory_model::memory_order_relaxed); - } - - new ( &cell->data ) value_type( std::forward(args)... ); - - cell->sequence.store(pos + 1, memory_model::memory_order_release); - ++m_ItemCounter; - - return true; + { +#if (CDS_COMPILER == CDS_COMPILER_GCC) && (CDS_COMPILER_VERSION < 40900) + //work around unsupported feature in g++ 4.8 for forwarding parameter packs to lambda. + return enqueue_with ( std::bind([]( value_type& dest,Args ... args ){ new ( &dest ) value_type( std::forward(args)... );}, std::placeholders::_1 ,args...)); +#else + return enqueue_with( [&args ...]( value_type& dest ){ new ( &dest ) value_type( std::forward(args)... ); }); +#endif } /// Dequeues a value using a functor