Skip to content

Commit

Permalink
Fixed callback copy count (openvinotoolkit#6607)
Browse files Browse the repository at this point in the history
  • Loading branch information
apankratovantonp authored Sep 30, 2021
1 parent 757db35 commit fab4056
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,18 @@ class AsyncInferRequestThreadSafeDefault : public IInferRequestInternal {
{
std::lock_guard<std::mutex> lock{_mutex};
_state = InferState::Idle;
callback = _callback;
std::swap(callback, _callback);
}
if (callback) {
try {
auto local_callback = std::move(callback);
local_callback(currentException);
callback(currentException);
} catch (...) {
currentException = std::current_exception();
}
std::lock_guard<std::mutex> lock{_mutex};
if (!_callback) {
std::swap(callback, _callback);
}
}
if (nullptr == currentException) {
promise.set_value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,21 @@ TEST_P(InferRequestCallbackTests, ReturnResultNotReadyFromWaitInAsyncModeForTooS
ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY));
}

TEST_P(InferRequestCallbackTests, ImplDoseNotCopyCallback) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
InferenceEngine::CNNNetwork cnnNet(function);
auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration);
auto req = execNet.CreateInferRequest();
{
auto somePtr = std::make_shared<int>(42);
req.SetCompletionCallback([somePtr] {
ASSERT_EQ(1, somePtr.use_count());
});
}

ASSERT_NO_THROW(req.StartAsync());
ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY));
}

} // namespace BehaviorTestsDefinitions

0 comments on commit fab4056

Please sign in to comment.