Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions desmume/src/GPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ GPUEngineBase::GPUEngineBase()
if (CommonSettings.num_cores > 1)
{
_asyncClearTask = new Task;
_asyncClearTask->start(false);
_asyncClearTask->start(false, 0, "async clear");
}
else
{
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 3 additions & 1 deletion desmume/src/filter/videofilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions desmume/src/libretro-common/include/rthreads/rthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -105,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:
*
Expand Down
20 changes: 18 additions & 2 deletions desmume/src/libretro-common/rthreads/rthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -304,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:
*
Expand Down
4 changes: 3 additions & 1 deletion desmume/src/rasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 6 additions & 4 deletions desmume/src/utils/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Task::Impl {
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();
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/utils/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Task

// 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);
Expand Down
4 changes: 2 additions & 2 deletions desmume/src/wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down