From 65590d04529c4ad7f586703e7875a94a5cbe2a9e Mon Sep 17 00:00:00 2001 From: khizmax Date: Wed, 1 Oct 2014 15:45:37 +0400 Subject: [PATCH] Replace cds::lock::scoped_lock with std::unique_lock, remove cds/lock/scoped_lock.h --- cds/container/rwqueue.h | 3 +- cds/gc/ptb/ptb.h | 8 +-- cds/intrusive/cuckoo_set.h | 8 +-- cds/intrusive/impl/lazy_list.h | 3 +- cds/intrusive/lazy_list_nogc.h | 5 +- cds/intrusive/lazy_list_rcu.h | 5 +- cds/intrusive/striped_set/striping_policy.h | 6 +- cds/intrusive/treiber_stack.h | 4 +- cds/lock/array.h | 31 +++++---- cds/lock/scoped_lock.h | 72 --------------------- cds/lock/spinlock.h | 1 - cds/memory/michael/allocator.h | 7 +- cds/urcu/details/gpb.h | 2 +- cds/urcu/details/gpi.h | 3 +- cds/urcu/details/gpt.h | 3 +- cds/urcu/details/sig_buffered.h | 2 +- cds/urcu/details/sig_threaded.h | 3 +- projects/Win/vc12/cds.vcxproj | 1 - projects/Win/vc12/cds.vcxproj.filters | 3 - tests/unit/map2/map_insdel_func.cpp | 7 +- tests/unit/map2/std_hash_map_gcc.h | 3 +- tests/unit/map2/std_hash_map_vc.h | 3 +- tests/unit/map2/std_map_gcc.h | 3 +- tests/unit/map2/std_map_vc.h | 3 +- tests/unit/pqueue/std_pqueue.h | 17 +---- tests/unit/queue/std_queue.h | 5 +- tests/unit/set2/set_insdel_func.h | 7 +- tests/unit/set2/std_hash_set_std.h | 3 +- tests/unit/set2/std_hash_set_vc9.h | 3 +- tests/unit/set2/std_set.h | 3 +- 30 files changed, 79 insertions(+), 148 deletions(-) delete mode 100644 cds/lock/scoped_lock.h diff --git a/cds/container/rwqueue.h b/cds/container/rwqueue.h index b63d2ad0..6754b6bc 100644 --- a/cds/container/rwqueue.h +++ b/cds/container/rwqueue.h @@ -5,6 +5,7 @@ #include #include // ref +#include // unique_lock #include #include #include @@ -106,7 +107,7 @@ namespace cds { namespace container { protected: //@cond typedef typename opt::details::alignment_setter< lock_type, options::alignment >::type aligned_lock_type; - typedef cds::lock::scoped_lock auto_lock; + typedef std::unique_lock auto_lock; typedef cds::details::Allocator< node_type, allocator_type > node_allocator; item_counter m_ItemCounter; diff --git a/cds/gc/ptb/ptb.h b/cds/gc/ptb/ptb.h index b4d716b2..7cb31de6 100644 --- a/cds/gc/ptb/ptb.h +++ b/cds/gc/ptb/ptb.h @@ -3,12 +3,12 @@ #ifndef __CDS_GC_PTB_PASS_THE_BUCK_H #define __CDS_GC_PTB_PASS_THE_BUCK_H +#include // unique_lock #include #include #include #include #include - #include #if CDS_COMPILER == CDS_COMPILER_MSVC @@ -173,7 +173,7 @@ namespace cds { namespace gc { details::guard_data * pGuard; { - cds::lock::scoped_lock al( m_freeListLock ); + std::unique_lock al( m_freeListLock ); pGuard = m_FreeGuardList.load(atomics::memory_order_relaxed); if ( pGuard ) m_FreeGuardList.store( pGuard->pNextFree.load(atomics::memory_order_relaxed), atomics::memory_order_relaxed ); @@ -193,7 +193,7 @@ namespace cds { namespace gc { { pGuard->pPost.store( nullptr, atomics::memory_order_relaxed ); - cds::lock::scoped_lock al( m_freeListLock ); + std::unique_lock al( m_freeListLock ); pGuard->pNextFree.store( m_FreeGuardList.load(atomics::memory_order_relaxed), atomics::memory_order_relaxed ); m_FreeGuardList.store( pGuard, atomics::memory_order_relaxed ); } @@ -245,7 +245,7 @@ namespace cds { namespace gc { pLast = p; } - cds::lock::scoped_lock al( m_freeListLock ); + std::unique_lock al( m_freeListLock ); pLast->pNextFree.store( m_FreeGuardList.load(atomics::memory_order_relaxed), atomics::memory_order_relaxed ); m_FreeGuardList.store( pList, atomics::memory_order_relaxed ); } diff --git a/cds/intrusive/cuckoo_set.h b/cds/intrusive/cuckoo_set.h index 2b42e763..e54f8237 100644 --- a/cds/intrusive/cuckoo_set.h +++ b/cds/intrusive/cuckoo_set.h @@ -391,9 +391,9 @@ namespace cds { namespace intrusive { lock_array( size_t nCapacity ): lock_array_type( nCapacity, typename lock_array_type::select_cell_policy(nCapacity) ) {} }; - class scoped_lock: public cds::lock::scoped_lock< lock_array_type > + class scoped_lock: public std::unique_lock< lock_array_type > { - typedef cds::lock::scoped_lock< lock_array_type > base_class; + typedef std::unique_lock< lock_array_type > base_class; public: scoped_lock( lock_array& arrLock, size_t nHash ): base_class( arrLock, nHash ) {} }; @@ -464,7 +464,7 @@ namespace cds { namespace intrusive { }; class scoped_full_lock { - cds::lock::scoped_lock< lock_array_type > m_guard; + std::unique_lock< lock_array_type > m_guard; public: scoped_full_lock( striping& policy ) : m_guard( policy.m_Locks[0] ) @@ -650,7 +650,7 @@ namespace cds { namespace intrusive { typedef cds::OS::ThreadId threadId_t; typedef cds::lock::Spin spinlock_type; - typedef cds::lock::scoped_lock< spinlock_type > scoped_spinlock; + typedef std::unique_lock< spinlock_type > scoped_spinlock; //@endcond protected: diff --git a/cds/intrusive/impl/lazy_list.h b/cds/intrusive/impl/lazy_list.h index c0d64a96..4c302892 100644 --- a/cds/intrusive/impl/lazy_list.h +++ b/cds/intrusive/impl/lazy_list.h @@ -3,6 +3,7 @@ #ifndef __CDS_INTRUSIVE_IMPL_LAZY_LIST_H #define __CDS_INTRUSIVE_IMPL_LAZY_LIST_H +#include // unique_lock #include #include @@ -1126,7 +1127,7 @@ namespace cds { namespace intrusive { search( pHead, val, pos, cmp ); if ( pos.pCur != tail() ) { - cds::lock::scoped_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); + std::unique_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); if ( !pos.pCur->is_marked() && cmp( *node_traits::to_value_ptr( *pos.pCur ), val ) == 0 ) { diff --git a/cds/intrusive/lazy_list_nogc.h b/cds/intrusive/lazy_list_nogc.h index a50e742a..e2b6f96e 100644 --- a/cds/intrusive/lazy_list_nogc.h +++ b/cds/intrusive/lazy_list_nogc.h @@ -3,6 +3,7 @@ #ifndef __CDS_INTRUSIVE_LAZY_LIST_NOGC_H #define __CDS_INTRUSIVE_LAZY_LIST_NOGC_H +#include // unique_lock #include #include @@ -612,7 +613,7 @@ namespace cds { namespace intrusive { search( pHead, val, pos, cmp ); if ( pos.pCur != &m_Tail ) { - cds::lock::scoped_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); + std::unique_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); if ( cmp( *node_traits::to_value_ptr( *pos.pCur ), val ) == 0 ) { f( *node_traits::to_value_ptr( *pos.pCur ), val ); @@ -638,7 +639,7 @@ namespace cds { namespace intrusive { search( pHead, val, pos, cmp ); if ( pos.pCur != &m_Tail ) { - cds::lock::scoped_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); + std::unique_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); if ( cmp( *node_traits::to_value_ptr( *pos.pCur ), val ) == 0 ) { return iterator( pos.pCur ); diff --git a/cds/intrusive/lazy_list_rcu.h b/cds/intrusive/lazy_list_rcu.h index 43ddce46..cc2acce5 100644 --- a/cds/intrusive/lazy_list_rcu.h +++ b/cds/intrusive/lazy_list_rcu.h @@ -3,6 +3,7 @@ #ifndef __CDS_INTRUSIVE_LAZY_LIST_RCU_H #define __CDS_INTRUSIVE_LAZY_LIST_RCU_H +#include // unique_lock #include #include #include @@ -1105,7 +1106,7 @@ namespace cds { namespace intrusive { rcu_lock l( bLock ); search( pHead, val, pos, cmp ); if ( pos.pCur != &m_Tail ) { - cds::lock::scoped_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); + std::unique_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); if ( cmp( *node_traits::to_value_ptr( *pos.pCur ), val ) == 0 ) { f( *node_traits::to_value_ptr( *pos.pCur ), val ); @@ -1131,7 +1132,7 @@ namespace cds { namespace intrusive { search( pHead, val, pos, cmp ); if ( pos.pCur != &m_Tail ) { - cds::lock::scoped_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); + std::unique_lock< typename node_type::lock_type> al( pos.pCur->m_Lock ); if ( cmp( *node_traits::to_value_ptr( *pos.pCur ), val ) == 0 ) { return const_iterator( pos.pCur ); diff --git a/cds/intrusive/striped_set/striping_policy.h b/cds/intrusive/striped_set/striping_policy.h index f3798601..a70858b9 100644 --- a/cds/intrusive/striped_set/striping_policy.h +++ b/cds/intrusive/striped_set/striping_policy.h @@ -145,7 +145,7 @@ namespace cds { namespace intrusive { namespace striped_set { typedef cds::OS::ThreadId threadId_t; typedef cds::lock::Spin spinlock_type; - typedef cds::lock::scoped_lock< spinlock_type > scoped_spinlock; + typedef std::unique_lock< spinlock_type > scoped_spinlock; //@endcond protected: @@ -273,11 +273,11 @@ namespace cds { namespace intrusive { namespace striped_set { public: //@cond class scoped_cell_lock { - cds::lock::scoped_lock< lock_type > m_guard; + std::unique_lock< lock_type > m_guard; public: scoped_cell_lock( refinable& policy, size_t nHash ) - : m_guard( policy.acquire( nHash ), true ) + : m_guard( policy.acquire( nHash ), std::adopt_lock_t() ) {} }; diff --git a/cds/intrusive/treiber_stack.h b/cds/intrusive/treiber_stack.h index 09b03c3e..5e5083c1 100644 --- a/cds/intrusive/treiber_stack.h +++ b/cds/intrusive/treiber_stack.h @@ -5,11 +5,11 @@ #include #include // ref +#include // unique_lock #include #include #include #include -#include #include namespace cds { namespace intrusive { @@ -183,7 +183,7 @@ namespace cds { namespace intrusive { op_collided = 2 }; - typedef cds::lock::scoped_lock< elimination_lock_type > slot_scoped_lock; + typedef std::unique_lock< elimination_lock_type > slot_scoped_lock; public: elimination_backoff() diff --git a/cds/lock/array.h b/cds/lock/array.h index ce94189a..ff8db6b8 100644 --- a/cds/lock/array.h +++ b/cds/lock/array.h @@ -3,10 +3,9 @@ #ifndef __CDS_LOCK_ARRAY_H #define __CDS_LOCK_ARRAY_H +#include //unique_lock #include -#include #include - #include namespace cds { namespace lock { @@ -273,38 +272,44 @@ namespace cds { namespace lock { } }; +}} // namespace cds::lock + +//@cond +namespace std { + /// Specialization \ref scoped_lock for lock::array template - class scoped_lock< cds::lock::array< Lock, SelectPolicy, Alloc > >: public cds::details::noncopyable + class unique_lock< cds::lock::array< Lock, SelectPolicy, Alloc > > { public: - typedef cds::lock::array< Lock, SelectPolicy, Alloc > lock_array_type ; ///< Lock array type + typedef cds::lock::array< Lock, SelectPolicy, Alloc > lock_array_type; ///< Lock array type private: - //@cond lock_array_type& m_arrLocks; size_t m_nLockGuarded; - static const size_t c_nLockAll = ~size_t(0); - //@endcond + static const size_t c_nLockAll = ~size_t( 0 ); public: /// Onws the lock array \p arrLocks and locks a cell determined by \p hint parameter template - scoped_lock( lock_array_type& arrLocks, Q const& hint ) + unique_lock( lock_array_type& arrLocks, Q const& hint ) : m_arrLocks( arrLocks ) - , m_nLockGuarded( arrLocks.lock( hint )) + , m_nLockGuarded( arrLocks.lock( hint ) ) {} /// Locks all from \p arrLocks array - scoped_lock( lock_array_type& arrLocks ) + unique_lock( lock_array_type& arrLocks ) : m_arrLocks( arrLocks ) , m_nLockGuarded( c_nLockAll ) { arrLocks.lock_all(); } - ~scoped_lock() + unique_lock() = delete; + unique_lock( unique_lock const& ) = delete; + + ~unique_lock() { if ( m_nLockGuarded == c_nLockAll ) m_arrLocks.unlock_all(); @@ -312,7 +317,7 @@ namespace cds { namespace lock { m_arrLocks.unlock( m_nLockGuarded ); } }; - -}} // namespace cds::lock +} // namespace std +//@endcond #endif // #ifndef __CDS_LOCK_ARRAY_H diff --git a/cds/lock/scoped_lock.h b/cds/lock/scoped_lock.h deleted file mode 100644 index 13b78f25..00000000 --- a/cds/lock/scoped_lock.h +++ /dev/null @@ -1,72 +0,0 @@ -//$$CDS-header$$-2 - -#ifndef __CDS_LOCK_SCOPED_LOCK_H -#define __CDS_LOCK_SCOPED_LOCK_H - -#include -#include - -namespace cds { namespace lock { - - /// Scoped lock - /** - - An object of type \p scoped_lock controls the ownership of a lockable object within a scope. - A \p scoped_lock object maintains ownership of a lockable object throughout the \p scoped_lock object’s lifetime. - The behavior of a program is undefined if the lockable object does not exist for the entire lifetime - of the \p scoped_lock object. - The supplied \p Lock type shall have two methods: \p lock and \p unlock. - - The constructor locks the wrapped lock object, the destructor unlocks it. - - Scoped lock is not copy-constructible and not default-constructible. - - This class is similar to \p std::lock_quard - */ - template - class scoped_lock: public cds::details::noncopyable - { - public: - typedef Lock lock_type ; ///< Lock type - - protected: - lock_type& m_Lock ; ///< Owned lock object - - protected: - //@cond - // Only for internal use!!! - scoped_lock() - {} - //@endcond - public: - /// Get ownership of lock object \p l and calls l.lock() - scoped_lock( lock_type& l ) - : m_Lock( l ) - { - l.lock(); - } - - /// Get ownership of lock object \p l and conditionally locks it - /** - The constructor calls l.lock() only if \p bAlreadyLocked is \p false. - If \p bAlreadyLocked is \p true, no locking is performed. - - In any case, the destructor of \p scoped_lock object invokes l.unlock(). - */ - scoped_lock( lock_type& l, bool bAlreadyLocked ) - : m_Lock( l ) - { - if ( !bAlreadyLocked ) - l.lock(); - } - - /// Unlock underlying lock object and release ownership - ~scoped_lock() - { - m_Lock.unlock(); - } - }; -}} // namespace cds::lock - - -#endif // #ifndef __CDS_LOCK_SCOPED_LOCK_H diff --git a/cds/lock/spinlock.h b/cds/lock/spinlock.h index 8bd65fb0..37842a53 100644 --- a/cds/lock/spinlock.h +++ b/cds/lock/spinlock.h @@ -15,7 +15,6 @@ #include #include #include -#include #include diff --git a/cds/memory/michael/allocator.h b/cds/memory/michael/allocator.h index 8da141ef..35f4ffae 100644 --- a/cds/memory/michael/allocator.h +++ b/cds/memory/michael/allocator.h @@ -15,6 +15,8 @@ 2011.01.02 khizmax Created */ +#include +#include // unique_lock #include #include #include @@ -30,7 +32,6 @@ #include #include -#include #include namespace cds { @@ -306,7 +307,7 @@ namespace michael { typedef details::free_list_locked_hook item_hook; typedef Lock lock_type; protected: - typedef cds::lock::scoped_lock auto_lock; + typedef std::unique_lock auto_lock; mutable lock_type m_access; //@endcond @@ -360,7 +361,7 @@ namespace michael { typedef details::partial_list_locked_hook item_hook; typedef Lock lock_type; protected: - typedef cds::lock::scoped_lock auto_lock; + typedef std::unique_lock auto_lock; mutable lock_type m_access; //@endcond diff --git a/cds/urcu/details/gpb.h b/cds/urcu/details/gpb.h index c822268d..9e8c4c63 100644 --- a/cds/urcu/details/gpb.h +++ b/cds/urcu/details/gpb.h @@ -196,7 +196,7 @@ namespace cds { namespace urcu { uint64_t nEpoch; atomics::atomic_thread_fence( atomics::memory_order_acquire ); { - cds::lock::scoped_lock sl( m_Lock ); + std::unique_lock sl( m_Lock ); if ( ep.m_p && m_Buffer.push( ep ) ) return false; nEpoch = m_nCurEpoch.fetch_add( 1, atomics::memory_order_relaxed ); diff --git a/cds/urcu/details/gpi.h b/cds/urcu/details/gpi.h index f4eee83e..a9ffda3b 100644 --- a/cds/urcu/details/gpi.h +++ b/cds/urcu/details/gpi.h @@ -6,7 +6,6 @@ #include #include #include -#include namespace cds { namespace urcu { @@ -136,7 +135,7 @@ namespace cds { namespace urcu { { atomics::atomic_thread_fence( atomics::memory_order_acquire ); { - cds::lock::scoped_lock sl( m_Lock ); + std::unique_lock sl( m_Lock ); flip_and_wait(); flip_and_wait(); } diff --git a/cds/urcu/details/gpt.h b/cds/urcu/details/gpt.h index 31e03c21..f7712634 100644 --- a/cds/urcu/details/gpt.h +++ b/cds/urcu/details/gpt.h @@ -3,6 +3,7 @@ #ifndef _CDS_URCU_DETAILS_GPT_H #define _CDS_URCU_DETAILS_GPT_H +#include //unique_lock #include #include #include @@ -200,7 +201,7 @@ namespace cds { namespace urcu { atomics::atomic_thread_fence( atomics::memory_order_acquire ); { - cds::lock::scoped_lock sl( m_Lock ); + std::unique_lock sl( m_Lock ); flip_and_wait(); flip_and_wait(); diff --git a/cds/urcu/details/sig_buffered.h b/cds/urcu/details/sig_buffered.h index 69530feb..13786c7d 100644 --- a/cds/urcu/details/sig_buffered.h +++ b/cds/urcu/details/sig_buffered.h @@ -194,7 +194,7 @@ namespace cds { namespace urcu { uint64_t nEpoch; atomics::atomic_thread_fence( atomics::memory_order_acquire ); { - cds::lock::scoped_lock sl( m_Lock ); + std::unique_lock sl( m_Lock ); if ( ep.m_p && m_Buffer.push( ep ) && m_Buffer.size() < capacity()) return false; nEpoch = m_nCurEpoch.fetch_add( 1, atomics::memory_order_relaxed ); diff --git a/cds/urcu/details/sig_threaded.h b/cds/urcu/details/sig_threaded.h index ca3795e8..2f5db2e2 100644 --- a/cds/urcu/details/sig_threaded.h +++ b/cds/urcu/details/sig_threaded.h @@ -3,6 +3,7 @@ #ifndef _CDS_URCU_DETAILS_SIG_THREADED_H #define _CDS_URCU_DETAILS_SIG_THREADED_H +#include //unique_lock #include #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED @@ -199,7 +200,7 @@ namespace cds { namespace urcu { atomics::atomic_thread_fence( atomics::memory_order_acquire ); { - cds::lock::scoped_lock sl( m_Lock ); + std::unique_lock sl( m_Lock ); back_off bkOff; base_class::force_membar_all_threads( bkOff ); diff --git a/projects/Win/vc12/cds.vcxproj b/projects/Win/vc12/cds.vcxproj index cea98ac6..1a36281a 100644 --- a/projects/Win/vc12/cds.vcxproj +++ b/projects/Win/vc12/cds.vcxproj @@ -787,7 +787,6 @@ - diff --git a/projects/Win/vc12/cds.vcxproj.filters b/projects/Win/vc12/cds.vcxproj.filters index 74f37bfe..f4b36afd 100644 --- a/projects/Win/vc12/cds.vcxproj.filters +++ b/projects/Win/vc12/cds.vcxproj.filters @@ -1175,9 +1175,6 @@ Header Files\cds\lock - - Header Files\cds\lock - Header Files\cds\container\details diff --git a/tests/unit/map2/map_insdel_func.cpp b/tests/unit/map2/map_insdel_func.cpp index d8a6e00c..719c1c7c 100644 --- a/tests/unit/map2/map_insdel_func.cpp +++ b/tests/unit/map2/map_insdel_func.cpp @@ -1,6 +1,7 @@ //$$CDS-header$$ #include +#include //unique_lock #include "map2/map_types.h" #include "cppunit/thread.h" @@ -89,7 +90,7 @@ namespace map2 { void operator()( pair_type& val ) { - cds::lock::scoped_lock< typename value_type::lock_type> ac( val.second.m_access ); + std::unique_lock< typename value_type::lock_type> ac( val.second.m_access ); val.second.nKey = val.first; val.second.nData = val.first * 8; @@ -182,7 +183,7 @@ namespace map2 { void operator()( bool bNew, pair_type& val ) { - cds::lock::scoped_lock ac( val.second.m_access ); + std::unique_lock ac( val.second.m_access ); if ( bNew ) { ++nCreated; val.second.nKey = val.first; @@ -305,7 +306,7 @@ namespace map2 { { while ( true ) { if ( item.second.bInitialized.load( atomics::memory_order_relaxed )) { - cds::lock::scoped_lock< typename value_type::lock_type> ac( item.second.m_access ); + std::unique_lock< typename value_type::lock_type> ac( item.second.m_access ); if ( m_cnt.nKeyExpected == item.second.nKey && m_cnt.nKeyExpected * 8 == item.second.nData ) ++m_cnt.nSuccessItem; diff --git a/tests/unit/map2/std_hash_map_gcc.h b/tests/unit/map2/std_hash_map_gcc.h index 6140f45d..5cb7ac81 100644 --- a/tests/unit/map2/std_hash_map_gcc.h +++ b/tests/unit/map2/std_hash_map_gcc.h @@ -3,6 +3,7 @@ #ifndef __CDSUNIT_STD_HASH_MAP_GCC_H #define __CDSUNIT_STD_HASH_MAP_GCC_H +#include //unique_lock #include #include // ref @@ -21,7 +22,7 @@ namespace map2 { { public: Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef std::unordered_map< Key, Value , std::hash diff --git a/tests/unit/map2/std_hash_map_vc.h b/tests/unit/map2/std_hash_map_vc.h index 5e9c8c8b..9acb49aa 100644 --- a/tests/unit/map2/std_hash_map_vc.h +++ b/tests/unit/map2/std_hash_map_vc.h @@ -5,6 +5,7 @@ #include #include // ref +#include //unique_lock namespace map2 { template @@ -12,7 +13,7 @@ namespace map2 { { public: Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef stdext::hash_map >, Alloc> base_class; public: typedef typename base_class::mapped_type value_type; diff --git a/tests/unit/map2/std_map_gcc.h b/tests/unit/map2/std_map_gcc.h index 67c3d698..c798c9cc 100644 --- a/tests/unit/map2/std_map_gcc.h +++ b/tests/unit/map2/std_map_gcc.h @@ -5,6 +5,7 @@ #include #include // ref +#include //unique_lock namespace map2 { @@ -14,7 +15,7 @@ namespace map2 { class StdMap: public std::map, Alloc> { Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef std::map, Alloc> base_class; public: typedef typename base_class::mapped_type value_type; diff --git a/tests/unit/map2/std_map_vc.h b/tests/unit/map2/std_map_vc.h index 655b4d80..021005e4 100644 --- a/tests/unit/map2/std_map_vc.h +++ b/tests/unit/map2/std_map_vc.h @@ -5,13 +5,14 @@ #include #include // ref +#include //unique_lock namespace map2 { template class StdMap: public std::map, Alloc> { Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef std::map, Alloc> base_class; public: typedef typename base_class::mapped_type value_type; diff --git a/tests/unit/pqueue/std_pqueue.h b/tests/unit/pqueue/std_pqueue.h index 85c19e6c..d95a88c4 100644 --- a/tests/unit/pqueue/std_pqueue.h +++ b/tests/unit/pqueue/std_pqueue.h @@ -4,6 +4,7 @@ #define __CDSUNIT_STD_PQUEUE_H #include +#include //unique_lock namespace pqueue { @@ -18,21 +19,7 @@ namespace pqueue { pqueue_type m_PQueue; mutable Lock m_Lock; - struct scoped_lock - { - Lock& m_lock; - - scoped_lock( Lock& l ) - : m_lock(l) - { - l.lock(); - } - - ~scoped_lock() - { - m_lock.unlock(); - } - }; + typedef std::unique_lock scoped_lock; public: bool push( value_type const& val ) diff --git a/tests/unit/queue/std_queue.h b/tests/unit/queue/std_queue.h index 6ac385ba..5c6d33e6 100644 --- a/tests/unit/queue/std_queue.h +++ b/tests/unit/queue/std_queue.h @@ -3,6 +3,7 @@ #ifndef __UNIT_QUEUE_STD_QUEUE_H #define __UNIT_QUEUE_STD_QUEUE_H +#include //unique_lock #include #include @@ -17,7 +18,7 @@ namespace queue { public: bool enqueue( const T& data ) { - cds::lock::scoped_lock a(m_Locker); + std::unique_lock a(m_Locker); base_class::push( data ); return true; @@ -25,7 +26,7 @@ namespace queue { bool push( const T& data ) { return enqueue( data ) ; } bool dequeue( T& data ) { - cds::lock::scoped_lock a(m_Locker); + std::unique_lock a(m_Locker); if ( base_class::empty() ) return false; diff --git a/tests/unit/set2/set_insdel_func.h b/tests/unit/set2/set_insdel_func.h index 11f6bfbc..df0ebc04 100644 --- a/tests/unit/set2/set_insdel_func.h +++ b/tests/unit/set2/set_insdel_func.h @@ -2,6 +2,7 @@ #include #include +#include //unique_lock #include "set2/set_types.h" #include "cppunit/thread.h" @@ -90,7 +91,7 @@ namespace set2 { 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; @@ -185,7 +186,7 @@ namespace set2 { void operator()( bool bNew, keyval_type& val, size_t nKey ) { - cds::lock::scoped_lock ac( val.val.m_access ); + std::unique_lock ac( val.val.m_access ); if ( !val.val.bInitialized ) { val.val.nKey = val.key; @@ -312,7 +313,7 @@ namespace set2 { 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; diff --git a/tests/unit/set2/std_hash_set_std.h b/tests/unit/set2/std_hash_set_std.h index fca8b853..55845ce9 100644 --- a/tests/unit/set2/std_hash_set_std.h +++ b/tests/unit/set2/std_hash_set_std.h @@ -5,6 +5,7 @@ #include #include // ref +#include //unique_lock namespace set2 { @@ -21,7 +22,7 @@ namespace set2 { { public: Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef std::unordered_set< Value , Hash diff --git a/tests/unit/set2/std_hash_set_vc9.h b/tests/unit/set2/std_hash_set_vc9.h index 7282ce03..64ed6977 100644 --- a/tests/unit/set2/std_hash_set_vc9.h +++ b/tests/unit/set2/std_hash_set_vc9.h @@ -4,6 +4,7 @@ #define __CDSUNIT_STD_HASH_SET_VC_H #include +#include //unique_lock namespace set2 { @@ -27,7 +28,7 @@ namespace set2 { { public: Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef stdext::hash_set, Alloc> base_class; public: diff --git a/tests/unit/set2/std_set.h b/tests/unit/set2/std_set.h index 2f55586c..fa9a270d 100644 --- a/tests/unit/set2/std_set.h +++ b/tests/unit/set2/std_set.h @@ -5,6 +5,7 @@ #include #include // ref +#include //unique_lock namespace set2 { template { Lock m_lock; - typedef cds::lock::scoped_lock AutoLock; + typedef std::unique_lock AutoLock; typedef std::set base_class; public: typedef typename base_class::key_type value_type; -- 2.34.1