blob: c44808918d7e850339c368b791c8b6ef5d9c98ef [file] [log] [blame]
Keith Davise813d672021-04-22 10:10:34 +01001//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <AsyncExecutionCallback.hpp>
7
8namespace armnn
9{
10
11namespace experimental
12{
13
14void 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
31void AsyncExecutionCallback::Wait() const
32{
33 std::unique_lock<std::mutex> lock(m_Mutex);
34 m_Condition.wait(lock, [this] { return m_Notified; });
35}
36
37armnn::Status AsyncExecutionCallback::GetStatus() const
38{
39 Wait();
40 return m_Status;
41}
42
43HighResolutionClock AsyncExecutionCallback::GetStartTime() const
44{
45 Wait();
46 return m_StartTime;
47}
48
49HighResolutionClock AsyncExecutionCallback::GetEndTime() const
50{
51 Wait();
52 return m_EndTime;
53}
54
55} // namespace experimental
56
57} // namespace armnn