NAP
autoresetevent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <mutex>
8 #include <functional>
9 #include <condition_variable>
10 
11 namespace nap
12 {
13  namespace utility
14  {
21  {
22  public:
26  enum class EWaitResult
27  {
28  Completed,
29  Canceled
30  };
31 
32  using LockedWaitCallback = std::function<void(EWaitResult)>;
33  using LockedSetCallback = std::function<void()>;
34 
38  void reset();
39 
47 
53  void set(const LockedSetCallback& callback = LockedSetCallback());
54 
58  void cancelWait();
59 
60  private:
61  std::mutex mMutex;
62  std::condition_variable mSignaledCondition;
63  bool mSignaled = false;
64  bool mWaitCanceled = false;
65  };
66  }
67 }
nap::utility::AutoResetEvent::set
void set(const LockedSetCallback &callback=LockedSetCallback())
nap::utility::AutoResetEvent::EWaitResult::Completed
@ Completed
The wait completed successfully (i.e. the event was signaled normally)
nap::utility::AutoResetEvent::reset
void reset()
nap::utility::AutoResetEvent::wait
EWaitResult wait(const LockedWaitCallback &callback=LockedWaitCallback())
nap::utility::AutoResetEvent::EWaitResult::Canceled
@ Canceled
The wait was canceled.
nap::utility::AutoResetEvent::cancelWait
void cancelWait()
nap
Definition: templateapp.h:17
nap::utility::AutoResetEvent::LockedSetCallback
std::function< void()> LockedSetCallback
Definition: autoresetevent.h:33
nap::utility::AutoResetEvent
Definition: autoresetevent.h:20
nap::utility::AutoResetEvent::EWaitResult
EWaitResult
Definition: autoresetevent.h:26
nap::utility::AutoResetEvent::LockedWaitCallback
std::function< void(EWaitResult)> LockedWaitCallback
Definition: autoresetevent.h:32