Panda3D
conditionVarFullWin32Impl.h
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 conditionVarFullWin32Impl.h
10  * @author drose
11  * @date 2006-08-28
12  */
13 
14 #ifndef CONDITIONVARFULLWIN32IMPL_H
15 #define CONDITIONVARFULLWIN32IMPL_H
16 
17 #include "pandabase.h"
18 #include "selectThreadImpl.h"
19 
20 #if defined(WIN32_VC)
21 
22 #include "mutexWin32Impl.h"
23 #include "pnotify.h"
24 #include "atomicAdjust.h"
25 
26 class MutexWin32Impl;
27 
28 /**
29  * Uses Windows native calls to implement a conditionVarFull.
30  *
31  * We follow the "SetEvent" implementation suggested by
32  * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html . This allows us to
33  * implement both notify() and notify_all(), but it has more overhead than the
34  * simpler implementation of ConditionVarWin32Impl.
35  *
36  * As described by the above reference, this implementation suffers from a few
37  * weaknesses; in particular, it does not necessarily wake up all threads
38  * fairly; and it may sometimes incorrectly wake up a thread that was not
39  * waiting at the time notify() was called. But we figure it's good enough
40  * for our purposes.
41  */
42 class EXPCL_PANDA_PIPELINE ConditionVarFullWin32Impl {
43 public:
44  INLINE ConditionVarFullWin32Impl(MutexWin32Impl &mutex);
45  INLINE ~ConditionVarFullWin32Impl();
46 
47  INLINE void wait();
48  INLINE void wait(double timeout);
49  INLINE void notify();
50  INLINE void notify_all();
51 
52 private:
53  CRITICAL_SECTION *_external_mutex;
54  HANDLE _event_signal;
55  HANDLE _event_broadcast;
56  TVOLATILE AtomicAdjust::Integer _waiters_count;
57 };
58 
60 
61 #endif // WIN32_VC
62 
63 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.