Name our threads on Linux

This commit is contained in:
Cameron Gutman 2019-05-03 18:54:40 -07:00
parent e01617cd17
commit 31aa893acd
7 changed files with 24 additions and 18 deletions

View File

@ -353,7 +353,7 @@ int startAudioStream(void* audioContext, int arFlags) {
AudioCallbacks.start(); AudioCallbacks.start();
err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread); err = PltCreateThread("AudioRecv", ReceiveThreadProc, NULL, &receiveThread);
if (err != 0) { if (err != 0) {
AudioCallbacks.stop(); AudioCallbacks.stop();
closeSocket(rtpSocket); closeSocket(rtpSocket);
@ -362,7 +362,7 @@ int startAudioStream(void* audioContext, int arFlags) {
} }
if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) { if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread); err = PltCreateThread("AudioDec", DecoderThreadProc, NULL, &decoderThread);
if (err != 0) { if (err != 0) {
AudioCallbacks.stop(); AudioCallbacks.stop();
PltInterruptThread(&receiveThread); PltInterruptThread(&receiveThread);
@ -378,7 +378,7 @@ int startAudioStream(void* audioContext, int arFlags) {
// until everything else is started. Otherwise we could accumulate a // until everything else is started. Otherwise we could accumulate a
// bunch of audio packets in the socket receive buffer while our audio // bunch of audio packets in the socket receive buffer while our audio
// backend is starting up and create audio latency. // backend is starting up and create audio latency.
err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread); err = PltCreateThread("AudioPing", UdpPingThreadProc, NULL, &udpPingThread);
if (err != 0) { if (err != 0) {
AudioCallbacks.stop(); AudioCallbacks.stop();
PltInterruptThread(&receiveThread); PltInterruptThread(&receiveThread);

View File

@ -152,7 +152,7 @@ static void ClInternalConnectionTerminated(long errorCode)
alreadyTerminated = 1; alreadyTerminated = 1;
// Invoke the termination callback on a separate thread // Invoke the termination callback on a separate thread
err = PltCreateThread(terminationCallbackThreadFunc, NULL, &terminationCallbackThread); err = PltCreateThread("AsyncTerm", terminationCallbackThreadFunc, NULL, &terminationCallbackThread);
if (err != 0) { if (err != 0) {
// Nothing we can safely do here, so we'll just assert on debug builds // Nothing we can safely do here, so we'll just assert on debug builds
Limelog("Failed to create termination thread: %d\n", err); Limelog("Failed to create termination thread: %d\n", err);

View File

@ -834,7 +834,7 @@ int startControlStream(void) {
enableNoDelay(ctlSock); enableNoDelay(ctlSock);
} }
err = PltCreateThread(controlReceiveThreadFunc, NULL, &controlReceiveThread); err = PltCreateThread("ControlRecv", controlReceiveThreadFunc, NULL, &controlReceiveThread);
if (err != 0) { if (err != 0) {
stopping = 1; stopping = 1;
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
@ -914,7 +914,7 @@ int startControlStream(void) {
return err; return err;
} }
err = PltCreateThread(lossStatsThreadFunc, NULL, &lossStatsThread); err = PltCreateThread("LossStats", lossStatsThreadFunc, NULL, &lossStatsThread);
if (err != 0) { if (err != 0) {
stopping = 1; stopping = 1;
@ -942,7 +942,7 @@ int startControlStream(void) {
return err; return err;
} }
err = PltCreateThread(invalidateRefFramesFunc, NULL, &invalidateRefFramesThread); err = PltCreateThread("InvRefFrames", invalidateRefFramesFunc, NULL, &invalidateRefFramesThread);
if (err != 0) { if (err != 0) {
stopping = 1; stopping = 1;

View File

@ -388,7 +388,7 @@ int startInputStream(void) {
enableNoDelay(inputSock); enableNoDelay(inputSock);
} }
err = PltCreateThread(inputSendThreadProc, NULL, &inputSendThread); err = PltCreateThread("InputSend", inputSendThreadProc, NULL, &inputSendThread);
if (err != 0) { if (err != 0) {
if (inputSock != INVALID_SOCKET) { if (inputSock != INVALID_SOCKET) {
closeSocket(inputSock); closeSocket(inputSock);

View File

@ -1,3 +1,5 @@
#define _GNU_SOURCE
#include "PlatformThreads.h" #include "PlatformThreads.h"
#include "Platform.h" #include "Platform.h"
@ -155,7 +157,7 @@ void PltInterruptThread(PLT_THREAD* thread) {
thread->cancelled = 1; 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; struct thread_context* ctx;
ctx = (struct thread_context*)malloc(sizeof(*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->alive = 1;
thread->context = ctx; thread->context = ctx;
ctx->thread = thread; 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) { if (thread->handle < 0) {
free(ctx); free(ctx);
return -1; return -1;
@ -195,6 +197,10 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD* thread) {
free(ctx); free(ctx);
return err; return err;
} }
#ifdef __linux__
pthread_setname_np(thread->thread, name);
#endif
} }
#endif #endif

View File

@ -45,11 +45,11 @@ void PltDeleteMutex(PLT_MUTEX* mutex);
void PltLockMutex(PLT_MUTEX* mutex); void PltLockMutex(PLT_MUTEX* mutex);
void PltUnlockMutex(PLT_MUTEX* mutex); void PltUnlockMutex(PLT_MUTEX* mutex);
int PltCreateThread(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 PltCloseThread(PLT_THREAD* thread);
void PltInterruptThread(PLT_THREAD*thread); void PltInterruptThread(PLT_THREAD* thread);
int PltIsThreadInterrupted(PLT_THREAD*thread); int PltIsThreadInterrupted(PLT_THREAD* thread);
void PltJoinThread(PLT_THREAD*thread); void PltJoinThread(PLT_THREAD* thread);
int PltCreateEvent(PLT_EVENT* event); int PltCreateEvent(PLT_EVENT* event);
void PltCloseEvent(PLT_EVENT* event); void PltCloseEvent(PLT_EVENT* event);

View File

@ -222,7 +222,7 @@ int startVideoStream(void* rendererContext, int drFlags) {
VideoCallbacks.start(); VideoCallbacks.start();
err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread); err = PltCreateThread("VideoRecv", ReceiveThreadProc, NULL, &receiveThread);
if (err != 0) { if (err != 0) {
VideoCallbacks.stop(); VideoCallbacks.stop();
closeSocket(rtpSocket); closeSocket(rtpSocket);
@ -231,7 +231,7 @@ int startVideoStream(void* rendererContext, int drFlags) {
} }
if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) { if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread); err = PltCreateThread("VideoDec", DecoderThreadProc, NULL, &decoderThread);
if (err != 0) { if (err != 0) {
VideoCallbacks.stop(); VideoCallbacks.stop();
PltInterruptThread(&receiveThread); PltInterruptThread(&receiveThread);
@ -270,7 +270,7 @@ int startVideoStream(void* rendererContext, int drFlags) {
// Start pinging before reading the first frame so GFE knows where // Start pinging before reading the first frame so GFE knows where
// to send UDP data // to send UDP data
err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread); err = PltCreateThread("VideoPing", UdpPingThreadProc, NULL, &udpPingThread);
if (err != 0) { if (err != 0) {
VideoCallbacks.stop(); VideoCallbacks.stop();
stopVideoDepacketizer(); stopVideoDepacketizer();