Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed callback copy count #6607

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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