mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 00:32:57 -04:00
Disable WinXP mutex emulation when _WIN32_WINNT >= 0x0600
This commit is contained in:
parent
89392f0e2d
commit
ab569916b1
@ -17,13 +17,18 @@
|
|||||||
|
|
||||||
#include "mutexWin32Impl.h"
|
#include "mutexWin32Impl.h"
|
||||||
|
|
||||||
|
// The number of spins to do before suspending the thread.
|
||||||
|
static const unsigned int spin_count = 4000;
|
||||||
|
|
||||||
|
// Only compile the below nonsense if we're not compiling for a Vista minimum.
|
||||||
|
#if _WIN32_WINNT < 0x0600
|
||||||
|
|
||||||
// If this is true, we will use SRWLock on Windows Vista and above instead of
|
// If this is true, we will use SRWLock on Windows Vista and above instead of
|
||||||
// our own implementation.
|
// our own implementation.
|
||||||
static const bool prefer_srwlock = true;
|
static const bool prefer_srwlock = true;
|
||||||
|
|
||||||
// These configure our own Windows XP implementation.
|
// These configure our own Windows XP implementation.
|
||||||
static const uintptr_t lock_bit = 0x40000000;
|
static const uintptr_t lock_bit = 0x40000000;
|
||||||
static const unsigned int spin_count = 4000;
|
|
||||||
|
|
||||||
// This gets set to spin_count if we are on a multi-core system.
|
// This gets set to spin_count if we are on a multi-core system.
|
||||||
static unsigned int effective_spin_count = 0;
|
static unsigned int effective_spin_count = 0;
|
||||||
@ -262,6 +267,8 @@ cvar_notify_all_xp(volatile PVOID *cvar) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // _WIN32_WINNT < 0x0600
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is put initially in the _lock slot; it makes sure that the lock
|
* This is put initially in the _lock slot; it makes sure that the lock
|
||||||
* functions get initialized the first time someone tries to grab a lock.
|
* functions get initialized the first time someone tries to grab a lock.
|
||||||
@ -282,17 +289,29 @@ try_lock_initially(volatile PVOID *lock) {
|
|||||||
return MutexWin32Impl::_funcs._try_lock(lock);
|
return MutexWin32Impl::_funcs._try_lock(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
/**
|
/**
|
||||||
* This gets put initially in the _unlock slot and should never be called,
|
* This gets put initially in the _unlock slot and should never be called,
|
||||||
* since the initial lock/try_lock implementation will replace the pointers.
|
* since the initial lock/try_lock implementation will replace the pointers.
|
||||||
*/
|
*/
|
||||||
void __stdcall MutexWin32Impl::
|
void __stdcall MutexWin32Impl::
|
||||||
unlock_initially(volatile PVOID *) {
|
unlock_initially(volatile PVOID *) {
|
||||||
|
#if !defined(NDEBUG) || defined(DEBUG_THREADS)
|
||||||
std::cerr << "Attempt to release a mutex at static init time before acquiring it!\n";
|
std::cerr << "Attempt to release a mutex at static init time before acquiring it!\n";
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as above for condition variables.
|
||||||
|
*/
|
||||||
|
static BOOL __stdcall
|
||||||
|
cvar_wait_initially(volatile PVOID *cvar, volatile PVOID *lock, DWORD timeout, ULONG) {
|
||||||
|
#if !defined(NDEBUG) || defined(DEBUG_THREADS)
|
||||||
|
std::cerr << "Attempt to wait for condition variable at static init time before acquiring mutex!\n";
|
||||||
|
assert(false);
|
||||||
|
#endif
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does nothing.
|
* Does nothing.
|
||||||
@ -312,7 +331,7 @@ MutexWin32Impl::LockFunctions MutexWin32Impl::_funcs = {
|
|||||||
&noop,
|
&noop,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
&cvar_wait_xp,
|
&cvar_wait_initially,
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
&MutexWin32Impl::unlock_initially,
|
&MutexWin32Impl::unlock_initially,
|
||||||
&MutexWin32Impl::unlock_initially,
|
&MutexWin32Impl::unlock_initially,
|
||||||
@ -332,6 +351,14 @@ init_lock_funcs() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _WIN32_WINNT >= 0x0600
|
||||||
|
_funcs._lock = (LockFunc)AcquireSRWLockExclusive;
|
||||||
|
_funcs._try_lock = (TryLockFunc)TryAcquireSRWLockExclusive;
|
||||||
|
_funcs._unlock = (LockFunc)ReleaseSRWLockExclusive;
|
||||||
|
_funcs._cvar_wait = (CondWaitFunc)SleepConditionVariableSRW;
|
||||||
|
_funcs._cvar_notify_one = (LockFunc)WakeConditionVariable;
|
||||||
|
_funcs._cvar_notify_all = (LockFunc)WakeAllConditionVariable;
|
||||||
|
#else
|
||||||
// We don't need to be very thread safe here. This can only ever be called
|
// We don't need to be very thread safe here. This can only ever be called
|
||||||
// at static init time, when there is still only one thread.
|
// at static init time, when there is still only one thread.
|
||||||
if (prefer_srwlock) {
|
if (prefer_srwlock) {
|
||||||
@ -370,6 +397,7 @@ init_lock_funcs() {
|
|||||||
} else {
|
} else {
|
||||||
effective_spin_count = 0;
|
effective_spin_count = 0;
|
||||||
}
|
}
|
||||||
|
#endif // _WIN32_WINNT < 0x0600
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user