</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" />
</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" />
<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>
<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>
<ClInclude Include="..\include\cecloader.h" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="..\src\lib\platform\windows\os-threads.cpp" />
<ClCompile Include="..\src\testclient\main.cpp" />
</ItemGroup>
<ItemGroup>
</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" />
--- /dev/null
+/*
+ * 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);
+ }
+}
// 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;