/// Metafunction converting option list to traits
/**
\p Options are:
- - \p opt::lock_type - mutex type, default is \p cds::sync::spin
- - \p opt::back_off - back-off strategy, defalt is \p cds::backoff::delay_of<2>
- - \p opt::allocator - allocator type, default is \ref CDS_DEFAULT_ALLOCATOR
+ - any \p cds::algo::flat_combining::make_traits options
- \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default)
- - \p opt::memory_model - C++ memory ordering model.
- List of all available memory ordering see opt::memory_model.
- Default if cds::opt::v:relaxed_ordering
- \p opt::enable_elimination - enable/disable operation \ref cds_elimination_description "elimination"
By default, the elimination is disabled. For queue, the elimination is possible if the queue
is empty.
op_push_back_move, ///< Push back (move semantics)
op_pop_front, ///< Pop front
op_pop_back, ///< Pop back
- op_clear, ///< Clear
- op_empty ///< Empty
+ op_clear ///< Clear
};
/// Flat combining publication list record
protected:
//@cond
- fc_kernel m_FlatCombining;
- deque_type m_Deque;
+ mutable fc_kernel m_FlatCombining;
+ deque_type m_Deque;
//@endcond
public:
value_type const& val ///< Value to be copied to inserted element
)
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
pRec->pValPush = &val;
if ( c_bEliminationEnabled )
value_type&& val ///< Value to be moved to inserted element
)
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
pRec->pValPush = &val;
if ( c_bEliminationEnabled )
value_type const& val ///< Value to be copied to inserted element
)
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
pRec->pValPush = &val;
if ( c_bEliminationEnabled )
value_type&& val ///< Value to be moved to inserted element
)
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
pRec->pValPush = &val;
if ( c_bEliminationEnabled )
value_type& val ///< Target to be received the copy of removed element
)
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
pRec->pValPop = &val;
if ( c_bEliminationEnabled )
value_type& val ///< Target to be received the copy of removed element
)
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
pRec->pValPop = &val;
if ( c_bEliminationEnabled )
/// Clears the deque
void clear()
{
- fc_record * pRec = m_FlatCombining.acquire_record();
+ auto pRec = m_FlatCombining.acquire_record();
if ( c_bEliminationEnabled )
m_FlatCombining.batch_combine( op_clear, pRec, *this );
/**
If the combining is in process the function waits while combining done.
*/
- bool empty()
+ bool empty() const
{
- fc_record * pRec = m_FlatCombining.acquire_record();
-
- if ( c_bEliminationEnabled )
- m_FlatCombining.batch_combine( op_empty, pRec, *this );
- else
- m_FlatCombining.combine( op_empty, pRec, *this );
-
- assert( pRec->is_done() );
- m_FlatCombining.release_record( pRec );
- return pRec->bEmpty;
+ bool bRet = false;
+ auto const& deq = m_Deque;
+ m_FlatCombining.invoke_exclusive( [&deq, &bRet]() { bRet = deq.empty(); } );
+ return bRet;
}
/// Internal statistics
while ( !m_Deque.empty() )
m_Deque.pop_front();
break;
- case op_empty:
- pRec->bEmpty = m_Deque.empty();
- break;
default:
assert(false);
break;