Fabric: `failCallback` implementation for MessageQueueEventBeat

Summary: See comments in the code.

Reviewed By: mdvacca

Differential Revision: D10081502

fbshipit-source-id: b55bf019346a44c4b2980c70f547f53e4994e968
This commit is contained in:
Valentin Shergin 2018-10-08 14:34:22 -07:00 committed by Facebook Github Bot
parent fa3525dc83
commit 02d2e85af3
1 changed files with 17 additions and 1 deletions

View File

@ -41,10 +41,26 @@ void MessageQueueEventBeat::induce() const {
return;
}
#ifndef NDEBUG
// We do a trick here.
// If `wasExecuted` was destroyed before set to `true`,
// it means that the execution block was deallocated not being executed.
// This indicates that `messageQueueThread_` is being deallocated.
auto wasExecuted = std::shared_ptr<bool>(new bool {false}, [this](bool *wasExecuted) {
if (!*wasExecuted && failCallback_) {
failCallback_();
}
delete wasExecuted;
});
#endif
isBusy_ = true;
messageQueueThread_->runOnQueue([this]() {
messageQueueThread_->runOnQueue([=]() mutable {
this->beat();
isBusy_ = false;
#ifndef NDEBUG
*wasExecuted = true;
#endif
});
}