Panda3D
conditionVarWin32Impl.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file conditionVarWin32Impl.I
10  * @author drose
11  * @date 2006-02-07
12  */
13 
14 /**
15  *
16  */
17 INLINE ConditionVarWin32Impl::
18 ConditionVarWin32Impl(MutexWin32Impl &mutex) {
19  _external_mutex = &mutex._lock;
20 
21  // Create an auto-reset event.
22  _event_signal = CreateEvent(nullptr, false, false, nullptr);
23 }
24 
25 /**
26  *
27  */
28 INLINE ConditionVarWin32Impl::
29 ~ConditionVarWin32Impl() {
30  CloseHandle(_event_signal);
31 }
32 
33 /**
34  *
35  */
36 INLINE void ConditionVarWin32Impl::
37 wait() {
38  LeaveCriticalSection(_external_mutex);
39 
40  DWORD result = WaitForSingleObject(_event_signal, INFINITE);
41  nassertv(result == WAIT_OBJECT_0);
42 
43  EnterCriticalSection(_external_mutex);
44 }
45 
46 /**
47  *
48  */
49 INLINE void ConditionVarWin32Impl::
50 wait(double timeout) {
51  LeaveCriticalSection(_external_mutex);
52 
53  DWORD result = WaitForSingleObject(_event_signal, (DWORD)(timeout * 1000.0));
54  nassertv(result == WAIT_OBJECT_0 || result == WAIT_TIMEOUT);
55 
56  EnterCriticalSection(_external_mutex);
57 }
58 
59 /**
60  *
61  */
62 INLINE void ConditionVarWin32Impl::
63 notify() {
64  SetEvent(_event_signal);
65 }