Verify canonical replay under opposing worker completion orders
This commit is contained in:
1 parent
66af7c5bb9
commit
ef980af125
7 files changed
+621
-20
No files matched your search
@@ -21,6 +21,9 @@ struct WorkerPoolOptions {
|
||||
std::function<void(std::size_t)> before_worker_start;
|
||||
std::function<void(std::size_t)> before_submit;
|
||||
std::function<void(std::size_t)> before_execute;
|
||||
// Success-only observation after invocation returns, before future readiness.
|
||||
// A throwing observer fails that future. Replacement contract: Void/Library#15.
|
||||
std::function<void(std::size_t)> after_execute;
|
||||
};
|
||||
|
||||
class WorkerPool {
|
||||
@@ -38,12 +41,22 @@ public:
|
||||
if (executor_->is_executor_thread()) {
|
||||
throw std::logic_error("cannot submit nested work to the same worker pool");
|
||||
}
|
||||
if (options_.before_submit || options_.before_execute) {
|
||||
if (options_.before_submit || options_.before_execute || options_.after_execute) {
|
||||
const auto index = submission_index_.fetch_add(1, std::memory_order_relaxed);
|
||||
if (options_.before_submit) options_.before_submit(index);
|
||||
return admit([this, index, function = std::forward<Function>(function)]() mutable -> decltype(auto) {
|
||||
return admit([this, index, function = std::forward<Function>(function)]() mutable
|
||||
-> std::invoke_result_t<Function> {
|
||||
if (options_.before_execute) options_.before_execute(index);
|
||||
return std::invoke(function);
|
||||
if (!options_.after_execute) return std::invoke(function);
|
||||
using Result = std::invoke_result_t<Function>;
|
||||
if constexpr (std::is_void_v<Result>) {
|
||||
std::invoke(function);
|
||||
options_.after_execute(index);
|
||||
} else {
|
||||
Result result = std::invoke(function);
|
||||
options_.after_execute(index);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
return admit(std::forward<Function>(function));
|
||||
|
||||
Reference in new issue
Block a user