From 917db3ecac4d2f73e921c8a4f8cf293c649877f9 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 31 Aug 2020 23:35:27 +0200 Subject: [PATCH 1/4] =?UTF-8?q?rthreads:=20Fix=20documentation=20(void=20f?= =?UTF-8?q?unction=20doesn=E2=80=99t=20return)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- desmume/src/libretro-common/include/rthreads/rthreads.h | 2 -- desmume/src/libretro-common/rthreads/rthreads.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/desmume/src/libretro-common/include/rthreads/rthreads.h b/desmume/src/libretro-common/include/rthreads/rthreads.h index 32ec43794..3258ceef6 100644 --- a/desmume/src/libretro-common/include/rthreads/rthreads.h +++ b/desmume/src/libretro-common/include/rthreads/rthreads.h @@ -87,8 +87,6 @@ int sthread_detach(sthread_t *thread); * @thread to terminate. If that thread has already terminated, then * it will return immediately. The thread specified by @thread must * be joinable. - * - * Returns: 0 on success, otherwise it returns a non-zero error number. */ void sthread_join(sthread_t *thread); diff --git a/desmume/src/libretro-common/rthreads/rthreads.c b/desmume/src/libretro-common/rthreads/rthreads.c index c3f03ca09..01cdc2701 100644 --- a/desmume/src/libretro-common/rthreads/rthreads.c +++ b/desmume/src/libretro-common/rthreads/rthreads.c @@ -270,8 +270,6 @@ int sthread_detach(sthread_t *thread) * @thread to terminate. If that thread has already terminated, then * it will return immediately. The thread specified by @thread must * be joinable. - * - * Returns: 0 on success, otherwise it returns a non-zero error number. */ void sthread_join(sthread_t *thread) { From e70e065ffe0c542fa9b7eb9ea949deedf72daa50 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 31 Aug 2020 23:33:15 +0200 Subject: [PATCH 2/4] rthreads: Add the ability to name threads --- .../include/rthreads/rthreads.h | 10 ++++++++++ .../src/libretro-common/rthreads/rthreads.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/desmume/src/libretro-common/include/rthreads/rthreads.h b/desmume/src/libretro-common/include/rthreads/rthreads.h index 3258ceef6..682fd6922 100644 --- a/desmume/src/libretro-common/include/rthreads/rthreads.h +++ b/desmume/src/libretro-common/include/rthreads/rthreads.h @@ -103,6 +103,16 @@ void sthread_join(sthread_t *thread); */ bool sthread_isself(sthread_t *thread); +/** + * sthread_set_name: + * @thread : pointer to thread object + * @name : name to define for the thread (at most + * 15 bytes) + * + * Set the thread name, useful for debugging. + */ +void sthread_setname(sthread_t *thread, const char *name); + /** * slock_new: * diff --git a/desmume/src/libretro-common/rthreads/rthreads.c b/desmume/src/libretro-common/rthreads/rthreads.c index 01cdc2701..2cac2909e 100644 --- a/desmume/src/libretro-common/rthreads/rthreads.c +++ b/desmume/src/libretro-common/rthreads/rthreads.c @@ -302,6 +302,24 @@ bool sthread_isself(sthread_t *thread) #endif } +/** + * sthread_set_name: + * @thread : pointer to thread object + * @name : name to define for the thread (at most + * 15 bytes) + * + * Set the thread name, useful for debugging. + */ +void sthread_setname(sthread_t *thread, const char *name) +{ + if (!thread) + return; + // TODO: implement that for Windows too. +#ifndef USE_WIN32_THREADS + pthread_setname_np(thread->id, name); +#endif +} + /** * slock_new: * From 5428763559de50256e30ccdbcf2f797cf2d24df1 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 31 Aug 2020 23:33:57 +0200 Subject: [PATCH 3/4] 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); From e4b07d2f4d89db56756cfb6a6a228e7bfd5910f5 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 31 Aug 2020 23:35:40 +0200 Subject: [PATCH 4/4] Name various threads to ease debugging --- desmume/src/GPU.cpp | 4 ++-- desmume/src/filter/videofilter.cpp | 4 +++- desmume/src/rasterize.cpp | 4 +++- desmume/src/wifi.cpp | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 095b62839..b6aed0d89 100755 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -1414,7 +1414,7 @@ GPUEngineBase::GPUEngineBase() if (CommonSettings.num_cores > 1) { _asyncClearTask = new Task; - _asyncClearTask->start(false); + _asyncClearTask->start(false, 0, "async clear"); } else { @@ -8717,7 +8717,7 @@ GPUSubsystem::GPUSubsystem() if (CommonSettings.num_cores > 1) { _asyncEngineBufferSetupTask = new Task; - _asyncEngineBufferSetupTask->start(false); + _asyncEngineBufferSetupTask->start(false, 0, "setup gpu bufs"); } else { diff --git a/desmume/src/filter/videofilter.cpp b/desmume/src/filter/videofilter.cpp index 37aed8d0c..5381bc2ee 100644 --- a/desmume/src/filter/videofilter.cpp +++ b/desmume/src/filter/videofilter.cpp @@ -188,7 +188,9 @@ void VideoFilter::__InstanceInit(size_t srcWidth, size_t srcHeight, VideoFilterT __vfThread[i].param.filterFunction = NULL; __vfThread[i].task = new Task; - __vfThread[i].task->start(false); + char name[16]; + snprintf(name, 16, "video filter %d", i); + __vfThread[i].task->start(false, 0, name); } __vfFunc = _vfAttributes.filterFunction; diff --git a/desmume/src/rasterize.cpp b/desmume/src/rasterize.cpp index 9b9858b2b..348b83f7e 100755 --- a/desmume/src/rasterize.cpp +++ b/desmume/src/rasterize.cpp @@ -1802,7 +1802,9 @@ SoftRasterizerRenderer::SoftRasterizerRenderer() // to help stabilize performance when running SoftRasterizer. _task[i].start(false, 43); #else - _task[i].start(false); + char name[16]; + snprintf(name, 16, "rasterizer %d", i); + _task[i].start(false, 0, name); #endif } } diff --git a/desmume/src/wifi.cpp b/desmume/src/wifi.cpp index 7a249a043..5ec0cd57f 100755 --- a/desmume/src/wifi.cpp +++ b/desmume/src/wifi.cpp @@ -3398,7 +3398,7 @@ bool AdhocCommInterface::Start(WifiHandler* currentWifiHandler) #ifdef DESMUME_COCOA this->_rxTask->start(false, 43); #else - this->_rxTask->start(false); + this->_rxTask->start(false, 0, "wifi ad-hoc"); #endif this->_isRXThreadRunning = true; this->_rxTask->execute(&Adhoc_RXPacketGetOnThread, this); @@ -3672,7 +3672,7 @@ bool SoftAPCommInterface::Start(WifiHandler* currentWifiHandler) #ifdef DESMUME_COCOA this->_rxTask->start(false, 43); #else - this->_rxTask->start(false); + this->_rxTask->start(false, 0, "wifi ap"); #endif this->_isRXThreadRunning = true; this->_rxTask->execute(&Infrastructure_RXPacketGetOnThread, this);