Remove LiveTV menu.
[vuplus_xbmc] / xbmc / threads / Event.h
index 82ac37b..08185f7 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *      Copyright (C) 2005-2011 Team XBMC
- *      http://www.xbmc.org
+ *      Copyright (C) 2005-2013 Team XBMC
+ *      http://xbmc.org
  *
  *  This Program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -13,9 +13,8 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with XBMC; see the file COPYING.  If not, write to
- *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *  http://www.gnu.org/copyleft/gpl.html
+ *  along with XBMC; see the file COPYING.  If not, see
+ *  <http://www.gnu.org/licenses/>.
  *
  */
 
@@ -24,6 +23,7 @@
 #include <vector>
 
 #include "threads/Condition.h"
+#include "threads/SingleLock.h"
 
 // forward declare the CEventGroup
 namespace XbmcThreads
@@ -41,12 +41,13 @@ namespace XbmcThreads
  *
  * This class manages 'spurious returns' from the condition variable.
  */
-class CEvent
+class CEvent : public XbmcThreads::NonCopyable
 {
   bool manualReset;
-  bool signaled;
+  volatile bool signaled;
   unsigned int numWaits;
 
+  CCriticalSection groupListMutex; // lock for the groups list
   std::vector<XbmcThreads::CEventGroup*> * groups;
 
   /**
@@ -54,28 +55,24 @@ class CEvent
    *  predicate being monitored to include both the signaled and interrupted
    *  states.
    */
-  XbmcThreads::TightConditionVariable<bool&> condVar;
+  XbmcThreads::ConditionVariable actualCv;
+  XbmcThreads::TightConditionVariable<volatile bool&> condVar;
   CCriticalSection mutex;
 
   friend class XbmcThreads::CEventGroup;
 
-  void groupSet();
   void addGroup(XbmcThreads::CEventGroup* group);
   void removeGroup(XbmcThreads::CEventGroup* group);
 
   // helper for the two wait methods
   inline bool prepReturn() { bool ret = signaled; if (!manualReset && numWaits == 0) signaled = false; return ret; }
 
-  // block the ability to copy
-  inline CEvent& operator=(const CEvent& src) { return *this; }
-  inline CEvent(const CEvent& other): condVar(signaled) {}
-
 public:
   inline CEvent(bool manual = false, bool signaled_ = false) : 
-    manualReset(manual), signaled(signaled_), numWaits(0), groups(NULL), condVar(signaled) {}
+    manualReset(manual), signaled(signaled_), numWaits(0), groups(NULL), condVar(actualCv,signaled) {}
 
   inline void Reset() { CSingleLock lock(mutex); signaled = false; }
-  inline void Set() { CSingleLock lock(mutex); signaled = true; condVar.notifyAll(); groupSet(); }
+  void Set();
 
   /**
    * This will wait up to 'milliSeconds' milliseconds for the Event
@@ -93,6 +90,12 @@ public:
   inline bool Wait()
   { CSingleLock lock(mutex); numWaits++; condVar.wait(mutex); numWaits--; return prepReturn(); }
 
+  /**
+   * This is mostly for testing. It allows a thread to make sure there are 
+   *  the right amount of other threads waiting.
+   */
+  inline int getNumWaits() { CSingleLock lock(mutex); return numWaits; }
+
 };
 
 namespace XbmcThreads
@@ -102,21 +105,21 @@ namespace XbmcThreads
    * It is equivalent to WaitOnMultipleObject that returns when "any" Event
    * in the group signaled.
    */
-  class CEventGroup
+  class CEventGroup : public NonCopyable
   {
     std::vector<CEvent*> events;
     CEvent* signaled;
+    XbmcThreads::ConditionVariable actualCv;
     XbmcThreads::TightConditionVariable<CEvent*&> condVar;
     CCriticalSection mutex;
 
     unsigned int numWaits;
 
-    inline void Set(CEvent* child) { CSingleLock lock(mutex); signaled = child; condVar.notifyAll(); }
+    // This is ONLY called from CEvent::Set.
+    inline void Set(CEvent* child) { CSingleLock l(mutex); signaled = child; condVar.notifyAll(); }
 
     friend class ::CEvent;
 
-    inline CEvent* prepReturn() { CEvent* ret = signaled; if (numWaits == 0) signaled = NULL; return ret; }
-
   public:
 
     /**
@@ -141,7 +144,7 @@ namespace XbmcThreads
      * signaled at which point a pointer to that CEvents will be 
      * returned.
      */
-    inline CEvent* wait() { CSingleLock lock(mutex); numWaits++; condVar.wait(mutex); numWaits--; return prepReturn(); }
+    CEvent* wait();
 
     /**
      * This will block until any one of the CEvents in the group are
@@ -149,6 +152,13 @@ namespace XbmcThreads
      * it will return a pointer to that CEvent, otherwise it will return
      * NULL.
      */
-    inline CEvent* wait(unsigned int milliseconds)  { CSingleLock lock(mutex); numWaits++; condVar.wait(mutex,milliseconds); numWaits--; return prepReturn(); }
+    CEvent* wait(unsigned int milliseconds);
+
+    /**
+     * This is mostly for testing. It allows a thread to make sure there are 
+     *  the right amount of other threads waiting.
+     */
+    inline int getNumWaits() { CSingleLock lock(mutex); return numWaits; }
+
   };
 }