mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-07-01 15:25:43 +00:00
Consolidate PltCloseThread() and PltJoinThread()
This commit is contained in:
parent
9545dd7603
commit
9686f6942f
@ -128,7 +128,6 @@ void destroyAudioStream(void) {
|
||||
if (pingThreadStarted) {
|
||||
PltInterruptThread(&udpPingThread);
|
||||
PltJoinThread(&udpPingThread);
|
||||
PltCloseThread(&udpPingThread);
|
||||
}
|
||||
|
||||
closeSocket(rtpSocket);
|
||||
@ -416,11 +415,6 @@ void stopAudioStream(void) {
|
||||
PltJoinThread(&decoderThread);
|
||||
}
|
||||
|
||||
PltCloseThread(&receiveThread);
|
||||
if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||
PltCloseThread(&decoderThread);
|
||||
}
|
||||
|
||||
AudioCallbacks.cleanup();
|
||||
}
|
||||
|
||||
@ -463,7 +457,6 @@ int startAudioStream(void* audioContext, int arFlags) {
|
||||
AudioCallbacks.stop();
|
||||
PltInterruptThread(&receiveThread);
|
||||
PltJoinThread(&receiveThread);
|
||||
PltCloseThread(&receiveThread);
|
||||
closeSocket(rtpSocket);
|
||||
AudioCallbacks.cleanup();
|
||||
return err;
|
||||
|
@ -1552,16 +1552,10 @@ int stopControlStream(void) {
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltJoinThread(&asyncCallbackThread);
|
||||
|
||||
PltCloseThread(&lossStatsThread);
|
||||
PltCloseThread(&requestIdrFrameThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
PltCloseThread(&asyncCallbackThread);
|
||||
|
||||
// We will only have an RFI thread if RFI is enabled
|
||||
if (isReferenceFrameInvalidationEnabled()) {
|
||||
PltInterruptThread(&invalidateRefFramesThread);
|
||||
PltJoinThread(&invalidateRefFramesThread);
|
||||
PltCloseThread(&invalidateRefFramesThread);
|
||||
}
|
||||
|
||||
if (peer != NULL) {
|
||||
@ -1778,7 +1772,6 @@ int startControlStream(void) {
|
||||
|
||||
PltInterruptThread(&controlReceiveThread);
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
|
||||
if (ctlSock != INVALID_SOCKET) {
|
||||
closeSocket(ctlSock);
|
||||
@ -1813,7 +1806,6 @@ int startControlStream(void) {
|
||||
|
||||
PltInterruptThread(&controlReceiveThread);
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
|
||||
if (ctlSock != INVALID_SOCKET) {
|
||||
closeSocket(ctlSock);
|
||||
@ -1841,7 +1833,6 @@ int startControlStream(void) {
|
||||
|
||||
PltInterruptThread(&controlReceiveThread);
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
|
||||
if (ctlSock != INVALID_SOCKET) {
|
||||
closeSocket(ctlSock);
|
||||
@ -1869,11 +1860,9 @@ int startControlStream(void) {
|
||||
|
||||
PltInterruptThread(&lossStatsThread);
|
||||
PltJoinThread(&lossStatsThread);
|
||||
PltCloseThread(&lossStatsThread);
|
||||
|
||||
PltInterruptThread(&controlReceiveThread);
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
|
||||
if (ctlSock != INVALID_SOCKET) {
|
||||
closeSocket(ctlSock);
|
||||
@ -1903,15 +1892,12 @@ int startControlStream(void) {
|
||||
|
||||
PltInterruptThread(&lossStatsThread);
|
||||
PltJoinThread(&lossStatsThread);
|
||||
PltCloseThread(&lossStatsThread);
|
||||
|
||||
PltInterruptThread(&controlReceiveThread);
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
|
||||
PltInterruptThread(&requestIdrFrameThread);
|
||||
PltJoinThread(&requestIdrFrameThread);
|
||||
PltCloseThread(&requestIdrFrameThread);
|
||||
|
||||
if (ctlSock != INVALID_SOCKET) {
|
||||
closeSocket(ctlSock);
|
||||
@ -1944,19 +1930,15 @@ int startControlStream(void) {
|
||||
|
||||
PltInterruptThread(&lossStatsThread);
|
||||
PltJoinThread(&lossStatsThread);
|
||||
PltCloseThread(&lossStatsThread);
|
||||
|
||||
PltInterruptThread(&controlReceiveThread);
|
||||
PltJoinThread(&controlReceiveThread);
|
||||
PltCloseThread(&controlReceiveThread);
|
||||
|
||||
PltInterruptThread(&requestIdrFrameThread);
|
||||
PltJoinThread(&requestIdrFrameThread);
|
||||
PltCloseThread(&requestIdrFrameThread);
|
||||
|
||||
PltInterruptThread(&asyncCallbackThread);
|
||||
PltJoinThread(&asyncCallbackThread);
|
||||
PltCloseThread(&asyncCallbackThread);
|
||||
|
||||
if (ctlSock != INVALID_SOCKET) {
|
||||
closeSocket(ctlSock);
|
||||
|
@ -736,7 +736,6 @@ int stopInputStream(void) {
|
||||
// input packets before shutting down.
|
||||
LbqSignalQueueDrain(&packetQueue);
|
||||
PltJoinThread(&inputSendThread);
|
||||
PltCloseThread(&inputSendThread);
|
||||
|
||||
if (inputSock != INVALID_SOCKET) {
|
||||
shutdownTcpSocket(inputSock);
|
||||
|
@ -186,25 +186,25 @@ void PltUnlockMutex(PLT_MUTEX* mutex) {
|
||||
}
|
||||
|
||||
void PltJoinThread(PLT_THREAD* thread) {
|
||||
activeThreads--;
|
||||
|
||||
#if defined(LC_WINDOWS)
|
||||
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
|
||||
CloseHandle(thread->handle);
|
||||
#elif defined(__vita__)
|
||||
while(thread->alive) {
|
||||
PltSleepMs(10);
|
||||
}
|
||||
if (thread->context != NULL)
|
||||
free(thread->context);
|
||||
sceKernelWaitThreadEnd(thread->handle, NULL, NULL);
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
#elif defined(__WIIU__)
|
||||
OSJoinThread(&thread->thread, NULL);
|
||||
#elif defined(__3DS__)
|
||||
threadJoin(thread->thread, U64_MAX);
|
||||
threadFree(thread->thread);
|
||||
#else
|
||||
pthread_join(thread->thread, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PltDetachThread(PLT_THREAD* thread)
|
||||
{
|
||||
void PltDetachThread(PLT_THREAD* thread) {
|
||||
// Assume detached threads are no longer active
|
||||
activeThreads--;
|
||||
|
||||
@ -223,21 +223,6 @@ void PltDetachThread(PLT_THREAD* thread)
|
||||
#endif
|
||||
}
|
||||
|
||||
void PltCloseThread(PLT_THREAD* thread) {
|
||||
activeThreads--;
|
||||
#if defined(LC_WINDOWS)
|
||||
CloseHandle(thread->handle);
|
||||
#elif defined(__vita__)
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
#elif defined(__WIIU__)
|
||||
// Thread is automatically closed after join
|
||||
#elif defined(__3DS__)
|
||||
threadFree(thread->thread);
|
||||
#else
|
||||
// Thread is automatically closed after join
|
||||
#endif
|
||||
}
|
||||
|
||||
bool PltIsThreadInterrupted(PLT_THREAD* thread) {
|
||||
return thread->cancelled;
|
||||
}
|
||||
|
@ -62,7 +62,6 @@ void PltLockMutex(PLT_MUTEX* mutex);
|
||||
void PltUnlockMutex(PLT_MUTEX* mutex);
|
||||
|
||||
int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread);
|
||||
void PltCloseThread(PLT_THREAD* thread);
|
||||
void PltInterruptThread(PLT_THREAD* thread);
|
||||
bool PltIsThreadInterrupted(PLT_THREAD* thread);
|
||||
void PltJoinThread(PLT_THREAD* thread);
|
||||
|
@ -303,12 +303,6 @@ void stopVideoStream(void) {
|
||||
PltJoinThread(&decoderThread);
|
||||
}
|
||||
|
||||
PltCloseThread(&udpPingThread);
|
||||
PltCloseThread(&receiveThread);
|
||||
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
|
||||
PltCloseThread(&decoderThread);
|
||||
}
|
||||
|
||||
if (firstFrameSocket != INVALID_SOCKET) {
|
||||
closeSocket(firstFrameSocket);
|
||||
firstFrameSocket = INVALID_SOCKET;
|
||||
@ -360,7 +354,6 @@ int startVideoStream(void* rendererContext, int drFlags) {
|
||||
VideoCallbacks.stop();
|
||||
PltInterruptThread(&receiveThread);
|
||||
PltJoinThread(&receiveThread);
|
||||
PltCloseThread(&receiveThread);
|
||||
closeSocket(rtpSocket);
|
||||
VideoCallbacks.cleanup();
|
||||
return err;
|
||||
@ -382,10 +375,6 @@ int startVideoStream(void* rendererContext, int drFlags) {
|
||||
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
|
||||
PltJoinThread(&decoderThread);
|
||||
}
|
||||
PltCloseThread(&receiveThread);
|
||||
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
|
||||
PltCloseThread(&decoderThread);
|
||||
}
|
||||
closeSocket(rtpSocket);
|
||||
VideoCallbacks.cleanup();
|
||||
return LastSocketError();
|
||||
@ -406,10 +395,6 @@ int startVideoStream(void* rendererContext, int drFlags) {
|
||||
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
|
||||
PltJoinThread(&decoderThread);
|
||||
}
|
||||
PltCloseThread(&receiveThread);
|
||||
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
|
||||
PltCloseThread(&decoderThread);
|
||||
}
|
||||
closeSocket(rtpSocket);
|
||||
if (firstFrameSocket != INVALID_SOCKET) {
|
||||
closeSocket(firstFrameSocket);
|
||||
|
Loading…
x
Reference in New Issue
Block a user