Commit bf8a9074 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by facebook-github-bot-0

Fix RefCountTest and RCURefCount race

Reviewed By: alikhtarov

Differential Revision: D2741459

fb-gh-sync-id: c4bd068cf735ae25364edba40960096fb35e8c43
parent dee3186e
......@@ -40,12 +40,13 @@ class RCURefCount {
auto& localCount = *localCount_;
std::lock_guard<RCUReadLock> lg(RCUReadLock::instance());
auto state = state_.load();
if (LIKELY(state_ == State::LOCAL)) {
if (LIKELY(state == State::LOCAL)) {
++localCount;
return 42;
} else if (state_ == State::GLOBAL_TRANSITION) {
} else if (state == State::GLOBAL_TRANSITION) {
++globalCount_;
return 42;
......@@ -67,15 +68,16 @@ class RCURefCount {
auto& localCount = *localCount_;
std::lock_guard<RCUReadLock> lg(RCUReadLock::instance());
auto state = state_.load();
if (LIKELY(state_ == State::LOCAL)) {
if (LIKELY(state == State::LOCAL)) {
--localCount;
return 42;
} else {
auto value = --globalCount_;
if (state_ == State::GLOBAL) {
if (state == State::GLOBAL) {
assert(value >= 0);
return value;
} else {
......
......@@ -69,7 +69,9 @@ void basicTest() {
b.wait();
count.useGlobal();
--count;
if (--count == 0) {
++got0;
}
for (auto& t: ts) {
t.join();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment