NAP
asyncobserver.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 // Nap includes
8 #include <utility/dllexport.h>
9 
10 // Std includes
11 #include <thread>
12 #include <condition_variable>
13 
14 
15 namespace nap
16 {
17  namespace audio
18  {
19 
24  class NAPAPI AsyncObserver
25  {
26  public:
27  AsyncObserver() = default;
28  ~AsyncObserver() = default;
29 
34  void setBarrier(uint32_t numberOfNotifications = 1);
35 
39  void notifyBarrier();
40 
44  void waitForNotifications();
45 
49  void notifyOne();
50 
54  void notifyAll();
55 
56  private:
57  std::condition_variable mCondition;
58  std::mutex mMutex;
59 
60  bool mNotified = false;
61  uint32_t mNumberOfNotifications = 0;
62  uint32_t mNotificationCounter = 0;
63  };
64 
65  }
66 }
nap::audio::AsyncObserver
Definition: asyncobserver.h:24
nap
Definition: templateapp.h:17