aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/AsyncExecutionCallback.cpp
blob: c44808918d7e850339c368b791c8b6ef5d9c98ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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