{
public:
Lock m_lock;
- typedef std::unique_lock<Lock> AutoLock;
+ typedef std::unique_lock<Lock> scoped_lock;
typedef std::unordered_set<
Value
, Hash
template <typename Key>
bool find( const Key& key )
{
- AutoLock al( m_lock );
+ scoped_lock al( m_lock );
return base_class::find( value_type(key) ) != base_class::end();
}
template <typename Key>
bool insert( Key const& key )
{
- AutoLock al( m_lock );
+ scoped_lock al( m_lock );
std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
return pRet.second;
}
template <typename Key, typename Func>
bool insert( Key const& key, Func func )
{
- AutoLock al( m_lock );
+ scoped_lock al( m_lock );
std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
if ( pRet.second ) {
func( *pRet.first );
template <typename T, typename Func>
std::pair<bool, bool> ensure( const T& key, Func func )
{
- AutoLock al( m_lock );
+ scoped_lock al( m_lock );
std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
if ( pRet.second ) {
func( true, *pRet.first, key );
template <typename Key>
bool erase( const Key& key )
{
- AutoLock al( m_lock );
+ scoped_lock al( m_lock );
return base_class::erase( value_type(key) ) != 0;
}
template <typename T, typename Func>
bool erase( const T& key, Func func )
{
- AutoLock al( m_lock );
+ scoped_lock al( m_lock );
typename base_class::iterator it = base_class::find( value_type(key) );
if ( it != base_class::end() ) {
func( *it );
+++ /dev/null
-//$$CDS-header$$
-
-#ifndef __CDSUNIT_STD_HASH_SET_VC_H
-#define __CDSUNIT_STD_HASH_SET_VC_H
-
-#include <hash_set>
-#include <mutex> //unique_lock
-
-namespace set2 {
-
- template <typename KeyVal, typename Hash, typename Less>
- struct hash_less: public stdext::hash_compare< KeyVal, Less >
- {
- typedef stdext::hash_compare< KeyVal, Less> base_class;
- size_t operator()(const KeyVal& kv) const
- {
- return Hash()(kv);
- }
-
- bool operator()(const KeyVal& kv1, const KeyVal& kv2) const
- {
- return base_class::operator()( kv1, kv2 );
- }
- };
-
- template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock, class Alloc = CDS_DEFAULT_ALLOCATOR>
- class StdHashSet: public stdext::hash_set<Value, hash_less<Value, Hash, Less >, Alloc>
- {
- public:
- Lock m_lock;
- typedef std::unique_lock<Lock> AutoLock;
- typedef stdext::hash_set<Value, hash_less<Value, Hash, Less >, Alloc> base_class;
-
- public:
- typedef typename base_class::value_type pair_type;
-
- StdHashSet( size_t nSetSize, size_t nLoadFactor )
- {}
-
- template <typename Key>
- bool find( const Key& key )
- {
- AutoLock al( m_lock );
- return base_class::find( value_type(key) ) != base_class::end();
- }
-
- template <typename Key>
- bool insert( Key const& key )
- {
- AutoLock al( m_lock );
- std::pair<base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
- return pRet.second;
- }
-
- template <typename Key, typename Func>
- bool insert( Key const& key, Func func )
- {
- AutoLock al( m_lock );
- std::pair<base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
- if ( pRet.second ) {
- func( *pRet.first );
- return true;
- }
- return false;
- }
-
- template <typename T, typename Func>
- std::pair<bool, bool> ensure( const T& key, Func func )
- {
- AutoLock al( m_lock );
- std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
- if ( pRet.second ) {
- func( true, *pRet.first, key );
- return std::make_pair( true, true );
- }
- else {
- func( false, *pRet.first, key );
- return std::make_pair( true, false );
- }
- }
-
- template <typename Key>
- bool erase( const Key& key )
- {
- AutoLock al( m_lock );
- return base_class::erase( value_type(key) ) != 0;
- }
-
- template <typename T, typename Func>
- bool erase( const T& key, Func func )
- {
- AutoLock al( m_lock );
- base_class::iterator it = base_class::find( key );
- if ( it != base_class::end() ) {
- func( *it );
- return base_class::erase( it ) != base_class::end();
- }
- return false;
- }
-
-
- std::ostream& dump( std::ostream& stm ) { return stm; }
- };
-} // namespace set2
-
-#endif // #ifndef __CDSUNIT_STD_HASH_SET_VC_H