forked from Bananymous/banan-os
Kernel: Scheduler can now check if tid is valid
Tid can become invalid if the thread is already terminated
This commit is contained in:
parent
642a6aa4ad
commit
0f23e1f0f4
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue