Add facility to run tasks on dedicated threads using the ThreadManager interface.

Useful for things that should be run ASAP even if the threadpool is full,
at a small extra cost. (Not recommended for very small tasks).

Considering using this to resolve the deadlocks in #16802.
This commit is contained in:
Henrik Rydgård
2023-01-31 11:07:40 +01:00
parent b04dd81cba
commit 6b0903f566
6 changed files with 26 additions and 7 deletions
+12
View File
@@ -217,6 +217,16 @@ void ThreadManager::Init(int numRealCores, int numLogicalCoresPerCpu) {
}
void ThreadManager::EnqueueTask(Task *task) {
if (task->Type() == TaskType::DEDICATED_THREAD) {
std::thread th([=](Task *task) {
SetCurrentThreadName("DedicatedThreadTask");
task->Run();
task->Release();
}, task);
th.detach();
return;
}
_assert_msg_(IsInitialized(), "ThreadManager not initialized");
int minThread;
@@ -270,6 +280,8 @@ void ThreadManager::EnqueueTask(Task *task) {
}
void ThreadManager::EnqueueTaskOnThread(int threadNum, Task *task) {
_assert_msg_(task->Type() != TaskType::DEDICATED_THREAD, "Dedicated thread tasks can't be put on specific threads");
_assert_msg_(threadNum >= 0 && threadNum < (int)global_->threads_.size(), "Bad threadnum or not initialized");
ThreadContext *thread = global_->threads_[threadNum];