diff --git a/src/Common/CancelableSharedMutex.h b/src/Common/CancelableSharedMutex.h index f989e8d5beb..0e5f48b4a93 100644 --- a/src/Common/CancelableSharedMutex.h +++ b/src/Common/CancelableSharedMutex.h @@ -4,6 +4,7 @@ #include #include +#include #include #include // 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: diff --git a/src/Common/SharedMutex.h b/src/Common/SharedMutex.h index ebe730ca419..26c649c6fa8 100644 --- a/src/Common/SharedMutex.h +++ b/src/Common/SharedMutex.h @@ -3,6 +3,7 @@ #ifdef OS_LINUX /// Because of futex #include +#include #include #include // 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