Thread ID lookup and naming.

This commit is contained in:
Ben Vanik
2014-01-07 20:54:47 -08:00
parent 20b76b0e59
commit 5fd0b211ce
5 changed files with 94 additions and 0 deletions

View File

@@ -82,3 +82,31 @@ void KernelState::SetExecutableModule(XModule* module) {
executable_module_->Retain();
}
}
void KernelState::RegisterThread(XThread* thread) {
xe_mutex_lock(object_mutex_);
threads_by_id_[thread->thread_id()] = thread;
xe_mutex_unlock(object_mutex_);
}
void KernelState::UnregisterThread(XThread* thread) {
xe_mutex_lock(object_mutex_);
auto it = threads_by_id_.find(thread->thread_id());
if (it != threads_by_id_.end()) {
threads_by_id_.erase(it);
}
xe_mutex_unlock(object_mutex_);
}
XThread* KernelState::GetThreadByID(uint32_t thread_id) {
XThread* thread = NULL;
xe_mutex_lock(object_mutex_);
auto it = threads_by_id_.find(thread_id);
if (it != threads_by_id_.end()) {
thread = it->second;
// Caller must release.
thread->Retain();
}
xe_mutex_unlock(object_mutex_);
return thread;
}