Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
SyncEvent.h
Go to the documentation of this file.
1 // This file is part of CoreLibrary containing useful reusable utility
2 // classes.
3 //
4 // Copyright (C) 2014 to present, Duncan Crutchley
5 // Contact <dac1976github@outlook.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published
9 // by the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License and GNU Lesser General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // and GNU Lesser General Public License along with this program. If
20 // not, see <http://www.gnu.org/licenses/>.
21 
27 #ifndef SYNCEVENT
28 #define SYNCEVENT
29 
30 #include "CoreLibraryDllGlobal.h"
31 #include <mutex>
32 #include <condition_variable>
33 
35 namespace core_lib
36 {
38 namespace threads
39 {
40 
42 enum class eResetCondition
43 {
44  manualReset,
45  autoReset
46 };
47 
49 enum class eNotifyType
50 {
51  signalOneThread,
52  signalAllThreads
53 };
54 
56 enum class eIntialCondition
57 {
58  notSignalled,
59  signalled
60 };
61 
70 class CORE_LIBRARY_DLL_SHARED_API SyncEvent final
71 {
72 public:
80  SyncEvent() = default;
99  SyncEvent(eNotifyType notifyCondition, eResetCondition resetCondition,
100  eIntialCondition initialCondition);
102  ~SyncEvent() = default;
104  SyncEvent(const SyncEvent&) = delete;
106  SyncEvent& operator=(const SyncEvent&) = delete;
108  SyncEvent(SyncEvent&&) = delete;
110  SyncEvent& operator=(SyncEvent&&) = delete;
117  void Wait();
128  bool WaitForTime(size_t milliseconds);
136  void Signal();
147  void Reset();
148 
149 private:
151  mutable std::mutex m_signalMutex;
153  std::condition_variable m_signalCondVar;
155  bool m_signalAllThreads{false};
157  bool m_autoReset{true};
159  bool m_signalFlag{false};
160 };
161 
162 } // namespace threads
163 } // namespace core_lib
164 
165 #endif // SYNCEVENT
std::mutex m_signalMutex
Mutex to lock access to members.
Definition: SyncEvent.h:151
eNotifyType
Enumeration defining notify mechanism for event.
Definition: SyncEvent.h:49
eIntialCondition
Enumeration defining intial state of event.
Definition: SyncEvent.h:56
Class defining a thread synchronisation event.
Definition: SyncEvent.h:70
eResetCondition
Enumeration defining reset mechanism for event.
Definition: SyncEvent.h:42
The core_lib namespace.
Definition: AsioDefines.h:59
std::condition_variable m_signalCondVar
Condition vairable to perform the waiting and signalling.
Definition: SyncEvent.h:153
File containing declaration of DLL import/export control defines.