Panda3D
conditionVarFullWin32Impl.h
1 // Filename: conditionVarFullWin32Impl.h
2 // Created by: drose (28Aug06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CONDITIONVARFULLWIN32IMPL_H
16 #define CONDITIONVARFULLWIN32IMPL_H
17 
18 #include "pandabase.h"
19 #include "selectThreadImpl.h"
20 
21 #if defined(WIN32_VC)
22 
23 #include "mutexWin32Impl.h"
24 #include "pnotify.h"
25 #include "atomicAdjust.h"
26 
27 class MutexWin32Impl;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : ConditionVarFullWin32Impl
31 // Description : Uses Windows native calls to implement a
32 // conditionVarFull.
33 //
34 // We follow the "SetEvent" implementation suggested by
35 // http://www.cs.wustl.edu/~schmidt/win32-cv-1.html .
36 // This allows us to implement both notify() and
37 // notify_all(), but it has more overhead than the
38 // simpler implementation of ConditionVarWin32Impl.
39 //
40 // As described by the above reference, this
41 // implementation suffers from a few weaknesses; in
42 // particular, it does not necessarily wake up all
43 // threads fairly; and it may sometimes incorrectly wake
44 // up a thread that was not waiting at the time notify()
45 // was called. But we figure it's good enough for our
46 // purposes.
47 ////////////////////////////////////////////////////////////////////
48 class EXPCL_PANDA_PIPELINE ConditionVarFullWin32Impl {
49 public:
50  INLINE ConditionVarFullWin32Impl(MutexWin32Impl &mutex);
51  INLINE ~ConditionVarFullWin32Impl();
52 
53  INLINE void wait();
54  INLINE void wait(double timeout);
55  INLINE void notify();
56  INLINE void notify_all();
57 
58 private:
59  CRITICAL_SECTION *_external_mutex;
60  HANDLE _event_signal;
61  HANDLE _event_broadcast;
62  TVOLATILE AtomicAdjust::Integer _waiters_count;
63 };
64 
65 #include "conditionVarFullWin32Impl.I"
66 
67 #endif // WIN32_VC
68 
69 #endif