Kernel: Fix most of mutex + block race conditions

All block functions now take an optional mutex parameter that is
atomically unlocked instead of having the user unlock it before hand.
This prevents a ton of race conditions everywhere in the code!
This commit is contained in:
2025-06-06 03:59:22 +03:00
parent 96d5ed9cc7
commit eecdad50a6
36 changed files with 374 additions and 322 deletions

View File

@@ -5,19 +5,19 @@
namespace Kernel
{
void ThreadBlocker::block_indefinite()
void ThreadBlocker::block_indefinite(BaseMutex* mutex)
{
Processor::scheduler().block_current_thread(this, static_cast<uint64_t>(-1));
Processor::scheduler().block_current_thread(this, static_cast<uint64_t>(-1), mutex);
}
void ThreadBlocker::block_with_timeout_ns(uint64_t timeout_ns)
void ThreadBlocker::block_with_timeout_ns(uint64_t timeout_ns, BaseMutex* mutex)
{
Processor::scheduler().block_current_thread(this, SystemTimer::get().ns_since_boot() + timeout_ns);
Processor::scheduler().block_current_thread(this, SystemTimer::get().ns_since_boot() + timeout_ns, mutex);
}
void ThreadBlocker::block_with_wake_time_ns(uint64_t wake_time_ns)
void ThreadBlocker::block_with_wake_time_ns(uint64_t wake_time_ns, BaseMutex* mutex)
{
Processor::scheduler().block_current_thread(this, wake_time_ns);
Processor::scheduler().block_current_thread(this, wake_time_ns, mutex);
}
void ThreadBlocker::unblock()