mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-02-16 10:30:59 +00:00
Use an interruptible sleep to allow our threads to exit sooner
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
|
||||
#include <enet/enet.h>
|
||||
|
||||
// The maximum amount of time before observing an interrupt
|
||||
// in PltSleepMsInterruptible().
|
||||
#define INTERRUPT_PERIOD_MS 50
|
||||
|
||||
int initializePlatformSockets(void);
|
||||
void cleanupPlatformSockets(void);
|
||||
|
||||
@@ -55,6 +59,14 @@ void PltSleepMs(int ms) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void PltSleepMsInterruptible(PLT_THREAD* thread, int ms) {
|
||||
while (ms > 0 && !PltIsThreadInterrupted(thread)) {
|
||||
int msToSleep = ms < INTERRUPT_PERIOD_MS ? ms : INTERRUPT_PERIOD_MS;
|
||||
PltSleepMs(msToSleep);
|
||||
ms -= msToSleep;
|
||||
}
|
||||
}
|
||||
|
||||
int PltCreateMutex(PLT_MUTEX* mutex) {
|
||||
#if defined(LC_WINDOWS)
|
||||
*mutex = CreateMutexEx(NULL, NULL, 0, MUTEX_ALL_ACCESS);
|
||||
|
||||
Reference in New Issue
Block a user