mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-12-03 03:31:27 +00:00
Make active object counts debug-only and atomic
This commit is contained in:
1 parent
7fd0f25967
commit
7d884fadc3
1 file changed
+19
-14
+19
-14
@@ -15,10 +15,12 @@ struct thread_context {
|
|||||||
const char* name;
|
const char* name;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int activeThreads = 0;
|
#ifdef LC_DEBUG
|
||||||
static int activeMutexes = 0;
|
static atomic_int activeThreads = 0;
|
||||||
static int activeEvents = 0;
|
static atomic_int activeMutexes = 0;
|
||||||
static int activeCondVars = 0;
|
static atomic_int activeEvents = 0;
|
||||||
|
static atomic_int activeCondVars = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LC_WINDOWS) && !defined(NXDK)
|
#if defined(LC_WINDOWS) && !defined(NXDK)
|
||||||
|
|
||||||
@@ -135,13 +137,14 @@ int PltCreateMutex(PLT_MUTEX* mutex) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LC_DEBUG
|
||||||
activeMutexes++;
|
activeMutexes++;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PltDeleteMutex(PLT_MUTEX* mutex) {
|
void PltDeleteMutex(PLT_MUTEX* mutex) {
|
||||||
LC_ASSERT(activeMutexes > 0);
|
LC_ASSERT(activeMutexes-- > 0);
|
||||||
activeMutexes--;
|
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
// No-op to destroy a SRWLOCK
|
// No-op to destroy a SRWLOCK
|
||||||
#elif defined(__WIIU__) || defined(__3DS__)
|
#elif defined(__WIIU__) || defined(__3DS__)
|
||||||
@@ -176,8 +179,7 @@ void PltUnlockMutex(PLT_MUTEX* mutex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PltJoinThread(PLT_THREAD* thread) {
|
void PltJoinThread(PLT_THREAD* thread) {
|
||||||
LC_ASSERT(activeThreads > 0);
|
LC_ASSERT(activeThreads-- > 0);
|
||||||
activeThreads--;
|
|
||||||
|
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
|
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
|
||||||
@@ -193,8 +195,7 @@ void PltJoinThread(PLT_THREAD* thread) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PltDetachThread(PLT_THREAD* thread) {
|
void PltDetachThread(PLT_THREAD* thread) {
|
||||||
LC_ASSERT(activeThreads > 0);
|
LC_ASSERT(activeThreads-- > 0);
|
||||||
activeThreads--;
|
|
||||||
|
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
// According MSDN:
|
// According MSDN:
|
||||||
@@ -309,7 +310,9 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef LC_DEBUG
|
||||||
activeThreads++;
|
activeThreads++;
|
||||||
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -330,13 +333,14 @@ int PltCreateEvent(PLT_EVENT* event) {
|
|||||||
}
|
}
|
||||||
event->signalled = false;
|
event->signalled = false;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LC_DEBUG
|
||||||
activeEvents++;
|
activeEvents++;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PltCloseEvent(PLT_EVENT* event) {
|
void PltCloseEvent(PLT_EVENT* event) {
|
||||||
LC_ASSERT(activeEvents > 0);
|
LC_ASSERT(activeEvents-- > 0);
|
||||||
activeEvents--;
|
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
CloseHandle(*event);
|
CloseHandle(*event);
|
||||||
#else
|
#else
|
||||||
@@ -388,13 +392,14 @@ int PltCreateConditionVariable(PLT_COND* cond, PLT_MUTEX* mutex) {
|
|||||||
#else
|
#else
|
||||||
pthread_cond_init(cond, NULL);
|
pthread_cond_init(cond, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef LC_DEBUG
|
||||||
activeCondVars++;
|
activeCondVars++;
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PltDeleteConditionVariable(PLT_COND* cond) {
|
void PltDeleteConditionVariable(PLT_COND* cond) {
|
||||||
LC_ASSERT(activeCondVars > 0);
|
LC_ASSERT(activeCondVars-- > 0);
|
||||||
activeCondVars--;
|
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
// No-op to delete a CONDITION_VARIABLE
|
// No-op to delete a CONDITION_VARIABLE
|
||||||
#elif defined(__WIIU__)
|
#elif defined(__WIIU__)
|
||||||
|
|||||||
Reference in new issue
Block a user