Tkrzw
Public Member Functions | List of all members
tkrzw::ScopedHashLock< SHAREDMUTEX > Class Template Referencefinal

Scoped lock with a mutex for a hash table. More...

#include <tkrzw_thread_util.h>

Public Member Functions

 ScopedHashLock (HashMutex< SHAREDMUTEX > &mutex, std::string_view data, bool writable)
 Constructor to lock one bucket. More...
 
 ScopedHashLock (HashMutex< SHAREDMUTEX > &mutex, bool writable)
 Constructro to lock all buckets. More...
 
 ScopedHashLock (HashMutex< SHAREDMUTEX > &mutex, int64_t bucket_index, bool writable)
 Constructor to lock the bucket specific to an index. More...
 
 ~ScopedHashLock ()
 Destructor. More...
 
 ScopedHashLock (const ScopedHashLock &rhs)=delete
 Copy and assignment are disabled. More...
 
ScopedHashLockoperator= (const ScopedHashLock &rhs)=delete
 
int64_t GetBucketIndex () const
 Gets the index of the bucket. More...
 

Detailed Description

template<typename SHAREDMUTEX = std::shared_mutex>
class tkrzw::ScopedHashLock< SHAREDMUTEX >

Scoped lock with a mutex for a hash table.

Constructor & Destructor Documentation

◆ ScopedHashLock() [1/4]

template<typename SHAREDMUTEX >
tkrzw::ScopedHashLock< SHAREDMUTEX >::ScopedHashLock ( HashMutex< SHAREDMUTEX > &  mutex,
std::string_view  data,
bool  writable 
)

Constructor to lock one bucket.

Parameters
mutexA hash mutex.
dataThe data to be set in the hash table.
writableTrue for exclusive lock or false for shared lock.

◆ ScopedHashLock() [2/4]

template<typename SHAREDMUTEX >
tkrzw::ScopedHashLock< SHAREDMUTEX >::ScopedHashLock ( HashMutex< SHAREDMUTEX > &  mutex,
bool  writable 
)

Constructro to lock all buckets.

Parameters
mutexA hash mutex.
writableTrue for exclusive lock or false for shared lock.

◆ ScopedHashLock() [3/4]

template<typename SHAREDMUTEX >
tkrzw::ScopedHashLock< SHAREDMUTEX >::ScopedHashLock ( HashMutex< SHAREDMUTEX > &  mutex,
int64_t  bucket_index,
bool  writable 
)

Constructor to lock the bucket specific to an index.

Parameters
mutexA hash mutex.
bucket_indexThe index of the bucket to lock.
writableTrue for exclusive lock or false for shared lock.

Only this constructor can fail. It is because of rehashing.

◆ ~ScopedHashLock()

template<typename SHAREDMUTEX >
tkrzw::ScopedHashLock< SHAREDMUTEX >::~ScopedHashLock

Destructor.

◆ ScopedHashLock() [4/4]

template<typename SHAREDMUTEX = std::shared_mutex>
tkrzw::ScopedHashLock< SHAREDMUTEX >::ScopedHashLock ( const ScopedHashLock< SHAREDMUTEX > &  rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ GetBucketIndex()

template<typename SHAREDMUTEX >
int64_t tkrzw::ScopedHashLock< SHAREDMUTEX >::GetBucketIndex

Gets the index of the bucket.

Returns
The index of the bucket which the data should belong to. The return value is always INT64MIN if all bucket is locked. The return value is -1 if the constructor taking a bucket index is called and it fails to lock the bucket because of rehashing.