mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Use an interruptible sleep to allow our threads to exit sooner
This commit is contained in:
parent
9220fcb8e8
commit
d6971983aa
@ -114,10 +114,10 @@ static void UdpPingThreadProc(void* context) {
|
||||
|
||||
// Send less frequently if we've received data from our peer
|
||||
if (receivedDataFromPeer) {
|
||||
PltSleepMs(5000);
|
||||
PltSleepMsInterruptible(&udpPingThread, 5000);
|
||||
}
|
||||
else {
|
||||
PltSleepMs(1000);
|
||||
PltSleepMsInterruptible(&udpPingThread, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ static void controlReceiveThreadFunc(void* context) {
|
||||
}
|
||||
else {
|
||||
// No events ready
|
||||
PltSleepMs(100);
|
||||
PltSleepMsInterruptible(&controlReceiveThread, 100);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -617,7 +617,7 @@ static void lossStatsThreadFunc(void* context) {
|
||||
lossCountSinceLastReport = 0;
|
||||
|
||||
// Wait a bit
|
||||
PltSleepMs(LOSS_REPORT_INTERVAL_MS);
|
||||
PltSleepMsInterruptible(&lossStatsThread, LOSS_REPORT_INTERVAL_MS);
|
||||
}
|
||||
|
||||
free(lossStatsPayload);
|
||||
|
@ -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);
|
||||
|
@ -62,4 +62,5 @@ void PltRunThreadProc(void);
|
||||
#define PLT_WAIT_SUCCESS 0
|
||||
#define PLT_WAIT_INTERRUPTED 1
|
||||
|
||||
void PltSleepMs(int ms);
|
||||
void PltSleepMs(int ms);
|
||||
void PltSleepMsInterruptible(PLT_THREAD* thread, int ms);
|
||||
|
@ -60,10 +60,10 @@ static void UdpPingThreadProc(void* context) {
|
||||
|
||||
// Send less frequently if we've received data from our peer
|
||||
if (receivedDataFromPeer) {
|
||||
PltSleepMs(5000);
|
||||
PltSleepMsInterruptible(&udpPingThread, 5000);
|
||||
}
|
||||
else {
|
||||
PltSleepMs(500);
|
||||
PltSleepMsInterruptible(&udpPingThread, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user