X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fplatform%2Fwindows%2Fos-threads.h;h=47101dcd0c5326c610546351c747da747f7360bc;hb=04283ce44fc45cbfb145075d02ff116e277f7560;hp=52bd4bc11ab946b3018bd522b01b64b0ace7cd9b;hpb=3a590d6a4652d1c47026446dcdc44ac9852f8af3;p=deb_libcec.git diff --git a/src/lib/platform/windows/os-threads.h b/src/lib/platform/windows/os-threads.h index 52bd4bc..47101dc 100644 --- a/src/lib/platform/windows/os-threads.h +++ b/src/lib/platform/windows/os-threads.h @@ -34,6 +34,7 @@ namespace PLATFORM { #define thread_t HANDLE + #define INVALID_THREAD_VALUE NULL #define ThreadsWait(thread, retVal) (::WaitForSingleObject(thread, INFINITE) < 0) #define ThreadsCreate(thread, func, arg) ((thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, NULL)) == NULL ? false : true) @@ -47,90 +48,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, uint32_t iTimeoutMs) - { - if (m_bOnVista) - { - return ((*g_SleepConditionVariableCS)(m_conditionVista, mutex, iTimeoutMs <= 0 ? INFINITE : iTimeoutMs) ? true : false); - } - else - { - ::ResetEvent(m_conditionPreVista); - MutexUnlock(mutex); - DWORD iWaitReturn = ::WaitForSingleObject(m_conditionPreVista, iTimeoutMs <= 0 ? 1000 : 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;