mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 09:25:49 +00:00
Use SRW locks for our mutex on Windows
These avoid a kernel transition for uncontended cases
This commit is contained in:
parent
13041e0323
commit
ae92f15b0a
@ -124,10 +124,7 @@ void PltSleepMsInterruptible(PLT_THREAD* thread, int ms) {
|
|||||||
|
|
||||||
int PltCreateMutex(PLT_MUTEX* mutex) {
|
int PltCreateMutex(PLT_MUTEX* mutex) {
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
*mutex = CreateMutexEx(NULL, NULL, 0, MUTEX_ALL_ACCESS);
|
InitializeSRWLock(mutex);
|
||||||
if (!*mutex) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#elif defined(__vita__)
|
#elif defined(__vita__)
|
||||||
*mutex = sceKernelCreateMutex("", 0, 0, NULL);
|
*mutex = sceKernelCreateMutex("", 0, 0, NULL);
|
||||||
if (*mutex < 0) {
|
if (*mutex < 0) {
|
||||||
@ -146,7 +143,7 @@ int PltCreateMutex(PLT_MUTEX* mutex) {
|
|||||||
void PltDeleteMutex(PLT_MUTEX* mutex) {
|
void PltDeleteMutex(PLT_MUTEX* mutex) {
|
||||||
activeMutexes--;
|
activeMutexes--;
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
CloseHandle(*mutex);
|
// No-op to destroy a SRWLOCK
|
||||||
#elif defined(__vita__)
|
#elif defined(__vita__)
|
||||||
sceKernelDeleteMutex(*mutex);
|
sceKernelDeleteMutex(*mutex);
|
||||||
#else
|
#else
|
||||||
@ -156,11 +153,7 @@ void PltDeleteMutex(PLT_MUTEX* mutex) {
|
|||||||
|
|
||||||
void PltLockMutex(PLT_MUTEX* mutex) {
|
void PltLockMutex(PLT_MUTEX* mutex) {
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
int err;
|
AcquireSRWLockExclusive(mutex);
|
||||||
err = WaitForSingleObjectEx(*mutex, INFINITE, FALSE);
|
|
||||||
if (err != WAIT_OBJECT_0) {
|
|
||||||
LC_ASSERT(false);
|
|
||||||
}
|
|
||||||
#elif defined(__vita__)
|
#elif defined(__vita__)
|
||||||
sceKernelLockMutex(*mutex, 1, NULL);
|
sceKernelLockMutex(*mutex, 1, NULL);
|
||||||
#else
|
#else
|
||||||
@ -170,7 +163,7 @@ void PltLockMutex(PLT_MUTEX* mutex) {
|
|||||||
|
|
||||||
void PltUnlockMutex(PLT_MUTEX* mutex) {
|
void PltUnlockMutex(PLT_MUTEX* mutex) {
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
ReleaseMutex(*mutex);
|
ReleaseSRWLockExclusive(mutex);
|
||||||
#elif defined(__vita__)
|
#elif defined(__vita__)
|
||||||
sceKernelUnlockMutex(*mutex, 1);
|
sceKernelUnlockMutex(*mutex, 1);
|
||||||
#else
|
#else
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
typedef void(*ThreadEntry)(void* context);
|
typedef void(*ThreadEntry)(void* context);
|
||||||
|
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
typedef HANDLE PLT_MUTEX;
|
typedef SRWLOCK PLT_MUTEX;
|
||||||
typedef HANDLE PLT_EVENT;
|
typedef HANDLE PLT_EVENT;
|
||||||
typedef struct _PLT_THREAD {
|
typedef struct _PLT_THREAD {
|
||||||
HANDLE handle;
|
HANDLE handle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user