From 31aa893acd2d82e1d46e200250da44c15dfce000 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 3 May 2019 18:54:40 -0700 Subject: [PATCH] Name our threads on Linux --- src/AudioStream.c | 6 +++--- src/Connection.c | 2 +- src/ControlStream.c | 6 +++--- src/InputStream.c | 2 +- src/Platform.c | 10 ++++++++-- src/PlatformThreads.h | 10 +++++----- src/VideoStream.c | 6 +++--- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/AudioStream.c b/src/AudioStream.c index ae2a493..d8160fa 100644 --- a/src/AudioStream.c +++ b/src/AudioStream.c @@ -353,7 +353,7 @@ int startAudioStream(void* audioContext, int arFlags) { AudioCallbacks.start(); - err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread); + err = PltCreateThread("AudioRecv", ReceiveThreadProc, NULL, &receiveThread); if (err != 0) { AudioCallbacks.stop(); closeSocket(rtpSocket); @@ -362,7 +362,7 @@ int startAudioStream(void* audioContext, int arFlags) { } if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) { - err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread); + err = PltCreateThread("AudioDec", DecoderThreadProc, NULL, &decoderThread); if (err != 0) { AudioCallbacks.stop(); PltInterruptThread(&receiveThread); @@ -378,7 +378,7 @@ int startAudioStream(void* audioContext, int arFlags) { // until everything else is started. Otherwise we could accumulate a // bunch of audio packets in the socket receive buffer while our audio // backend is starting up and create audio latency. - err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread); + err = PltCreateThread("AudioPing", UdpPingThreadProc, NULL, &udpPingThread); if (err != 0) { AudioCallbacks.stop(); PltInterruptThread(&receiveThread); diff --git a/src/Connection.c b/src/Connection.c index edb0d97..3361087 100644 --- a/src/Connection.c +++ b/src/Connection.c @@ -152,7 +152,7 @@ static void ClInternalConnectionTerminated(long errorCode) alreadyTerminated = 1; // Invoke the termination callback on a separate thread - err = PltCreateThread(terminationCallbackThreadFunc, NULL, &terminationCallbackThread); + err = PltCreateThread("AsyncTerm", terminationCallbackThreadFunc, NULL, &terminationCallbackThread); if (err != 0) { // Nothing we can safely do here, so we'll just assert on debug builds Limelog("Failed to create termination thread: %d\n", err); diff --git a/src/ControlStream.c b/src/ControlStream.c index 78435a1..c379cc0 100644 --- a/src/ControlStream.c +++ b/src/ControlStream.c @@ -834,7 +834,7 @@ int startControlStream(void) { enableNoDelay(ctlSock); } - err = PltCreateThread(controlReceiveThreadFunc, NULL, &controlReceiveThread); + err = PltCreateThread("ControlRecv", controlReceiveThreadFunc, NULL, &controlReceiveThread); if (err != 0) { stopping = 1; if (ctlSock != INVALID_SOCKET) { @@ -914,7 +914,7 @@ int startControlStream(void) { return err; } - err = PltCreateThread(lossStatsThreadFunc, NULL, &lossStatsThread); + err = PltCreateThread("LossStats", lossStatsThreadFunc, NULL, &lossStatsThread); if (err != 0) { stopping = 1; @@ -942,7 +942,7 @@ int startControlStream(void) { return err; } - err = PltCreateThread(invalidateRefFramesFunc, NULL, &invalidateRefFramesThread); + err = PltCreateThread("InvRefFrames", invalidateRefFramesFunc, NULL, &invalidateRefFramesThread); if (err != 0) { stopping = 1; diff --git a/src/InputStream.c b/src/InputStream.c index d5f2c6a..23b6c95 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -388,7 +388,7 @@ int startInputStream(void) { enableNoDelay(inputSock); } - err = PltCreateThread(inputSendThreadProc, NULL, &inputSendThread); + err = PltCreateThread("InputSend", inputSendThreadProc, NULL, &inputSendThread); if (err != 0) { if (inputSock != INVALID_SOCKET) { closeSocket(inputSock); diff --git a/src/Platform.c b/src/Platform.c index c74e0ed..888f8cd 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include "PlatformThreads.h" #include "Platform.h" @@ -155,7 +157,7 @@ void PltInterruptThread(PLT_THREAD* thread) { thread->cancelled = 1; } -int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD* thread) { +int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread) { struct thread_context* ctx; ctx = (struct thread_context*)malloc(sizeof(*ctx)); @@ -181,7 +183,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD* thread) { thread->alive = 1; thread->context = ctx; ctx->thread = thread; - thread->handle = sceKernelCreateThread("", ThreadProc, 0, 0x40000, 0, 0, NULL); + thread->handle = sceKernelCreateThread(name, ThreadProc, 0, 0x40000, 0, 0, NULL); if (thread->handle < 0) { free(ctx); return -1; @@ -195,6 +197,10 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD* thread) { free(ctx); return err; } + +#ifdef __linux__ + pthread_setname_np(thread->thread, name); +#endif } #endif diff --git a/src/PlatformThreads.h b/src/PlatformThreads.h index a6b6675..78d11b4 100644 --- a/src/PlatformThreads.h +++ b/src/PlatformThreads.h @@ -45,11 +45,11 @@ void PltDeleteMutex(PLT_MUTEX* mutex); void PltLockMutex(PLT_MUTEX* mutex); void PltUnlockMutex(PLT_MUTEX* mutex); -int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD*thread); -void PltCloseThread(PLT_THREAD*thread); -void PltInterruptThread(PLT_THREAD*thread); -int PltIsThreadInterrupted(PLT_THREAD*thread); -void PltJoinThread(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); +int PltIsThreadInterrupted(PLT_THREAD* thread); +void PltJoinThread(PLT_THREAD* thread); int PltCreateEvent(PLT_EVENT* event); void PltCloseEvent(PLT_EVENT* event); diff --git a/src/VideoStream.c b/src/VideoStream.c index 73a45a6..d497649 100644 --- a/src/VideoStream.c +++ b/src/VideoStream.c @@ -222,7 +222,7 @@ int startVideoStream(void* rendererContext, int drFlags) { VideoCallbacks.start(); - err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread); + err = PltCreateThread("VideoRecv", ReceiveThreadProc, NULL, &receiveThread); if (err != 0) { VideoCallbacks.stop(); closeSocket(rtpSocket); @@ -231,7 +231,7 @@ int startVideoStream(void* rendererContext, int drFlags) { } if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) { - err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread); + err = PltCreateThread("VideoDec", DecoderThreadProc, NULL, &decoderThread); if (err != 0) { VideoCallbacks.stop(); PltInterruptThread(&receiveThread); @@ -270,7 +270,7 @@ int startVideoStream(void* rendererContext, int drFlags) { // Start pinging before reading the first frame so GFE knows where // to send UDP data - err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread); + err = PltCreateThread("VideoPing", UdpPingThreadProc, NULL, &udpPingThread); if (err != 0) { VideoCallbacks.stop(); stopVideoDepacketizer();