mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 06:11:03 +00:00
Use an interruptible sleep to allow our threads to exit sooner
This commit is contained in:
+2
-2
@@ -114,10 +114,10 @@ static void UdpPingThreadProc(void* context) {
|
|||||||
|
|
||||||
// Send less frequently if we've received data from our peer
|
// Send less frequently if we've received data from our peer
|
||||||
if (receivedDataFromPeer) {
|
if (receivedDataFromPeer) {
|
||||||
PltSleepMs(5000);
|
PltSleepMsInterruptible(&udpPingThread, 5000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PltSleepMs(1000);
|
PltSleepMsInterruptible(&udpPingThread, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -511,7 +511,7 @@ static void controlReceiveThreadFunc(void* context) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// No events ready
|
// No events ready
|
||||||
PltSleepMs(100);
|
PltSleepMsInterruptible(&controlReceiveThread, 100);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -617,7 +617,7 @@ static void lossStatsThreadFunc(void* context) {
|
|||||||
lossCountSinceLastReport = 0;
|
lossCountSinceLastReport = 0;
|
||||||
|
|
||||||
// Wait a bit
|
// Wait a bit
|
||||||
PltSleepMs(LOSS_REPORT_INTERVAL_MS);
|
PltSleepMsInterruptible(&lossStatsThread, LOSS_REPORT_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(lossStatsPayload);
|
free(lossStatsPayload);
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
#include <enet/enet.h>
|
#include <enet/enet.h>
|
||||||
|
|
||||||
|
// The maximum amount of time before observing an interrupt
|
||||||
|
// in PltSleepMsInterruptible().
|
||||||
|
#define INTERRUPT_PERIOD_MS 50
|
||||||
|
|
||||||
int initializePlatformSockets(void);
|
int initializePlatformSockets(void);
|
||||||
void cleanupPlatformSockets(void);
|
void cleanupPlatformSockets(void);
|
||||||
|
|
||||||
@@ -55,6 +59,14 @@ void PltSleepMs(int ms) {
|
|||||||
#endif
|
#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) {
|
int PltCreateMutex(PLT_MUTEX* mutex) {
|
||||||
#if defined(LC_WINDOWS)
|
#if defined(LC_WINDOWS)
|
||||||
*mutex = CreateMutexEx(NULL, NULL, 0, MUTEX_ALL_ACCESS);
|
*mutex = CreateMutexEx(NULL, NULL, 0, MUTEX_ALL_ACCESS);
|
||||||
|
|||||||
@@ -62,4 +62,5 @@ void PltRunThreadProc(void);
|
|||||||
#define PLT_WAIT_SUCCESS 0
|
#define PLT_WAIT_SUCCESS 0
|
||||||
#define PLT_WAIT_INTERRUPTED 1
|
#define PLT_WAIT_INTERRUPTED 1
|
||||||
|
|
||||||
void PltSleepMs(int ms);
|
void PltSleepMs(int ms);
|
||||||
|
void PltSleepMsInterruptible(PLT_THREAD* thread, int ms);
|
||||||
|
|||||||
+2
-2
@@ -60,10 +60,10 @@ static void UdpPingThreadProc(void* context) {
|
|||||||
|
|
||||||
// Send less frequently if we've received data from our peer
|
// Send less frequently if we've received data from our peer
|
||||||
if (receivedDataFromPeer) {
|
if (receivedDataFromPeer) {
|
||||||
PltSleepMs(5000);
|
PltSleepMsInterruptible(&udpPingThread, 5000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PltSleepMs(500);
|
PltSleepMsInterruptible(&udpPingThread, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user