Commit f2d225e4 authored by Maged Michael's avatar Maged Michael Committed by Facebook GitHub Bot

hazptr: Make cohort active_ data-race-free

Summary: Make hazptr_obj_cohort active_ atomic to be data-race-free.

Reviewed By: yfeldblum

Differential Revision: D22976574

fbshipit-source-id: 5a09aa7cedc26c71b2160b2df14a7e0f7b55e2e7
parent 0bf08a92
......@@ -298,7 +298,7 @@ class hazptr_obj_cohort {
SharedList l_;
Atom<int> count_;
bool active_;
Atom<bool> active_;
Atom<bool> pushed_to_domain_tagged_;
public:
......@@ -314,17 +314,17 @@ class hazptr_obj_cohort {
/** Destructor */
~hazptr_obj_cohort() {
if (active_) {
if (active()) {
shutdown_and_reclaim();
}
DCHECK(!active_);
DCHECK(!active());
DCHECK(l_.empty());
}
/** shutdown_and_reclaim */
void shutdown_and_reclaim() {
DCHECK(active_);
active_ = false;
DCHECK(active());
clear_active();
if (!l_.empty()) {
List l = l_.pop_all();
clear_count();
......@@ -340,6 +340,14 @@ class hazptr_obj_cohort {
private:
friend class hazptr_obj<Atom>;
bool active() {
return active_.load(std::memory_order_relaxed);
}
void clear_active() {
active_.store(false, std::memory_order_relaxed);
}
int count() const noexcept {
return count_.load(std::memory_order_acquire);
}
......@@ -359,7 +367,7 @@ class hazptr_obj_cohort {
/** push_obj */
void push_obj(Obj* obj) {
if (active_) {
if (active()) {
l_.push(obj);
inc_count();
check_threshold_push();
......
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