mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 21:51:57 +00:00
add TSA support
This commit is contained in:
parent
534db794c1
commit
ae56ac1b56
@ -4,6 +4,7 @@
|
||||
|
||||
#include <Common/CancelToken.h>
|
||||
#include <base/types.h>
|
||||
#include <base/defines.h>
|
||||
#include <atomic>
|
||||
#include <shared_mutex> // for std::unique_lock and std::shared_lock
|
||||
|
||||
@ -13,7 +14,7 @@ namespace DB
|
||||
// Reimplementation of `std::shared_mutex` that can interoperate with thread cancelation via `CancelToken::signal()`.
|
||||
// It has cancelation point on waiting during `lock()` and `shared_lock()`.
|
||||
// NOTE: It has NO cancelation points on fast code path, when locking does not require waiting.
|
||||
class CancelableSharedMutex
|
||||
class TSA_CAPABILITY("CancelableSharedMutex") CancelableSharedMutex
|
||||
{
|
||||
public:
|
||||
CancelableSharedMutex();
|
||||
@ -22,14 +23,14 @@ public:
|
||||
CancelableSharedMutex & operator=(const CancelableSharedMutex &) = delete;
|
||||
|
||||
// Exclusive ownership
|
||||
void lock();
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
void lock() TSA_ACQUIRE();
|
||||
bool try_lock() TSA_TRY_ACQUIRE(true);
|
||||
void unlock() TSA_RELEASE();
|
||||
|
||||
// Shared ownership
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
void unlock_shared();
|
||||
void lock_shared() TSA_ACQUIRE_SHARED();
|
||||
bool try_lock_shared() TSA_TRY_ACQUIRE_SHARED(true);
|
||||
void unlock_shared() TSA_RELEASE_SHARED();
|
||||
|
||||
private:
|
||||
// State 64-bits layout:
|
||||
|
@ -3,6 +3,7 @@
|
||||
#ifdef OS_LINUX /// Because of futex
|
||||
|
||||
#include <base/types.h>
|
||||
#include <base/defines.h>
|
||||
#include <atomic>
|
||||
#include <shared_mutex> // for std::unique_lock and std::shared_lock
|
||||
|
||||
@ -10,7 +11,7 @@ namespace DB
|
||||
{
|
||||
|
||||
// Faster implementation of `std::shared_mutex` based on a pair of futexes
|
||||
class SharedMutex
|
||||
class TSA_CAPABILITY("SharedMutex") SharedMutex
|
||||
{
|
||||
public:
|
||||
SharedMutex();
|
||||
@ -19,14 +20,14 @@ public:
|
||||
SharedMutex & operator=(const SharedMutex &) = delete;
|
||||
|
||||
// Exclusive ownership
|
||||
void lock();
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
void lock() TSA_ACQUIRE();
|
||||
bool try_lock() TSA_TRY_ACQUIRE(true);
|
||||
void unlock() TSA_RELEASE();
|
||||
|
||||
// Shared ownership
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
void unlock_shared();
|
||||
void lock_shared() TSA_ACQUIRE_SHARED();
|
||||
bool try_lock_shared() TSA_TRY_ACQUIRE_SHARED(true);
|
||||
void unlock_shared() TSA_RELEASE_SHARED();
|
||||
|
||||
private:
|
||||
static constexpr UInt64 readers = (1ull << 32ull) - 1ull; // Lower 32 bits of state
|
||||
|
Loading…
Reference in New Issue
Block a user