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 { ...@@ -40,12 +40,13 @@ class RCURefCount {
auto& localCount = *localCount_; auto& localCount = *localCount_;
std::lock_guard<RCUReadLock> lg(RCUReadLock::instance()); std::lock_guard<RCUReadLock> lg(RCUReadLock::instance());
auto state = state_.load();
if (LIKELY(state_ == State::LOCAL)) { if (LIKELY(state == State::LOCAL)) {
++localCount; ++localCount;
return 42; return 42;
} else if (state_ == State::GLOBAL_TRANSITION) { } else if (state == State::GLOBAL_TRANSITION) {
++globalCount_; ++globalCount_;
return 42; return 42;
...@@ -67,15 +68,16 @@ class RCURefCount { ...@@ -67,15 +68,16 @@ class RCURefCount {
auto& localCount = *localCount_; auto& localCount = *localCount_;
std::lock_guard<RCUReadLock> lg(RCUReadLock::instance()); std::lock_guard<RCUReadLock> lg(RCUReadLock::instance());
auto state = state_.load();
if (LIKELY(state_ == State::LOCAL)) { if (LIKELY(state == State::LOCAL)) {
--localCount; --localCount;
return 42; return 42;
} else { } else {
auto value = --globalCount_; auto value = --globalCount_;
if (state_ == State::GLOBAL) { if (state == State::GLOBAL) {
assert(value >= 0); assert(value >= 0);
return value; return value;
} else { } else {
......
...@@ -69,7 +69,9 @@ void basicTest() { ...@@ -69,7 +69,9 @@ void basicTest() {
b.wait(); b.wait();
count.useGlobal(); count.useGlobal();
--count; if (--count == 0) {
++got0;
}
for (auto& t: ts) { for (auto& t: ts) {
t.join(); 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