From: <man...@us...> - 2014-03-21 15:17:17
|
Revision: 3929 http://sourceforge.net/p/modplug/code/3929 Author: manxorist Date: 2014-03-21 15:17:06 +0000 (Fri, 21 Mar 2014) Log Message: ----------- [Mod] sounddev: SetWaitable timer is actually supported on all windows version. MSDN is sometimes really confusing. Use SetWaitable timer for all NT based kernels and timeSetEvent only for ancient Win98. This changes behaviour on Win2000, does anybody care? Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/sounddev/SoundDeviceThread.cpp trunk/OpenMPT/sounddev/SoundDeviceThread.h Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2014-03-21 10:22:26 UTC (rev 3928) +++ trunk/OpenMPT/common/misc_util.h 2014-03-21 15:17:06 UTC (rev 3929) @@ -654,6 +654,9 @@ enum WinNTVersion { + VerWinNT4 = 0x0400, + VerWin98 = 0x040a, + VerWinME = 0x045a, VerWin2000 = 0x0500, VerWinXP = 0x0501, VerWinXPSP2 = 0x0502, @@ -673,6 +676,16 @@ return ((uint32)mpt::saturate_cast<uint8>(versioninfo.dwMajorVersion) << 8) | (uint32)mpt::saturate_cast<uint8>(versioninfo.dwMinorVersion); } +static inline bool IsWinNT() +//-------------------------- +{ + OSVERSIONINFO versioninfo; + MemsetZero(versioninfo); + versioninfo.dwOSVersionInfoSize = sizeof(versioninfo); + GetVersionEx(&versioninfo); + return (versioninfo.dwPlatformId == VER_PLATFORM_WIN32_NT); +} + } // namespace Windows #endif // WIN32 Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.cpp 2014-03-21 10:22:26 UTC (rev 3928) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.cpp 2014-03-21 15:17:06 UTC (rev 3929) @@ -24,35 +24,8 @@ //------------------------------------------------------------------------------------------ { - m_HasXP = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinXP); + m_HasNTKernel = mpt::Windows::IsWinNT(); - pCreateWaitableTimer = nullptr; - pSetWaitableTimer = nullptr; - pCancelWaitableTimer = nullptr; - #if _WIN32_WINNT >= _WIN32_WINNT_WINXP - m_HasXP = true; - pCreateWaitableTimer = &CreateWaitableTimer; - pSetWaitableTimer = &SetWaitableTimer; - pCancelWaitableTimer = &CancelWaitableTimer; - #else - if(m_HasXP) - { - m_Kernel32DLL = mpt::Library(mpt::LibraryPath::System(MPT_PATHSTRING("kernel32"))); - if(!m_Kernel32DLL.Bind(pCreateWaitableTimer, "CreateWaitableTimerA")) - { - m_HasXP = false; - } - if(!m_Kernel32DLL.Bind(pSetWaitableTimer, "SetWaitableTimer")) - { - m_HasXP = false; - } - if(!m_Kernel32DLL.Bind(pCancelWaitableTimer, "CancelWaitableTimer")) - { - m_HasXP = false; - } - } - #endif - m_WakeupInterval = 0.0; m_hPlayThread = NULL; m_dwPlayThreadId = 0; @@ -93,11 +66,6 @@ CloseHandle(m_hAudioWakeUp); m_hAudioWakeUp = NULL; } - - pCreateWaitableTimer = nullptr; - pSetWaitableTimer = nullptr; - pCancelWaitableTimer = nullptr; - } @@ -184,8 +152,8 @@ Util::MultimediaClock clock_noxp; - bool period_noxp_set; - bool periodic_xp_timer; + bool period_nont_set; + bool periodic_nt_timer; HANDLE sleepEvent; @@ -200,28 +168,28 @@ if(sleepMilliseconds < 1) sleepMilliseconds = 1; if(sleep100Nanoseconds < 1) sleep100Nanoseconds = 1; - period_noxp_set = false; - periodic_xp_timer = (sleep100Nanoseconds >= 10000); // can be represented as a millisecond period, otherwise use non-periodic timers which allow higher precision but might me slower because we have to set them again in each period + period_nont_set = false; + periodic_nt_timer = (sleep100Nanoseconds >= 10000); // can be represented as a millisecond period, otherwise use non-periodic timers which allow higher precision but might me slower because we have to set them again in each period sleepEvent = NULL; - if(self.m_HasXP) + if(self.m_HasNTKernel) { - if(periodic_xp_timer) + if(periodic_nt_timer) { - sleepEvent = self.pCreateWaitableTimer(NULL, FALSE, NULL); + sleepEvent = CreateWaitableTimer(NULL, FALSE, NULL); LARGE_INTEGER dueTime; dueTime.QuadPart = 0 - sleep100Nanoseconds; // negative time means relative - self.pSetWaitableTimer(sleepEvent, &dueTime, sleepMilliseconds, NULL, NULL, FALSE); + SetWaitableTimer(sleepEvent, &dueTime, sleepMilliseconds, NULL, NULL, FALSE); } else { - sleepEvent = self.pCreateWaitableTimer(NULL, TRUE, NULL); + sleepEvent = CreateWaitableTimer(NULL, TRUE, NULL); } } else { sleepEvent = CreateEvent(NULL, FALSE, FALSE, NULL); clock_noxp.SetResolution(1); // increase resolution of multimedia timer - period_noxp_set = true; + period_nont_set = true; } } @@ -241,13 +209,13 @@ void Retrigger() //-------------- { - if(self.m_HasXP) + if(self.m_HasNTKernel) { - if(!periodic_xp_timer) + if(!periodic_nt_timer) { LARGE_INTEGER dueTime; dueTime.QuadPart = 0 - sleep100Nanoseconds; // negative time means relative - self.pSetWaitableTimer(sleepEvent, &dueTime, 0, NULL, NULL, FALSE); + SetWaitableTimer(sleepEvent, &dueTime, 0, NULL, NULL, FALSE); } } else { @@ -258,20 +226,20 @@ CPeriodicWaker::~CPeriodicWaker() //------------------------------- { - if(self.m_HasXP) + if(self.m_HasNTKernel) { - if(periodic_xp_timer) + if(periodic_nt_timer) { - self.pCancelWaitableTimer(sleepEvent); + CancelWaitableTimer(sleepEvent); } CloseHandle(sleepEvent); sleepEvent = NULL; } else { - if(period_noxp_set) + if(period_nont_set) { clock_noxp.SetResolution(0); - period_noxp_set = false; + period_nont_set = false; } CloseHandle(sleepEvent); sleepEvent = NULL; Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-03-21 10:22:26 UTC (rev 3928) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-03-21 15:17:06 UTC (rev 3929) @@ -44,14 +44,7 @@ private: CSoundDeviceWithThread & m_SoundDevice; - bool m_HasXP; - mpt::Library m_Kernel32DLL; - typedef HANDLE (WINAPI *FCreateWaitableTimer)(LPSECURITY_ATTRIBUTES, BOOL, LPCTSTR); - typedef BOOL (WINAPI *FSetWaitableTimer)(HANDLE, const LARGE_INTEGER *, LONG, PTIMERAPCROUTINE, LPVOID, BOOL); - typedef BOOL (WINAPI *FCancelWaitableTimer)(HANDLE); - FCreateWaitableTimer pCreateWaitableTimer; - FSetWaitableTimer pSetWaitableTimer; - FCancelWaitableTimer pCancelWaitableTimer; + bool m_HasNTKernel; double m_WakeupInterval; HANDLE m_hAudioWakeUp; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |