Keith Davis | e813d67 | 2021-04-22 10:10:34 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include <AsyncExecutionCallback.hpp> |
| 7 | |
| 8 | namespace armnn |
| 9 | { |
| 10 | |
| 11 | namespace experimental |
| 12 | { |
| 13 | |
| 14 | void AsyncExecutionCallback::Notify(armnn::Status status, InferenceTimingPair timeTaken) |
| 15 | { |
| 16 | { |
| 17 | std::lock_guard<std::mutex> hold(m_Mutex); |
| 18 | if (m_Notified) |
| 19 | { |
| 20 | return; |
| 21 | } |
| 22 | // store results and mark as notified |
| 23 | m_Status = status; |
| 24 | m_StartTime = timeTaken.first; |
| 25 | m_EndTime = timeTaken.second; |
| 26 | m_Notified = true; |
| 27 | } |
| 28 | m_Condition.notify_all(); |
| 29 | } |
| 30 | |
| 31 | void AsyncExecutionCallback::Wait() const |
| 32 | { |
| 33 | std::unique_lock<std::mutex> lock(m_Mutex); |
| 34 | m_Condition.wait(lock, [this] { return m_Notified; }); |
| 35 | } |
| 36 | |
| 37 | armnn::Status AsyncExecutionCallback::GetStatus() const |
| 38 | { |
| 39 | Wait(); |
| 40 | return m_Status; |
| 41 | } |
| 42 | |
| 43 | HighResolutionClock AsyncExecutionCallback::GetStartTime() const |
| 44 | { |
| 45 | Wait(); |
| 46 | return m_StartTime; |
| 47 | } |
| 48 | |
| 49 | HighResolutionClock AsyncExecutionCallback::GetEndTime() const |
| 50 | { |
| 51 | Wait(); |
| 52 | return m_EndTime; |
| 53 | } |
| 54 | |
| 55 | } // namespace experimental |
| 56 | |
| 57 | } // namespace armnn |