Scoped lock with a mutex for a hash table.
More...
#include <tkrzw_thread_util.h>
Scoped lock with a mutex for a hash table.
◆ ScopedHashLock() [1/3]
| tkrzw::ScopedHashLock::ScopedHashLock |
( |
HashMutex & |
mutex, |
|
|
std::string_view |
data, |
|
|
bool |
writable |
|
) |
| |
Constructor to lock one bucket.
- Parameters
-
| mutex | A hash mutex. |
| data | The data to be set in the hash table. |
| writable | True for exclusive lock or false for shared lock. |
◆ ScopedHashLock() [2/3]
| tkrzw::ScopedHashLock::ScopedHashLock |
( |
HashMutex & |
mutex, |
|
|
bool |
writable |
|
) |
| |
Constructro to lock all buckets.
- Parameters
-
| mutex | A hash mutex. |
| writable | True for exclusive lock or false for shared lock. |
◆ ScopedHashLock() [3/3]
| tkrzw::ScopedHashLock::ScopedHashLock |
( |
HashMutex & |
mutex, |
|
|
int64_t |
bucket_index, |
|
|
bool |
writable |
|
) |
| |
Constructor to lock the bucket specific to an index.
- Parameters
-
| mutex | A hash mutex. |
| bucket_index | The index of the bucket to lock. |
| writable | True for exclusive lock or false for shared lock. Only this constructor can fail. It is because of rehashing. |
◆ ~ScopedHashLock()
| tkrzw::ScopedHashLock::~ScopedHashLock |
( |
| ) |
|
◆ GetBucketIndex()
| int64_t tkrzw::ScopedHashLock::GetBucketIndex |
( |
| ) |
const |
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.