//$$CDS-header$$
+#include <functional>
+#include <vector>
+#include <mutex> //unique_lock
+
#include "set2/set_types.h"
#include "cppunit/thread.h"
#include <cds/lock/spinlock.h>
-#include <vector>
-#include <boost/ref.hpp>
namespace set2 {
struct value_type {
size_t nKey;
size_t nData;
- CDS_ATOMIC::atomic<size_t> nEnsureCall;
- bool volatile bInitialized;
- std::thread::id threadId; // insert thread id
+ atomics::atomic<size_t> nEnsureCall;
+ bool volatile bInitialized;
+ cds::OS::ThreadId threadId ; // insert thread id
typedef cds::lock::Spinlock< cds::backoff::pause > lock_type;
mutable lock_type m_access;
, nData(0)
, nEnsureCall(0)
, bInitialized( false )
- , threadId( std::this_thread::get_id() )
+ , threadId( cds::OS::get_current_thread_id() )
{}
value_type( value_type const& s )
: nKey(s.nKey)
, nData(s.nData)
- , nEnsureCall(s.nEnsureCall.load(CDS_ATOMIC::memory_order_relaxed))
+ , nEnsureCall(s.nEnsureCall.load(atomics::memory_order_relaxed))
, bInitialized( s.bInitialized )
- , threadId( std::this_thread::get_id() )
+ , threadId( cds::OS::get_current_thread_id() )
{}
// boost::container::flat_map requires operator =
{
nKey = v.nKey;
nData = v.nData;
- nEnsureCall.store( v.nEnsureCall.load(CDS_ATOMIC::memory_order_relaxed), CDS_ATOMIC::memory_order_relaxed );
+ nEnsureCall.store( v.nEnsureCall.load(atomics::memory_order_relaxed), atomics::memory_order_relaxed );
bInitialized = v.bInitialized;
return *this;
void operator()( keyval_type& val )
{
- cds::lock::scoped_lock< typename value_type::lock_type> ac( val.val.m_access );
+ std::unique_lock< typename value_type::lock_type> ac( val.val.m_access );
val.val.nKey = val.key;
val.val.nData = val.key * 8;
if ( m_nThreadNo & 1 ) {
for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) {
for ( size_t * p = pKeyFirst; p < pKeyLast; ++p ) {
- if ( rSet.insert( *p, cds::ref(func) ) )
+ if ( rSet.insert( *p, std::ref(func) ) )
++m_nInsertSuccess;
else
++m_nInsertFailed;
else {
for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) {
for ( size_t * p = pKeyLast - 1; p >= pKeyFirst; --p ) {
- if ( rSet.insert( *p, cds::ref(func) ) )
+ if ( rSet.insert( *p, std::ref(func) ) )
++m_nInsertSuccess;
else
++m_nInsertFailed;
, nModified(0)
{}
- void operator()( bool bNew, keyval_type& val, size_t nKey )
+ void operator()( bool bNew, keyval_type& val, size_t /*nKey*/ )
{
- cds::lock::scoped_lock<typename value_type::lock_type> ac( val.val.m_access );
+ std::unique_lock<typename value_type::lock_type> ac( val.val.m_access );
if ( !val.val.bInitialized )
{
val.val.nKey = val.key;
++nCreated;
}
else {
- val.val.nEnsureCall.fetch_add( 1, CDS_ATOMIC::memory_order_relaxed );
+ val.val.nEnsureCall.fetch_add( 1, atomics::memory_order_relaxed );
++nModified;
}
}
if ( m_nThreadNo & 1 ) {
for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) {
for ( size_t * p = pKeyFirst; p < pKeyLast; ++p ) {
- std::pair<bool, bool> ret = rSet.ensure( *p, cds::ref( func ) );
+ std::pair<bool, bool> ret = rSet.ensure( *p, std::ref( func ) );
if ( ret.first ) {
if ( ret.second )
++m_nEnsureCreated;
else {
for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) {
for ( size_t * p = pKeyLast - 1 ; p >= pKeyFirst; --p ) {
- std::pair<bool, bool> ret = rSet.ensure( *p, cds::ref( func ) );
+ std::pair<bool, bool> ret = rSet.ensure( *p, std::ref( func ) );
if ( ret.first ) {
if ( ret.second )
++m_nEnsureCreated;
while ( true ) {
bool bBkoff = false;
{
- cds::lock::scoped_lock< typename value_type::lock_type> ac( item.val.m_access );
+ std::unique_lock< typename value_type::lock_type> ac( item.val.m_access );
if ( item.val.bInitialized ) {
if ( m_cnt.nKeyExpected == item.val.nKey && m_cnt.nKeyExpected * 8 == item.val.nData )
++m_cnt.nSuccessItem;
for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) {
for ( size_t * p = pKeyFirst; p < pKeyLast; ++p ) {
func.m_cnt.nKeyExpected = *p;
- if ( rSet.erase( *p, cds::ref(func) ))
+ if ( rSet.erase( *p, std::ref(func) ))
++m_nDeleteSuccess;
else
++m_nDeleteFailed;
for ( size_t nPass = 0; nPass < c_nThreadPassCount; ++nPass ) {
for ( size_t * p = pKeyLast - 1; p >= pKeyFirst; --p ) {
func.m_cnt.nKeyExpected = *p;
- if ( rSet.erase( *p, cds::ref(func) ))
+ if ( rSet.erase( *p, std::ref(func) ))
++m_nDeleteSuccess;
else
++m_nDeleteFailed;