proxygen
ShardedAtomicInt Struct Reference

Public Member Functions

void inc (int64_t val=1)
 
int64_t readFast ()
 
int64_t readFull ()
 

Public Attributes

std::atomic< int64_tints_ [kBuckets_]
 

Static Public Attributes

static const int64_t kBuckets_ = 2048
 

Detailed Description

Definition at line 303 of file ThreadCachedIntTest.cpp.

Member Function Documentation

void ShardedAtomicInt::inc ( int64_t  val = 1)
inline

Definition at line 307 of file ThreadCachedIntTest.cpp.

References folly::getCurrentThreadID(), folly::hash::twang_mix64(), and val.

307  {
309  std::atomic_fetch_add(&ints_[buck], val);
310  }
std::atomic< int64_t > ints_[kBuckets_]
double val
Definition: String.cpp:273
static const int64_t kBuckets_
uint64_t twang_mix64(uint64_t key) noexcept
Definition: Hash.h:49
uint64_t getCurrentThreadID()
Definition: ThreadId.h:42
int64_t ShardedAtomicInt::readFast ( )
inline

Definition at line 313 of file ThreadCachedIntTest.cpp.

References FOR_EACH_RANGE, i, and int64_t.

Referenced by BENCHMARK().

313  {
314  int64_t ret = 0;
315  static const int numToRead = 8;
316  FOR_EACH_RANGE (i, 0, numToRead) {
317  ret += ints_[i].load(std::memory_order_relaxed);
318  }
319  return ret * (kBuckets_ / numToRead);
320  }
std::atomic< int64_t > ints_[kBuckets_]
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static const int64_t kBuckets_
int64_t ShardedAtomicInt::readFull ( )
inline

Definition at line 323 of file ThreadCachedIntTest.cpp.

References i, and int64_t.

Referenced by BENCHMARK().

323  {
324  int64_t ret = 0;
325  for (auto& i : ints_) {
326  // Fun fact - using memory_order_consume below reduces perf 30-40% in high
327  // contention benchmarks.
328  ret += i.load(std::memory_order_relaxed);
329  }
330  return ret;
331  }
std::atomic< int64_t > ints_[kBuckets_]

Member Data Documentation

std::atomic<int64_t> ShardedAtomicInt::ints_[kBuckets_]

Definition at line 305 of file ThreadCachedIntTest.cpp.

const int64_t ShardedAtomicInt::kBuckets_ = 2048
static

Definition at line 304 of file ThreadCachedIntTest.cpp.


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