TestQueue Struct Reference

Public Member Functions

 TestQueue ()
 
 ~TestQueue ()
 
bool Push ()
 
bool Pop ()
 
bool Empty ()
 

Public Attributes

std::atomic< intval_
 

Static Public Attributes

static const int kQueueSize = 10
 

Constructor & Destructor Documentation

◆ TestQueue()

TestQueue::TestQueue ( )
inline
44 : val_() {}
std::atomic< int > val_
Definition: threads_eventcount.cpp:41

◆ ~TestQueue()

TestQueue::~TestQueue ( )
inline
46 { VERIFY_IS_EQUAL(val_.load(), 0); }
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367

References val_, and VERIFY_IS_EQUAL.

Member Function Documentation

◆ Empty()

bool TestQueue::Empty ( )
inline
68 { return val_.load(std::memory_order_relaxed) == 0; }

References val_.

◆ Pop()

bool TestQueue::Pop ( )
inline
58  {
59  int val = val_.load(std::memory_order_relaxed);
60  for (;;) {
61  VERIFY_GE(val, 0);
63  if (val == 0) return false;
64  if (val_.compare_exchange_weak(val, val - 1, std::memory_order_relaxed)) return true;
65  }
66  }
#define VERIFY_GE(a, b)
Definition: main.h:364
#define VERIFY_LE(a, b)
Definition: main.h:365
val
Definition: calibrate.py:119
static const int kQueueSize
Definition: threads_eventcount.cpp:42

References kQueueSize, calibrate::val, val_, VERIFY_GE, and VERIFY_LE.

◆ Push()

bool TestQueue::Push ( )
inline
48  {
49  int val = val_.load(std::memory_order_relaxed);
50  for (;;) {
51  VERIFY_GE(val, 0);
53  if (val == kQueueSize) return false;
54  if (val_.compare_exchange_weak(val, val + 1, std::memory_order_relaxed)) return true;
55  }
56  }

References kQueueSize, calibrate::val, val_, VERIFY_GE, and VERIFY_LE.

Member Data Documentation

◆ kQueueSize

const int TestQueue::kQueueSize = 10
static

Referenced by Pop(), and Push().

◆ val_

std::atomic<int> TestQueue::val_

Referenced by Empty(), Pop(), Push(), and ~TestQueue().


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