Fixed callback copy count (#6607)
This commit is contained in:
parent
757db35528
commit
fab4056ceb
@ -404,15 +404,18 @@ private:
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock{_mutex};
|
std::lock_guard<std::mutex> lock{_mutex};
|
||||||
_state = InferState::Idle;
|
_state = InferState::Idle;
|
||||||
callback = _callback;
|
std::swap(callback, _callback);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
try {
|
try {
|
||||||
auto local_callback = std::move(callback);
|
callback(currentException);
|
||||||
local_callback(currentException);
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
currentException = std::current_exception();
|
currentException = std::current_exception();
|
||||||
}
|
}
|
||||||
|
std::lock_guard<std::mutex> lock{_mutex};
|
||||||
|
if (!_callback) {
|
||||||
|
std::swap(callback, _callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (nullptr == currentException) {
|
if (nullptr == currentException) {
|
||||||
promise.set_value();
|
promise.set_value();
|
||||||
|
@ -145,4 +145,21 @@ TEST_P(InferRequestCallbackTests, ReturnResultNotReadyFromWaitInAsyncModeForTooS
|
|||||||
ASSERT_NO_THROW(req.Wait(InferenceEngine::InferRequest::WaitMode::RESULT_READY));
|
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
|
} // namespace BehaviorTestsDefinitions
|
Loading…
Reference in New Issue
Block a user