From 1bc8b7346d6a6ae0ddfcfcc4dd0ce39915bd322c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 2 May 2014 08:56:23 -0300 Subject: [PATCH] Added internal thread name support, for use with debuggers. --- src/modules/audio/openal/Audio.cpp | 1 + src/modules/thread/LuaThread.cpp | 1 + src/modules/thread/sdl/Thread.cpp | 2 +- src/modules/thread/threads.cpp | 5 +++++ src/modules/thread/threads.h | 8 ++++++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/audio/openal/Audio.cpp b/src/modules/audio/openal/Audio.cpp index c6af9be19..c424524d5 100644 --- a/src/modules/audio/openal/Audio.cpp +++ b/src/modules/audio/openal/Audio.cpp @@ -37,6 +37,7 @@ Audio::PoolThread::PoolThread(Pool *pool) , finish(false) { mutex = thread::newMutex(); + threadName = "AudioPool"; } Audio::PoolThread::~PoolThread() diff --git a/src/modules/thread/LuaThread.cpp b/src/modules/thread/LuaThread.cpp index 807994e1e..b4e7ff1c0 100644 --- a/src/modules/thread/LuaThread.cpp +++ b/src/modules/thread/LuaThread.cpp @@ -38,6 +38,7 @@ LuaThread::LuaThread(const std::string &name, love::Data *code) , nargs(0) { code->retain(); + threadName = name; } LuaThread::~LuaThread() diff --git a/src/modules/thread/sdl/Thread.cpp b/src/modules/thread/sdl/Thread.cpp index 416846331..c6a6dc619 100644 --- a/src/modules/thread/sdl/Thread.cpp +++ b/src/modules/thread/sdl/Thread.cpp @@ -51,7 +51,7 @@ bool Thread::start() return false; if (thread) // Clean old handle up SDL_WaitThread(thread, 0); - thread = SDL_CreateThread(thread_runner, NULL, this); + thread = SDL_CreateThread(thread_runner, t->getThreadName(), this); running = (thread != 0); return running; } diff --git a/src/modules/thread/threads.cpp b/src/modules/thread/threads.cpp index 631b75b53..9abeb5899 100644 --- a/src/modules/thread/threads.cpp +++ b/src/modules/thread/threads.cpp @@ -99,5 +99,10 @@ bool Threadable::isRunning() const return owner->isRunning(); } +const char *Threadable::getThreadName() const +{ + return threadName.empty() ? nullptr : threadName.c_str(); +} + } // thread } // love diff --git a/src/modules/thread/threads.h b/src/modules/thread/threads.h index f4c887e94..516abae98 100644 --- a/src/modules/thread/threads.h +++ b/src/modules/thread/threads.h @@ -21,9 +21,13 @@ #ifndef LOVE_THREAD_THREADS_H #define LOVE_THREAD_THREADS_H +// LOVE #include "common/config.h" #include "Thread.h" +// C++ +#include + namespace love { namespace thread @@ -83,9 +87,13 @@ public: bool start(); void wait(); bool isRunning() const; + const char *getThreadName() const; protected: + Thread *owner; + std::string threadName; + }; Mutex *newMutex();