Consolidate PltCloseThread() and PltJoinThread()

This commit is contained in:
Cameron Gutman 2024-02-17 18:14:03 -06:00
parent 9545dd7603
commit 9686f6942f
6 changed files with 7 additions and 64 deletions

View File

@ -128,7 +128,6 @@ void destroyAudioStream(void) {
if (pingThreadStarted) { if (pingThreadStarted) {
PltInterruptThread(&udpPingThread); PltInterruptThread(&udpPingThread);
PltJoinThread(&udpPingThread); PltJoinThread(&udpPingThread);
PltCloseThread(&udpPingThread);
} }
closeSocket(rtpSocket); closeSocket(rtpSocket);
@ -416,11 +415,6 @@ void stopAudioStream(void) {
PltJoinThread(&decoderThread); PltJoinThread(&decoderThread);
} }
PltCloseThread(&receiveThread);
if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
PltCloseThread(&decoderThread);
}
AudioCallbacks.cleanup(); AudioCallbacks.cleanup();
} }
@ -463,7 +457,6 @@ int startAudioStream(void* audioContext, int arFlags) {
AudioCallbacks.stop(); AudioCallbacks.stop();
PltInterruptThread(&receiveThread); PltInterruptThread(&receiveThread);
PltJoinThread(&receiveThread); PltJoinThread(&receiveThread);
PltCloseThread(&receiveThread);
closeSocket(rtpSocket); closeSocket(rtpSocket);
AudioCallbacks.cleanup(); AudioCallbacks.cleanup();
return err; return err;

View File

@ -1552,16 +1552,10 @@ int stopControlStream(void) {
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltJoinThread(&asyncCallbackThread); PltJoinThread(&asyncCallbackThread);
PltCloseThread(&lossStatsThread);
PltCloseThread(&requestIdrFrameThread);
PltCloseThread(&controlReceiveThread);
PltCloseThread(&asyncCallbackThread);
// We will only have an RFI thread if RFI is enabled // We will only have an RFI thread if RFI is enabled
if (isReferenceFrameInvalidationEnabled()) { if (isReferenceFrameInvalidationEnabled()) {
PltInterruptThread(&invalidateRefFramesThread); PltInterruptThread(&invalidateRefFramesThread);
PltJoinThread(&invalidateRefFramesThread); PltJoinThread(&invalidateRefFramesThread);
PltCloseThread(&invalidateRefFramesThread);
} }
if (peer != NULL) { if (peer != NULL) {
@ -1778,7 +1772,6 @@ int startControlStream(void) {
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltCloseThread(&controlReceiveThread);
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);
@ -1813,7 +1806,6 @@ int startControlStream(void) {
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltCloseThread(&controlReceiveThread);
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);
@ -1841,7 +1833,6 @@ int startControlStream(void) {
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltCloseThread(&controlReceiveThread);
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);
@ -1869,11 +1860,9 @@ int startControlStream(void) {
PltInterruptThread(&lossStatsThread); PltInterruptThread(&lossStatsThread);
PltJoinThread(&lossStatsThread); PltJoinThread(&lossStatsThread);
PltCloseThread(&lossStatsThread);
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltCloseThread(&controlReceiveThread);
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);
@ -1903,15 +1892,12 @@ int startControlStream(void) {
PltInterruptThread(&lossStatsThread); PltInterruptThread(&lossStatsThread);
PltJoinThread(&lossStatsThread); PltJoinThread(&lossStatsThread);
PltCloseThread(&lossStatsThread);
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltCloseThread(&controlReceiveThread);
PltInterruptThread(&requestIdrFrameThread); PltInterruptThread(&requestIdrFrameThread);
PltJoinThread(&requestIdrFrameThread); PltJoinThread(&requestIdrFrameThread);
PltCloseThread(&requestIdrFrameThread);
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);
@ -1944,19 +1930,15 @@ int startControlStream(void) {
PltInterruptThread(&lossStatsThread); PltInterruptThread(&lossStatsThread);
PltJoinThread(&lossStatsThread); PltJoinThread(&lossStatsThread);
PltCloseThread(&lossStatsThread);
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
PltJoinThread(&controlReceiveThread); PltJoinThread(&controlReceiveThread);
PltCloseThread(&controlReceiveThread);
PltInterruptThread(&requestIdrFrameThread); PltInterruptThread(&requestIdrFrameThread);
PltJoinThread(&requestIdrFrameThread); PltJoinThread(&requestIdrFrameThread);
PltCloseThread(&requestIdrFrameThread);
PltInterruptThread(&asyncCallbackThread); PltInterruptThread(&asyncCallbackThread);
PltJoinThread(&asyncCallbackThread); PltJoinThread(&asyncCallbackThread);
PltCloseThread(&asyncCallbackThread);
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);

View File

@ -736,7 +736,6 @@ int stopInputStream(void) {
// input packets before shutting down. // input packets before shutting down.
LbqSignalQueueDrain(&packetQueue); LbqSignalQueueDrain(&packetQueue);
PltJoinThread(&inputSendThread); PltJoinThread(&inputSendThread);
PltCloseThread(&inputSendThread);
if (inputSock != INVALID_SOCKET) { if (inputSock != INVALID_SOCKET) {
shutdownTcpSocket(inputSock); shutdownTcpSocket(inputSock);

View File

@ -186,25 +186,25 @@ void PltUnlockMutex(PLT_MUTEX* mutex) {
} }
void PltJoinThread(PLT_THREAD* thread) { void PltJoinThread(PLT_THREAD* thread) {
activeThreads--;
#if defined(LC_WINDOWS) #if defined(LC_WINDOWS)
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE); WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
CloseHandle(thread->handle);
#elif defined(__vita__) #elif defined(__vita__)
while(thread->alive) { sceKernelWaitThreadEnd(thread->handle, NULL, NULL);
PltSleepMs(10); sceKernelDeleteThread(thread->handle);
}
if (thread->context != NULL)
free(thread->context);
#elif defined(__WIIU__) #elif defined(__WIIU__)
OSJoinThread(&thread->thread, NULL); OSJoinThread(&thread->thread, NULL);
#elif defined(__3DS__) #elif defined(__3DS__)
threadJoin(thread->thread, U64_MAX); threadJoin(thread->thread, U64_MAX);
threadFree(thread->thread);
#else #else
pthread_join(thread->thread, NULL); pthread_join(thread->thread, NULL);
#endif #endif
} }
void PltDetachThread(PLT_THREAD* thread) void PltDetachThread(PLT_THREAD* thread) {
{
// Assume detached threads are no longer active // Assume detached threads are no longer active
activeThreads--; activeThreads--;
@ -223,21 +223,6 @@ void PltDetachThread(PLT_THREAD* thread)
#endif #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) { bool PltIsThreadInterrupted(PLT_THREAD* thread) {
return thread->cancelled; return thread->cancelled;
} }

View File

@ -62,7 +62,6 @@ void PltLockMutex(PLT_MUTEX* mutex);
void PltUnlockMutex(PLT_MUTEX* mutex); void PltUnlockMutex(PLT_MUTEX* mutex);
int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread); int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread);
void PltCloseThread(PLT_THREAD* thread);
void PltInterruptThread(PLT_THREAD* thread); void PltInterruptThread(PLT_THREAD* thread);
bool PltIsThreadInterrupted(PLT_THREAD* thread); bool PltIsThreadInterrupted(PLT_THREAD* thread);
void PltJoinThread(PLT_THREAD* thread); void PltJoinThread(PLT_THREAD* thread);

View File

@ -302,12 +302,6 @@ void stopVideoStream(void) {
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) { if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
PltJoinThread(&decoderThread); PltJoinThread(&decoderThread);
} }
PltCloseThread(&udpPingThread);
PltCloseThread(&receiveThread);
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
PltCloseThread(&decoderThread);
}
if (firstFrameSocket != INVALID_SOCKET) { if (firstFrameSocket != INVALID_SOCKET) {
closeSocket(firstFrameSocket); closeSocket(firstFrameSocket);
@ -360,7 +354,6 @@ int startVideoStream(void* rendererContext, int drFlags) {
VideoCallbacks.stop(); VideoCallbacks.stop();
PltInterruptThread(&receiveThread); PltInterruptThread(&receiveThread);
PltJoinThread(&receiveThread); PltJoinThread(&receiveThread);
PltCloseThread(&receiveThread);
closeSocket(rtpSocket); closeSocket(rtpSocket);
VideoCallbacks.cleanup(); VideoCallbacks.cleanup();
return err; return err;
@ -382,10 +375,6 @@ int startVideoStream(void* rendererContext, int drFlags) {
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) { if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
PltJoinThread(&decoderThread); PltJoinThread(&decoderThread);
} }
PltCloseThread(&receiveThread);
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
PltCloseThread(&decoderThread);
}
closeSocket(rtpSocket); closeSocket(rtpSocket);
VideoCallbacks.cleanup(); VideoCallbacks.cleanup();
return LastSocketError(); return LastSocketError();
@ -406,10 +395,6 @@ int startVideoStream(void* rendererContext, int drFlags) {
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) { if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
PltJoinThread(&decoderThread); PltJoinThread(&decoderThread);
} }
PltCloseThread(&receiveThread);
if ((VideoCallbacks.capabilities & (CAPABILITY_DIRECT_SUBMIT | CAPABILITY_PULL_RENDERER)) == 0) {
PltCloseThread(&decoderThread);
}
closeSocket(rtpSocket); closeSocket(rtpSocket);
if (firstFrameSocket != INVALID_SOCKET) { if (firstFrameSocket != INVALID_SOCKET) {
closeSocket(firstFrameSocket); closeSocket(firstFrameSocket);