proxygen
folly::detail::Sleeper Class Reference

#include <Sleeper.h>

Public Member Functions

 Sleeper () noexcept
 
void wait () noexcept
 

Static Public Member Functions

static void sleep () noexcept
 

Private Attributes

uint32_t spinCount
 

Static Private Attributes

static const uint32_t kMaxActiveSpin = 4000
 

Detailed Description

Definition at line 39 of file Sleeper.h.

Constructor & Destructor Documentation

folly::detail::Sleeper::Sleeper ( )
inlinenoexcept

Definition at line 45 of file Sleeper.h.

45 : spinCount(0) {}
uint32_t spinCount
Definition: Sleeper.h:42

Member Function Documentation

static void folly::detail::Sleeper::sleep ( )
inlinestaticnoexcept

Definition at line 47 of file Sleeper.h.

Referenced by folly::detail::distributed_mutex::spin(), and wait().

47  {
48  /*
49  * Always sleep 0.5ms, assuming this will make the kernel put
50  * us down for whatever its minimum timer resolution is (in
51  * linux this varies by kernel version from 1ms to 10ms).
52  */
53  struct timespec ts = {0, 500000};
54  nanosleep(&ts, nullptr);
55  }
void folly::detail::Sleeper::wait ( )
inlinenoexcept

Definition at line 57 of file Sleeper.h.

References folly::asm_volatile_pause(), sleep(), and spinCount.

Referenced by folly::MicroSpinLock::lock(), and folly::PicoSpinLock< uintptr_t >::lock().

57  {
58  if (spinCount < kMaxActiveSpin) {
59  ++spinCount;
61  } else {
62  sleep();
63  }
64  }
static const uint32_t kMaxActiveSpin
Definition: Sleeper.h:40
static void sleep() noexcept
Definition: Sleeper.h:47
uint32_t spinCount
Definition: Sleeper.h:42
void asm_volatile_pause()
Definition: Asm.h:37

Member Data Documentation

const uint32_t folly::detail::Sleeper::kMaxActiveSpin = 4000
staticprivate

Definition at line 40 of file Sleeper.h.

uint32_t folly::detail::Sleeper::spinCount
private

Definition at line 42 of file Sleeper.h.

Referenced by wait().


The documentation for this class was generated from the following file: