aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/spin_wait.cpp
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/system/spin_wait.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/spin_wait.cpp')
-rw-r--r--util/system/spin_wait.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/util/system/spin_wait.cpp b/util/system/spin_wait.cpp
index e27045e74f..b04552d915 100644
--- a/util/system/spin_wait.cpp
+++ b/util/system/spin_wait.cpp
@@ -1,40 +1,40 @@
-#include "spin_wait.h"
-#include "yield.h"
-#include "compat.h"
-#include "thread.h"
-#include "spinlock.h"
-
-#include <util/digest/numeric.h>
-#include <util/generic/utility.h>
-
-template <class T>
+#include "spin_wait.h"
+#include "yield.h"
+#include "compat.h"
+#include "thread.h"
+#include "spinlock.h"
+
+#include <util/digest/numeric.h>
+#include <util/generic/utility.h>
+
+template <class T>
static inline T RandomizeSleepTime(T t) noexcept {
- static TAtomic counter = 0;
- const T rndNum = IntHash((T)AtomicIncrement(counter));
-
- return (t * (T)4 + (rndNum % t) * (T)2) / (T)5;
-}
-
-//arbitrary values
-#define MIN_SLEEP_TIME 500
+ static TAtomic counter = 0;
+ const T rndNum = IntHash((T)AtomicIncrement(counter));
+
+ return (t * (T)4 + (rndNum % t) * (T)2) / (T)5;
+}
+
+//arbitrary values
+#define MIN_SLEEP_TIME 500
#define MAX_SPIN_COUNT 0x7FF
-
-TSpinWait::TSpinWait() noexcept
- : T(MIN_SLEEP_TIME)
- , C(0)
-{
-}
-
-void TSpinWait::Sleep() noexcept {
- ++C;
-
- if (C == MAX_SPIN_COUNT) {
- ThreadYield();
- } else if ((C & MAX_SPIN_COUNT) == 0) {
- usleep(RandomizeSleepTime(T));
-
- T = Min<unsigned>((T * 3) / 2, 20000);
- } else {
- SpinLockPause();
- }
-}
+
+TSpinWait::TSpinWait() noexcept
+ : T(MIN_SLEEP_TIME)
+ , C(0)
+{
+}
+
+void TSpinWait::Sleep() noexcept {
+ ++C;
+
+ if (C == MAX_SPIN_COUNT) {
+ ThreadYield();
+ } else if ((C & MAX_SPIN_COUNT) == 0) {
+ usleep(RandomizeSleepTime(T));
+
+ T = Min<unsigned>((T * 3) / 2, 20000);
+ } else {
+ SpinLockPause();
+ }
+}