Panda3D

conditionVarFullWin32Impl.h

00001 // Filename: conditionVarFullWin32Impl.h
00002 // Created by:  drose (28Aug06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CONDITIONVARFULLWIN32IMPL_H
00016 #define CONDITIONVARFULLWIN32IMPL_H
00017 
00018 #include "pandabase.h"
00019 #include "selectThreadImpl.h"
00020 
00021 #if defined(WIN32_VC)
00022 
00023 #include "mutexWin32Impl.h"
00024 #include "pnotify.h"
00025 #include "atomicAdjust.h"
00026 
00027 class MutexWin32Impl;
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : ConditionVarFullWin32Impl
00031 // Description : Uses Windows native calls to implement a
00032 //               conditionVarFull.
00033 //
00034 //               We follow the "SetEvent" implementation suggested by
00035 //               http://www.cs.wustl.edu/~schmidt/win32-cv-1.html .
00036 //               This allows us to implement both notify() and
00037 //               notify_all(), but it has more overhead than the
00038 //               simpler implementation of ConditionVarWin32Impl.
00039 //
00040 //               As described by the above reference, this
00041 //               implementation suffers from a few weaknesses; in
00042 //               particular, it does not necessarily wake up all
00043 //               threads fairly; and it may sometimes incorrectly wake
00044 //               up a thread that was not waiting at the time notify()
00045 //               was called.  But we figure it's good enough for our
00046 //               purposes.
00047 ////////////////////////////////////////////////////////////////////
00048 class EXPCL_PANDA_PIPELINE ConditionVarFullWin32Impl {
00049 public:
00050   INLINE ConditionVarFullWin32Impl(MutexWin32Impl &mutex);
00051   INLINE ~ConditionVarFullWin32Impl();
00052 
00053   INLINE void wait();
00054   INLINE void wait(double timeout);
00055   INLINE void notify();
00056   INLINE void notify_all();
00057 
00058 private:
00059   CRITICAL_SECTION *_external_mutex;
00060   HANDLE _event_signal;
00061   HANDLE _event_broadcast;
00062   TVOLATILE AtomicAdjust::Integer _waiters_count;
00063 };
00064 
00065 #include "conditionVarFullWin32Impl.I"
00066 
00067 #endif  // WIN32_VC
00068 
00069 #endif
 All Classes Functions Variables Enumerations