diff options
Diffstat (limited to 'src/armnn/AsyncExecutionCallback.cpp')
-rw-r--r-- | src/armnn/AsyncExecutionCallback.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/armnn/AsyncExecutionCallback.cpp b/src/armnn/AsyncExecutionCallback.cpp new file mode 100644 index 0000000000..c44808918d --- /dev/null +++ b/src/armnn/AsyncExecutionCallback.cpp @@ -0,0 +1,57 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <AsyncExecutionCallback.hpp> + +namespace armnn +{ + +namespace experimental +{ + +void AsyncExecutionCallback::Notify(armnn::Status status, InferenceTimingPair timeTaken) +{ + { + std::lock_guard<std::mutex> hold(m_Mutex); + if (m_Notified) + { + return; + } + // store results and mark as notified + m_Status = status; + m_StartTime = timeTaken.first; + m_EndTime = timeTaken.second; + m_Notified = true; + } + m_Condition.notify_all(); +} + +void AsyncExecutionCallback::Wait() const +{ + std::unique_lock<std::mutex> lock(m_Mutex); + m_Condition.wait(lock, [this] { return m_Notified; }); +} + +armnn::Status AsyncExecutionCallback::GetStatus() const +{ + Wait(); + return m_Status; +} + +HighResolutionClock AsyncExecutionCallback::GetStartTime() const +{ + Wait(); + return m_StartTime; +} + +HighResolutionClock AsyncExecutionCallback::GetEndTime() const +{ + Wait(); + return m_EndTime; +} + +} // namespace experimental + +} // namespace armnn
\ No newline at end of file |