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

hazard pointers: Rearrange invoking asynchronous reclamation in executor

Summary:
Rearrange invoking asynchronous reclamation in executor.

Eliminate the LOG message about skipping asynchronous reclamation.

Reviewed By: yfeldblum

Differential Revision: D30908286

fbshipit-source-id: ee79714bf8e6253a01d04c6d2ffa81895c4133c8
parent 9258f5e9
...@@ -304,10 +304,7 @@ class hazptr_domain { ...@@ -304,10 +304,7 @@ class hazptr_domain {
return; return;
} }
inc_num_bulk_reclaims(); inc_num_bulk_reclaims();
if (std::is_same<Atom<int>, std::atomic<int>>{} && if (!invoke_reclamation_in_executor(rcount)) {
this == &default_hazptr_domain<Atom>() && hazptr_use_executor()) {
invoke_reclamation_in_executor(rcount);
} else {
do_reclamation(rcount); do_reclamation(rcount);
} }
} }
...@@ -584,11 +581,17 @@ class hazptr_domain { ...@@ -584,11 +581,17 @@ class hazptr_domain {
return rec; return rec;
} }
void invoke_reclamation_in_executor(int rcount) { bool invoke_reclamation_in_executor(int rcount) {
if (!std::is_same<Atom<int>, std::atomic<int>>{} ||
this != &default_hazptr_domain<Atom>() || !hazptr_use_executor()) {
return false;
}
auto fn = exec_fn_.load(std::memory_order_acquire); auto fn = exec_fn_.load(std::memory_order_acquire);
auto ex = fn ? fn() : get_default_executor(); auto ex = fn ? fn() : get_default_executor();
if (!ex) {
return false;
}
auto backlog = exec_backlog_.fetch_add(1, std::memory_order_relaxed); auto backlog = exec_backlog_.fetch_add(1, std::memory_order_relaxed);
if (ex) {
auto recl_fn = [this, rcount] { auto recl_fn = [this, rcount] {
exec_backlog_.store(0, std::memory_order_relaxed); exec_backlog_.store(0, std::memory_order_relaxed);
do_reclamation(rcount); do_reclamation(rcount);
...@@ -598,20 +601,16 @@ class hazptr_domain { ...@@ -598,20 +601,16 @@ class hazptr_domain {
} else { } else {
ex->add(recl_fn); ex->add(recl_fn);
} }
} else {
if (kIsDebug) {
LOG(INFO) << "Skip asynchronous reclamation by hazptr executor";
}
}
if (backlog >= 10) { if (backlog >= 10) {
hazptr_warning_executor_backlog(backlog); hazptr_warning_executor_backlog(backlog);
} }
return true;
} }
template <typename Func> template <typename Func>
void invoke_reclamation_may_deadlock(folly::Executor* ex, Func recl_fn) { void invoke_reclamation_may_deadlock(folly::Executor* ex, Func recl_fn) {
ex->add(recl_fn); ex->add(recl_fn);
// This program is using the default inline executor, which is an // This program is using the default executor, which is an
// inline executor. This is not necessarily a problem. But if this // inline executor. This is not necessarily a problem. But if this
// program encounters deadlock, then this may be the cause. Most // program encounters deadlock, then this may be the cause. Most
// likely this program did not call // likely this program did not call
......
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