Changeset View
Changeset View
Standalone View
Standalone View
src/test/rcu_tests.cpp
Show All 34 Lines | |||||
#define WAIT_FOR_STEP(step) \ | #define WAIT_FOR_STEP(step) \ | ||||
do { \ | do { \ | ||||
cond.notify_all(); \ | cond.notify_all(); \ | ||||
} while (!cond.wait_for(lock, std::chrono::milliseconds(1), \ | } while (!cond.wait_for(lock, std::chrono::milliseconds(1), \ | ||||
[&] { return otherstep == step; })) | [&] { return otherstep == step; })) | ||||
void synchronize(std::atomic<RCUTestStep> &step, | void synchronize(std::atomic<RCUTestStep> &step, | ||||
const std::atomic<RCUTestStep> &otherstep, | const std::atomic<RCUTestStep> &otherstep, Mutex &cs, | ||||
CWaitableCriticalSection &cs, std::condition_variable &cond, | std::condition_variable &cond, | ||||
std::atomic<uint64_t> &syncRev) { | std::atomic<uint64_t> &syncRev) { | ||||
assert(step == RCUTestStep::Init); | assert(step == RCUTestStep::Init); | ||||
{ | { | ||||
WAIT_LOCK(cs, lock); | WAIT_LOCK(cs, lock); | ||||
step = RCUTestStep::Locked; | step = RCUTestStep::Locked; | ||||
// Wait for our lock to be acknowledged. | // Wait for our lock to be acknowledged. | ||||
Show All 18 Lines | void synchronize(std::atomic<RCUTestStep> &step, | ||||
RCULock::synchronize(); | RCULock::synchronize(); | ||||
// Update step. | // Update step. | ||||
step = RCUTestStep::Synchronized; | step = RCUTestStep::Synchronized; | ||||
} | } | ||||
void lockAndWaitForSynchronize(std::atomic<RCUTestStep> &step, | void lockAndWaitForSynchronize(std::atomic<RCUTestStep> &step, | ||||
const std::atomic<RCUTestStep> &otherstep, | const std::atomic<RCUTestStep> &otherstep, | ||||
CWaitableCriticalSection &cs, | Mutex &cs, std::condition_variable &cond, | ||||
std::condition_variable &cond, | |||||
std::atomic<uint64_t> &syncRev) { | std::atomic<uint64_t> &syncRev) { | ||||
assert(step == RCUTestStep::Init); | assert(step == RCUTestStep::Init); | ||||
WAIT_LOCK(cs, lock); | WAIT_LOCK(cs, lock); | ||||
// Wait for th eother thread to be locked. | // Wait for th eother thread to be locked. | ||||
WAIT_FOR_STEP(RCUTestStep::Locked); | WAIT_FOR_STEP(RCUTestStep::Locked); | ||||
step = RCUTestStep::LockAck; | step = RCUTestStep::LockAck; | ||||
Show All 17 Lines | void lockAndWaitForSynchronize(std::atomic<RCUTestStep> &step, | ||||
assert(RCUTest::hasSyncedTo(syncRev) >= syncRev); | assert(RCUTest::hasSyncedTo(syncRev) >= syncRev); | ||||
WAIT_FOR_STEP(RCUTestStep::Synchronized); | WAIT_FOR_STEP(RCUTestStep::Synchronized); | ||||
} | } | ||||
static const int COUNT = 128; | static const int COUNT = 128; | ||||
BOOST_AUTO_TEST_CASE(synchronize_test) { | BOOST_AUTO_TEST_CASE(synchronize_test) { | ||||
CWaitableCriticalSection cs; | Mutex cs; | ||||
std::condition_variable cond; | std::condition_variable cond; | ||||
std::atomic<RCUTestStep> parentstep; | std::atomic<RCUTestStep> parentstep; | ||||
std::atomic<RCUTestStep> childstep; | std::atomic<RCUTestStep> childstep; | ||||
std::atomic<uint64_t> syncRev; | std::atomic<uint64_t> syncRev; | ||||
for (int i = 0; i < COUNT; i++) { | for (int i = 0; i < COUNT; i++) { | ||||
parentstep = RCUTestStep::Init; | parentstep = RCUTestStep::Init; | ||||
childstep = RCUTestStep::Init; | childstep = RCUTestStep::Init; | ||||
▲ Show 20 Lines • Show All 269 Lines • Show Last 20 Lines |