platform/win32: moved the static variables in os-threads from the header to a separat...
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 3 Apr 2012 11:50:32 +0000 (13:50 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 3 Apr 2012 11:51:50 +0000 (13:51 +0200)
project/cec-config.vcxproj
project/cec-config.vcxproj.filters
project/libcec.vcxproj
project/libcec.vcxproj.filters
project/testclient.vcxproj
project/testclient.vcxproj.filters
src/lib/platform/windows/os-threads.cpp [new file with mode: 0644]
src/lib/platform/windows/os-threads.h

index 2243ff94368802b028f05b9089833c39bacdff38..6ca84e430d4c449f6d9a0feb78aab0984c847f26 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\src\cec-config\cec-config.cpp" />
+    <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="cec-config.rc" />
index 0d3f64797f092fe5ccf5b3b2b03f7ddf883ff82e..2ee5127e2cdbc3def865c83e95a59740c54df0cd 100644 (file)
@@ -21,6 +21,9 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\src\cec-config\cec-config.cpp" />
+    <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp">
+      <Filter>platform</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="cec-config.rc" />
index 3c1e89b837222c5325caf766a1bdb2899582cf4d..5b3c6f039153f78667a4caf5c466d95a6af3aa3c 100644 (file)
@@ -73,6 +73,7 @@
     <ClCompile Include="..\src\lib\LibCEC.cpp" />
     <ClCompile Include="..\src\lib\LibCECC.cpp" />
     <ClCompile Include="..\src\lib\LibCECDll.cpp" />
+    <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp" />
     <ClCompile Include="..\src\lib\platform\windows\serialport.cpp" />
   </ItemGroup>
   <ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 56f1a464a29d6120280b634ab8b04d097e78c28f..50ae8df5c3e8f261fd53a10085a5137fd1546374 100644 (file)
     <ClCompile Include="..\src\lib\devices\CECTV.cpp">
       <Filter>devices</Filter>
     </ClCompile>
+    <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp">
+      <Filter>platform\windows</Filter>
+    </ClCompile>
     <ClCompile Include="..\src\lib\platform\windows\serialport.cpp">
       <Filter>platform\windows</Filter>
     </ClCompile>
   <ItemGroup>
     <ResourceCompile Include="libcec.rc" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index fb1957290a362c2ea309f2c9388f09baa73f1292..0862f27ccda27a72bbcdf1256d89afe7bafd0c9f 100644 (file)
     <ClInclude Include="..\include\cecloader.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp" />
     <ClCompile Include="..\src\testclient\main.cpp" />
   </ItemGroup>
   <ItemGroup>
index 70acf3d3041ea6202fe042add81dbe2caf3622f8..0fd21fb85474a02309eeccc6f3f852b19d581ad8 100644 (file)
@@ -18,6 +18,9 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="..\src\testclient\main.cpp" />
+    <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp">
+      <Filter>platform</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="testclient.rc" />
diff --git a/src/lib/platform/windows/os-threads.cpp b/src/lib/platform/windows/os-threads.cpp
new file mode 100644 (file)
index 0000000..7c06d41
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited.  All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing       <license@pulse-eight.com>
+ *     http://www.pulse-eight.com/
+ *     http://www.pulse-eight.net/
+ */
+
+#include "../os.h"
+#include "os-threads.h"
+using namespace PLATFORM;
+
+static ConditionArg                     g_InitializeConditionVariable;
+static ConditionArg                     g_WakeConditionVariable;
+static ConditionArg                     g_WakeAllConditionVariable;
+static ConditionMutexArg                g_SleepConditionVariableCS;
+
+// check whether vista+ conditions are available at runtime
+static bool CheckVistaConditionFunctions(void)
+{
+  static int iHasVistaConditionFunctions(-1);
+  if (iHasVistaConditionFunctions == -1)
+  {
+    HMODULE handle = GetModuleHandle("Kernel32");
+    if (handle == NULL)
+    {
+      iHasVistaConditionFunctions = 0;
+    }
+    else
+    {
+      g_InitializeConditionVariable = (ConditionArg)     GetProcAddress(handle,"InitializeConditionVariable");
+      g_WakeConditionVariable       = (ConditionArg)     GetProcAddress(handle,"WakeConditionVariable");
+      g_WakeAllConditionVariable    = (ConditionArg)     GetProcAddress(handle,"WakeAllConditionVariable");
+      g_SleepConditionVariableCS    = (ConditionMutexArg)GetProcAddress(handle,"SleepConditionVariableCS");
+
+      // 1 when everything is resolved, 0 otherwise
+      iHasVistaConditionFunctions = g_InitializeConditionVariable &&
+                                    g_WakeConditionVariable &&
+                                    g_WakeAllConditionVariable &&
+                                    g_SleepConditionVariableCS ? 1 : 0;
+    }
+  }
+  return iHasVistaConditionFunctions == 1;
+}
+
+CConditionImpl::CConditionImpl(void)
+{
+  m_bOnVista = CheckVistaConditionFunctions();
+  if (m_bOnVista)
+    (*g_InitializeConditionVariable)(m_conditionVista = new CONDITION_VARIABLE);
+  else
+    m_conditionPreVista = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+}
+
+CConditionImpl::~CConditionImpl(void)
+{
+  if (m_bOnVista)
+    delete m_conditionVista;
+  else
+    ::CloseHandle(m_conditionPreVista);
+}
+
+void CConditionImpl::Signal(void)
+{
+  if (m_bOnVista)
+    (*g_WakeConditionVariable)(m_conditionVista);
+  else
+    ::SetEvent(m_conditionPreVista);
+}
+
+void CConditionImpl::Broadcast(void)
+{
+  if (m_bOnVista)
+    (*g_WakeAllConditionVariable)(m_conditionVista);
+  else
+    ::SetEvent(m_conditionPreVista);
+}
+
+bool CConditionImpl::Wait(mutex_t &mutex)
+{
+  if (m_bOnVista)
+  {
+    return ((*g_SleepConditionVariableCS)(m_conditionVista, mutex, INFINITE) ? true : false);
+  }
+  else
+  {
+    ::ResetEvent(m_conditionPreVista);
+    MutexUnlock(mutex);
+    DWORD iWaitReturn = ::WaitForSingleObject(m_conditionPreVista, 1000);
+    MutexLock(mutex);
+    return (iWaitReturn == 0);
+  }
+}
+
+bool CConditionImpl::Wait(mutex_t &mutex, uint32_t iTimeoutMs)
+{
+  if (iTimeoutMs == 0)
+    return Wait(mutex);
+
+  if (m_bOnVista)
+  {
+    return ((*g_SleepConditionVariableCS)(m_conditionVista, mutex, iTimeoutMs) ? true : false);
+  }
+  else
+  {
+    ::ResetEvent(m_conditionPreVista);
+    MutexUnlock(mutex);
+    DWORD iWaitReturn = ::WaitForSingleObject(m_conditionPreVista, iTimeoutMs);
+    MutexLock(mutex);
+    return (iWaitReturn == 0);
+  }
+}
index e082691e24582b1afb6208488d8aa8118ecf8680..3714c16711950919edd768708e5d2cee4fa48594 100644 (file)
@@ -47,109 +47,16 @@ namespace PLATFORM
   // windows vista+ conditions
   typedef VOID (WINAPI *ConditionArg)     (CONDITION_VARIABLE*);
   typedef BOOL (WINAPI *ConditionMutexArg)(CONDITION_VARIABLE*, CRITICAL_SECTION*, DWORD);
-  static ConditionArg                     g_InitializeConditionVariable;
-  static ConditionArg                     g_WakeConditionVariable;
-  static ConditionArg                     g_WakeAllConditionVariable;
-  static ConditionMutexArg                g_SleepConditionVariableCS;
-
-  // check whether vista+ conditions are available at runtime  
-  static bool CheckVistaConditionFunctions(void)
-  {
-    static int iHasVistaConditionFunctions(-1);
-    if (iHasVistaConditionFunctions == -1)
-    {
-      HMODULE handle = GetModuleHandle("Kernel32");
-      if (handle == NULL)
-      {
-        iHasVistaConditionFunctions = 0;
-      }
-      else
-      {
-        g_InitializeConditionVariable = (ConditionArg)     GetProcAddress(handle,"InitializeConditionVariable");
-        g_WakeConditionVariable       = (ConditionArg)     GetProcAddress(handle,"WakeConditionVariable");
-        g_WakeAllConditionVariable    = (ConditionArg)     GetProcAddress(handle,"WakeAllConditionVariable");
-        g_SleepConditionVariableCS    = (ConditionMutexArg)GetProcAddress(handle,"SleepConditionVariableCS");
-
-        // 1 when everything is resolved, 0 otherwise
-        iHasVistaConditionFunctions = g_InitializeConditionVariable &&
-                                      g_WakeConditionVariable &&
-                                      g_WakeAllConditionVariable &&
-                                      g_SleepConditionVariableCS ? 1 : 0;
-      }
-    }
-    return iHasVistaConditionFunctions == 1;
-  }
 
   class CConditionImpl
   {
   public:
-    CConditionImpl(void)
-    {
-      m_bOnVista = CheckVistaConditionFunctions();
-      if (m_bOnVista)
-        (*g_InitializeConditionVariable)(m_conditionVista = new CONDITION_VARIABLE);
-      else
-        m_conditionPreVista = ::CreateEvent(NULL, TRUE, FALSE, NULL);
-    }
-
-    virtual ~CConditionImpl(void)
-    {
-      if (m_bOnVista)
-        delete m_conditionVista;
-      else
-        ::CloseHandle(m_conditionPreVista);
-    }
-
-    void Signal(void)
-    {
-      if (m_bOnVista)
-        (*g_WakeConditionVariable)(m_conditionVista);
-      else
-        ::SetEvent(m_conditionPreVista);
-    }
-
-    void Broadcast(void)
-    {
-      if (m_bOnVista)
-        (*g_WakeAllConditionVariable)(m_conditionVista);
-      else
-        ::SetEvent(m_conditionPreVista);
-    }
-
-    bool Wait(mutex_t &mutex)
-    {
-      if (m_bOnVista)
-      {
-        return ((*g_SleepConditionVariableCS)(m_conditionVista, mutex, INFINITE) ? true : false);
-      }
-      else
-      {
-        ::ResetEvent(m_conditionPreVista);
-        MutexUnlock(mutex);
-        DWORD iWaitReturn = ::WaitForSingleObject(m_conditionPreVista, 1000);
-        MutexLock(mutex);
-        return (iWaitReturn == 0);
-      }
-    }
-
-    bool Wait(mutex_t &mutex, uint32_t iTimeoutMs)
-    {
-      if (iTimeoutMs == 0)
-        return Wait(mutex);
-
-      if (m_bOnVista)
-      {
-        return ((*g_SleepConditionVariableCS)(m_conditionVista, mutex, iTimeoutMs) ? true : false);
-      }
-      else
-      {
-        ::ResetEvent(m_conditionPreVista);
-        MutexUnlock(mutex);
-        DWORD iWaitReturn = ::WaitForSingleObject(m_conditionPreVista, iTimeoutMs);
-        MutexLock(mutex);
-        return (iWaitReturn == 0);
-      }
-    }
+    CConditionImpl(void);
+    virtual ~CConditionImpl(void);
+    void Signal(void);
+    void Broadcast(void);
+    bool Wait(mutex_t &mutex);
+    bool Wait(mutex_t &mutex, uint32_t iTimeoutMs);
 
     bool                m_bOnVista;
     CONDITION_VARIABLE *m_conditionVista;