Kernel: Scheduler can now check if tid is valid

Tid can become invalid if the thread is already terminated
This commit is contained in:
Bananymous 2023-07-27 18:34:06 +03:00
parent 642a6aa4ad
commit 0f23e1f0f4
2 changed files with 24 additions and 0 deletions

View File

@ -31,6 +31,8 @@ namespace Kernel
Thread& current_thread(); Thread& current_thread();
static pid_t current_tid(); static pid_t current_tid();
static bool is_valid_tid(pid_t tid);
private: private:
Scheduler() = default; Scheduler() = default;

View File

@ -373,4 +373,26 @@ namespace Kernel
} }
} }
bool Scheduler::is_valid_tid(pid_t tid)
{
CriticalScope _;
if (s_instance == nullptr)
return tid == 0;
for (auto& thread : s_instance->m_active_threads)
if (thread.thread->tid() == tid)
return true;
for (auto& thread : s_instance->m_sleeping_threads)
if (thread.thread->tid() == tid)
return true;
for (auto& thread : s_instance->m_blocking_threads)
if (thread.thread->tid() == tid)
return true;
return false;
}
} }