aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/refcount.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/generic/refcount.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/refcount.h')
-rw-r--r--util/generic/refcount.h110
1 files changed, 55 insertions, 55 deletions
diff --git a/util/generic/refcount.h b/util/generic/refcount.h
index 966e853b77..7d53dc29d4 100644
--- a/util/generic/refcount.h
+++ b/util/generic/refcount.h
@@ -1,42 +1,42 @@
#pragma once
-
-#include <util/system/guard.h>
-#include <util/system/atomic.h>
+
+#include <util/system/guard.h>
+#include <util/system/atomic.h>
#include <util/system/defaults.h>
#include <util/system/yassert.h>
+
+template <class TCounterCheckPolicy>
+class TSimpleCounterTemplate: public TCounterCheckPolicy {
+ using TCounterCheckPolicy::Check;
-template <class TCounterCheckPolicy>
-class TSimpleCounterTemplate: public TCounterCheckPolicy {
- using TCounterCheckPolicy::Check;
-
-public:
+public:
inline TSimpleCounterTemplate(long initial = 0) noexcept
- : Counter_(initial)
- {
- }
-
+ : Counter_(initial)
+ {
+ }
+
inline ~TSimpleCounterTemplate() {
- Check();
- }
-
+ Check();
+ }
+
inline TAtomicBase Add(TAtomicBase d) noexcept {
- Check();
+ Check();
return Counter_ += d;
- }
+ }
inline TAtomicBase Inc() noexcept {
return Add(1);
- }
+ }
inline TAtomicBase Sub(TAtomicBase d) noexcept {
- Check();
- return Counter_ -= d;
- }
-
+ Check();
+ return Counter_ -= d;
+ }
+
inline TAtomicBase Dec() noexcept {
- return Sub(1);
- }
-
+ return Sub(1);
+ }
+
inline bool TryWeakInc() noexcept {
if (!Counter_) {
return false;
@@ -49,10 +49,10 @@ public:
}
inline TAtomicBase Val() const noexcept {
- return Counter_;
- }
-
-private:
+ return Counter_;
+ }
+
+private:
TAtomicBase Counter_;
};
@@ -64,7 +64,7 @@ protected:
#if defined(SIMPLE_COUNTER_THREAD_CHECK)
- #include <util/system/thread.i>
+ #include <util/system/thread.i>
class TCheckPolicy {
public:
@@ -83,7 +83,7 @@ private:
#else
using TCheckPolicy = TNoCheckPolicy;
#endif
-
+
// Use this one if access from multiple threads to your pointer is an error and you want to enforce thread checks
using TSimpleCounter = TSimpleCounterTemplate<TCheckPolicy>;
// Use this one if you do want to share the pointer between threads, omit thread checks and do the synchronization yourself
@@ -100,35 +100,35 @@ struct TCommonLockOps<TSimpleCounterTemplate<TCounterCheckPolicy>> {
}
};
-class TAtomicCounter {
-public:
+class TAtomicCounter {
+public:
inline TAtomicCounter(long initial = 0) noexcept
- : Counter_(initial)
- {
- }
-
+ : Counter_(initial)
+ {
+ }
+
inline ~TAtomicCounter() = default;
-
+
inline TAtomicBase Add(TAtomicBase d) noexcept {
return AtomicAdd(Counter_, d);
- }
+ }
inline TAtomicBase Inc() noexcept {
return Add(1);
- }
-
+ }
+
inline TAtomicBase Sub(TAtomicBase d) noexcept {
- return AtomicSub(Counter_, d);
- }
+ return AtomicSub(Counter_, d);
+ }
inline TAtomicBase Dec() noexcept {
- return Sub(1);
- }
-
+ return Sub(1);
+ }
+
inline TAtomicBase Val() const noexcept {
- return AtomicGet(Counter_);
- }
-
+ return AtomicGet(Counter_);
+ }
+
inline bool TryWeakInc() noexcept {
while (true) {
intptr_t curValue = Counter_;
@@ -146,16 +146,16 @@ public:
}
}
-private:
- TAtomic Counter_;
-};
-
-template <>
+private:
+ TAtomic Counter_;
+};
+
+template <>
struct TCommonLockOps<TAtomicCounter> {
static inline void Acquire(TAtomicCounter* t) noexcept {
t->Inc();
}
-
+
static inline void Release(TAtomicCounter* t) noexcept {
t->Dec();
}