aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/deprecated/galloc/internal_spinlock.h
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2023-12-02 01:45:21 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2023-12-02 02:42:50 +0300
commit9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c (patch)
tree9f88a486917d371d099cd712efd91b4c122d209d /contrib/deprecated/galloc/internal_spinlock.h
parent32fb6dda1feb24f9ab69ece5df0cb9ec238ca5e6 (diff)
downloadydb-9c43d58f75cf086b744cf4fe2ae180e8f37e4a0c.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/deprecated/galloc/internal_spinlock.h')
-rw-r--r--contrib/deprecated/galloc/internal_spinlock.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/contrib/deprecated/galloc/internal_spinlock.h b/contrib/deprecated/galloc/internal_spinlock.h
new file mode 100644
index 0000000000..e7086f2da2
--- /dev/null
+++ b/contrib/deprecated/galloc/internal_spinlock.h
@@ -0,0 +1,47 @@
+#pragma once
+
+extern "C" {
+ #include "hack.h"
+ #include "spinlock.h"
+}
+
+#define SPINLOCK_INITIALIZER { _SPINLOCK_INITIALIZER }
+
+struct TCMalloc_SpinLock {
+ volatile spinlock_t private_lockword_;
+
+ inline void Init() noexcept {
+ private_lockword_ = _SPINLOCK_INITIALIZER;
+ }
+
+ inline void Finalize() noexcept {
+ }
+
+ inline void Lock() noexcept {
+ _SPINLOCK(&private_lockword_);
+ }
+
+ inline void Unlock() noexcept {
+ _SPINUNLOCK(&private_lockword_);
+ }
+};
+
+class TCMalloc_SpinLockHolder {
+ private:
+ TCMalloc_SpinLock* lock_;
+
+ public:
+ inline explicit TCMalloc_SpinLockHolder(TCMalloc_SpinLock* l)
+ : lock_(l)
+ {
+ l->Lock();
+ }
+
+ inline ~TCMalloc_SpinLockHolder() {
+ lock_->Unlock();
+ }
+};
+
+// Short-hands for convenient use by tcmalloc.cc
+typedef TCMalloc_SpinLock SpinLock;
+typedef TCMalloc_SpinLockHolder SpinLockHolder;