Newton Dynamics  4.00
ndSyncMutex.h
1 /* Copyright (c) <2003-2022> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __ND_SYNC_MUTEX_H_
23 #define __ND_SYNC_MUTEX_H_
24 
25 #include "ndCoreStdafx.h"
26 
29 {
30  public:
32  D_CORE_API ndSyncMutex();
33 
35  D_CORE_API ~ndSyncMutex();
36 
41  D_CORE_API void Sync();
42 
44  D_CORE_API void Tick();
45 
47  D_CORE_API void Release();
48 
49 #ifndef D_USE_THREAD_EMULATION
50  private:
51  std::mutex m_mutex;
52  std::condition_variable m_condition;
53  ndInt32 m_count;
54 #endif
55 };
56 
57 #endif
ndSyncMutex
Generic counting mutex for synchronization of thread jobs.
Definition: ndSyncMutex.h:29
ndSyncMutex::Tick
D_CORE_API void Tick()
Increment internal variable m_count by one.
Definition: ndSyncMutex.cpp:58
ndSyncMutex::Sync
D_CORE_API void Sync()
Synchronize with another worker threads.
Definition: ndSyncMutex.cpp:38
ndSyncMutex::ndSyncMutex
D_CORE_API ndSyncMutex()
Create and initialize counter to zero.
Definition: ndSyncMutex.cpp:25
ndSyncMutex::~ndSyncMutex
D_CORE_API ~ndSyncMutex()
Destroy mutex.
Definition: ndSyncMutex.cpp:34
ndSyncMutex::Release
D_CORE_API void Release()
Decrement internal variable m_count by one and signal the thread to wakeup.
Definition: ndSyncMutex.cpp:49