From 5428763559de50256e30ccdbcf2f797cf2d24df1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 31 Aug 2020 23:33:57 +0200 Subject: [PATCH] task: Add the ability to name threads --- desmume/src/utils/task.cpp | 10 ++++++---- desmume/src/utils/task.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/desmume/src/utils/task.cpp b/desmume/src/utils/task.cpp index e696c8d51..0e591863a 100644 --- a/desmume/src/utils/task.cpp +++ b/desmume/src/utils/task.cpp @@ -30,7 +30,7 @@ public: Impl(); ~Impl(); - void start(bool spinlock, int threadPriority); + void start(bool spinlock, int threadPriority, const char *name); void execute(const TWork &work, void *param); void* finish(); void shutdown(); @@ -87,7 +87,7 @@ Task::Impl::~Impl() scond_free(condWork); } -void Task::Impl::start(bool spinlock, int threadPriority) +void Task::Impl::start(bool spinlock, int threadPriority, const char *name) { slock_lock(this->mutex); @@ -102,6 +102,8 @@ void Task::Impl::start(bool spinlock, int threadPriority) this->exitThread = false; this->_thread = sthread_create_with_priority(&taskProc, this, threadPriority); this->_isThreadRunning = true; + if (name) + sthread_setname(this->_thread, name); slock_unlock(this->mutex); } @@ -168,8 +170,8 @@ void Task::Impl::shutdown() slock_unlock(this->mutex); } -void Task::start(bool spinlock) { impl->start(spinlock, 0); } -void Task::start(bool spinlock, int threadPriority) { impl->start(spinlock, threadPriority); } +void Task::start(bool spinlock) { impl->start(spinlock, 0, nullptr); } +void Task::start(bool spinlock, int threadPriority, const char *name) { impl->start(spinlock, threadPriority, name); } void Task::shutdown() { impl->shutdown(); } Task::Task() : impl(new Task::Impl()) {} Task::~Task() { delete impl; } diff --git a/desmume/src/utils/task.h b/desmume/src/utils/task.h index eab44fd1d..e4053d741 100644 --- a/desmume/src/utils/task.h +++ b/desmume/src/utils/task.h @@ -30,7 +30,7 @@ public: // initialize task runner void start(bool spinlock); - void start(bool spinlock, int threadPriority); + void start(bool spinlock, int threadPriority, const char *name = nullptr); //execute some work void execute(const TWork &work, void* param);