diff options
author | Jim Carroll <thecarrolls@jiminger.com> | 2013-08-24 21:57:40 -0400 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2013-08-24 23:25:32 -0400 |
commit | 76fe1512e6abfa2580dbd6cf796fddca2f43ae1f (patch) | |
tree | 9a2345e8748e1c846f76203c75641a29190b33f9 | |
parent | 49e9127aaa1336ff5cd143092d01ef203ecb51c4 (diff) |
Remove the Xp specific threading code.
-rw-r--r-- | project/VS2010Express/XbmcThreads.vcxproj | 1 | ||||
-rw-r--r-- | project/VS2010Express/XbmcThreads.vcxproj.filters | 3 | ||||
-rw-r--r-- | xbmc/threads/platform/Implementation.cpp | 2 | ||||
-rw-r--r-- | xbmc/threads/platform/win/Condition.h | 231 | ||||
-rw-r--r-- | xbmc/threads/platform/win/CriticalSection.h | 11 | ||||
-rw-r--r-- | xbmc/threads/platform/win/Implementation.cpp | 68 |
6 files changed, 22 insertions, 294 deletions
diff --git a/project/VS2010Express/XbmcThreads.vcxproj b/project/VS2010Express/XbmcThreads.vcxproj index 0741ef4e30..1cb9110269 100644 --- a/project/VS2010Express/XbmcThreads.vcxproj +++ b/project/VS2010Express/XbmcThreads.vcxproj @@ -19,7 +19,6 @@ <ClInclude Include="..\..\xbmc\threads\platform\win\ThreadImpl.cpp" /> <ClInclude Include="..\..\xbmc\threads\platform\ThreadImpl.cpp" /> <ClCompile Include="..\..\xbmc\threads\platform\Implementation.cpp" /> - <ClInclude Include="..\..\xbmc\threads\platform\win\Implementation.cpp" /> <ClCompile Include="..\..\xbmc\threads\platform\win\Win32Exception.cpp" /> <ClCompile Include="..\..\xbmc\threads\SystemClock.cpp" /> <ClCompile Include="..\..\xbmc\threads\Thread.cpp" /> diff --git a/project/VS2010Express/XbmcThreads.vcxproj.filters b/project/VS2010Express/XbmcThreads.vcxproj.filters index 843fd3a331..ba6170653d 100644 --- a/project/VS2010Express/XbmcThreads.vcxproj.filters +++ b/project/VS2010Express/XbmcThreads.vcxproj.filters @@ -58,9 +58,6 @@ <ClInclude Include="..\..\xbmc\threads\platform\ThreadImpl.cpp"> <Filter>platform</Filter> </ClInclude> - <ClInclude Include="..\..\xbmc\threads\platform\win\Implementation.cpp"> - <Filter>platform\win</Filter> - </ClInclude> <ClInclude Include="..\..\xbmc\threads\platform\win\Win32Exception.h"> <Filter>platform\win</Filter> </ClInclude> diff --git a/xbmc/threads/platform/Implementation.cpp b/xbmc/threads/platform/Implementation.cpp index 9b7e5e47f0..7363c751d2 100644 --- a/xbmc/threads/platform/Implementation.cpp +++ b/xbmc/threads/platform/Implementation.cpp @@ -20,6 +20,4 @@ #if (defined TARGET_POSIX) #include "threads/platform/pthreads/Implementation.cpp" -#elif (defined TARGET_WINDOWS) -#include "threads/platform/win/Implementation.cpp" #endif diff --git a/xbmc/threads/platform/win/Condition.h b/xbmc/threads/platform/win/Condition.h index 3070b4cfa0..ea6f5c5f18 100644 --- a/xbmc/threads/platform/win/Condition.h +++ b/xbmc/threads/platform/win/Condition.h @@ -27,227 +27,34 @@ namespace XbmcThreads { - class ConditionVariable; - - namespace intern - { - /** - * ConditionVariableXp is effectively a condition variable implementation - * assuming we're on Windows XP or earlier. This means we don't have - * access to InitializeConditionVariable and that the structure - * CONDITION_VARIABLE doesnt actually exist. - * - * This code is basically copied from SDL_syscond.c but structured to use - * native windows threading primitives rather than other SDL primitives. - */ - class ConditionVariableXp : public NonCopyable - { - friend class ConditionVariable; - CCriticalSection lock; - int waiting; - int signals; - - class Semaphore - { - friend class ConditionVariableXp; - HANDLE sem; - volatile LONG count; - - inline Semaphore() : count(0L), sem(NULL) { } - inline ~Semaphore() { if (sem) CloseHandle(sem); } - - inline void Init() { sem = CreateSemaphore(NULL,0,32*1024,NULL); } - - inline bool wait(DWORD dwMilliseconds) - { - return (WAIT_OBJECT_0 == WaitForSingleObject(sem, dwMilliseconds)) ? - (InterlockedDecrement(&count), true) : false; - } - - inline bool post() - { - /* Increase the counter in the first place, because - * after a successful release the semaphore may - * immediately get destroyed by another thread which - * is waiting for this semaphore. - */ - InterlockedIncrement(&count); - return ReleaseSemaphore(sem, 1, NULL) ? true : (InterlockedDecrement(&count), false); - } - }; - - Semaphore wait_sem; - Semaphore wait_done; - - inline ConditionVariableXp() : waiting(0), signals(0) { } - inline ~ConditionVariableXp() {} - - inline void Init() { wait_sem.Init(); wait_done.Init(); } - - inline void wait(CCriticalSection& mutex) - { - wait(mutex,(unsigned long)-1L); - } - - inline bool wait(CCriticalSection& mutex, unsigned long milliseconds) - { - bool success = false; - DWORD ms = ((unsigned long)-1L) == milliseconds ? INFINITE : (DWORD)milliseconds; - - { - CSingleLock l(lock); - waiting++; - } - - { - CSingleExit ex(mutex); - success = wait_sem.wait(ms); - - { - CSingleLock l(lock); - if (signals > 0) - { - if (!success) - wait_sem.wait(INFINITE); - wait_done.post(); - --signals; - } - --waiting; - } - } - - return success; - } - - - inline void wait(CSingleLock& lock) { wait(lock.get_underlying()); } - inline bool wait(CSingleLock& lock, unsigned long milliseconds) { return wait(lock.get_underlying(), milliseconds); } - - inline void notifyAll() - { - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - CSingleLock l(lock); - if ( waiting > signals ) - { - int i, num_waiting; - - num_waiting = (waiting - signals); - signals = waiting; - for ( i=0; i<num_waiting; ++i ) - wait_sem.post(); - - /* Now all released threads are blocked here, waiting for us. - Collect them all (and win fabulous prizes!) :-) - */ - l.Leave(); - for ( i=0; i<num_waiting; ++i ) - wait_done.wait(INFINITE); - } - } - - inline void notify() - { - /* If there are waiting threads not already signalled, then - signal the condition and wait for the thread to respond. - */ - CSingleLock l(lock); - if ( waiting > signals ) - { - ++signals; - wait_sem.post(); - l.Leave(); - wait_done.wait(INFINITE); - } - } - }; - - /** - * This is condition variable implementation that uses the Vista (or later) - * windows api but it is safe to compile, link, and load on Xp. - */ - class ConditionVariableVista : public NonCopyable - { - friend class ConditionVariable; - - CONDITION_VARIABLE cond; - - typedef VOID (WINAPI *TakesCV)(PCONDITION_VARIABLE); - typedef BOOL (WINAPI *SleepCVCS)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD); - - static bool setConditionVarFuncs(); - static TakesCV InitializeConditionVariableProc; - static SleepCVCS SleepConditionVariableCSProc; - static TakesCV WakeConditionVariableProc; - static TakesCV WakeAllConditionVariableProc; - - inline ConditionVariableVista() { } - - inline void Init() { (*InitializeConditionVariableProc)(&cond); } - - // apparently, windows condition variables do not need to be deleted - inline ~ConditionVariableVista() { } - - inline void wait(CCriticalSection& lock) - { - // even the windows implementation is capable of spontaneous wakes - (*SleepConditionVariableCSProc)(&cond,&lock.get_underlying().mutex,INFINITE); - } - - inline bool wait(CCriticalSection& lock, unsigned long milliseconds) - { - return (*SleepConditionVariableCSProc)(&cond,&lock.get_underlying().mutex,milliseconds) ? true : false; - } - - inline void wait(CSingleLock& lock) { wait(lock.get_underlying()); } - inline bool wait(CSingleLock& lock, unsigned long milliseconds) { return wait(lock.get_underlying(), milliseconds); } - inline void notifyAll() { (*WakeAllConditionVariableProc)(&cond); } - inline void notify() { (*WakeConditionVariableProc)(&cond); } - }; - } - -#define XBMC_CV(func) if (isVista) vistaimpl. func ;else xpimpl. func -#define XBMC_RCV(func) (isVista ? vistaimpl. func : xpimpl. func ) + /** + * This is condition variable implementation that uses the underlying + * Windows mechanisms and assumes Vista (or later) + */ class ConditionVariable : public NonCopyable { - // stupid hack for statics - static bool isIsVistaSet; - static bool isVista; - static bool getIsVista(); - intern::ConditionVariableXp xpimpl; - intern::ConditionVariableVista vistaimpl; + CONDITION_VARIABLE cond; + public: - inline ConditionVariable() - { - if (isIsVistaSet ? isVista : getIsVista()) - vistaimpl.Init(); - else - xpimpl.Init(); - } + inline ConditionVariable() { InitializeConditionVariable(&cond); } + + // apparently, windows condition variables do not need to be deleted + inline ~ConditionVariable() { } - inline void wait(CCriticalSection& lock) - { - int count = lock.count; - lock.count = 0; - XBMC_CV(wait(lock)); - lock.count = count; + inline void wait(CCriticalSection& lock) + { + // even the windows implementation is capable of spontaneous wakes + SleepConditionVariableCS(&cond,&lock.get_underlying().mutex,INFINITE); } - inline bool wait(CCriticalSection& lock, unsigned long milliseconds) - { - int count = lock.count; - lock.count = 0; - bool res = XBMC_RCV(wait(lock, milliseconds)); - lock.count = count; - return res; + inline bool wait(CCriticalSection& lock, unsigned long milliseconds) + { + return SleepConditionVariableCS(&cond,&lock.get_underlying().mutex,milliseconds) ? true : false; } inline void wait(CSingleLock& lock) { wait(lock.get_underlying()); } inline bool wait(CSingleLock& lock, unsigned long milliseconds) { return wait(lock.get_underlying(), milliseconds); } - - - inline void notifyAll() { XBMC_CV(notifyAll()); } - inline void notify() { XBMC_CV(notify()); } + inline void notifyAll() { WakeAllConditionVariable(&cond); } + inline void notify() { WakeConditionVariable(&cond); } }; } diff --git a/xbmc/threads/platform/win/CriticalSection.h b/xbmc/threads/platform/win/CriticalSection.h index daeb1fe866..464a3a1495 100644 --- a/xbmc/threads/platform/win/CriticalSection.h +++ b/xbmc/threads/platform/win/CriticalSection.h @@ -27,12 +27,8 @@ namespace XbmcThreads { - namespace intern - { - // forward declare in preparation for the friend declaration - class ConditionVariableVista; - class ConditionVariableXp; - } + // forward declare in preparation for the friend declaration + class ConditionVariable; namespace windows { @@ -41,8 +37,7 @@ namespace XbmcThreads CRITICAL_SECTION mutex; // needs acces to 'mutex' - friend class XbmcThreads::intern::ConditionVariableVista; - friend class XbmcThreads::intern::ConditionVariableXp; + friend class XbmcThreads::ConditionVariable; public: inline RecursiveMutex() { diff --git a/xbmc/threads/platform/win/Implementation.cpp b/xbmc/threads/platform/win/Implementation.cpp deleted file mode 100644 index 3e1cf26f8a..0000000000 --- a/xbmc/threads/platform/win/Implementation.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - * the Free Software Foundation; either version 2, 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 XBMC; see the file COPYING. If not, see - * <http://www.gnu.org/licenses/>. - * - */ - -#include "threads/Condition.h" - -namespace XbmcThreads -{ - - namespace intern - { - ConditionVariableVista::TakesCV ConditionVariableVista::InitializeConditionVariableProc; - ConditionVariableVista::SleepCVCS ConditionVariableVista::SleepConditionVariableCSProc; - ConditionVariableVista::TakesCV ConditionVariableVista::WakeConditionVariableProc; - ConditionVariableVista::TakesCV ConditionVariableVista::WakeAllConditionVariableProc; - - bool ConditionVariableVista::setConditionVarFuncs() - { - HMODULE mod = GetModuleHandle("Kernel32"); - - if (mod == NULL) - return false; - - InitializeConditionVariableProc = (TakesCV)GetProcAddress(mod,"InitializeConditionVariable"); - if (InitializeConditionVariableProc == NULL) - return false; - - SleepConditionVariableCSProc = (SleepCVCS)GetProcAddress(mod,"SleepConditionVariableCS"); - WakeAllConditionVariableProc = (TakesCV)GetProcAddress(mod,"WakeAllConditionVariable"); - WakeConditionVariableProc = (TakesCV)GetProcAddress(mod,"WakeConditionVariable"); - - return SleepConditionVariableCSProc != NULL && - WakeAllConditionVariableProc != NULL && - WakeConditionVariableProc != NULL; - } - } - - bool ConditionVariable::getIsVista() - { - if (!isIsVistaSet) - { - isVista = intern::ConditionVariableVista::setConditionVarFuncs(); - isIsVistaSet = true; - } - - return isVista; - } - - bool ConditionVariable::isVista = getIsVista(); - // bss segment nulled out by loader. - bool ConditionVariable::isIsVistaSet; -} |