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:
@@ -1,4 +1,3 @@
|
||||
#include <kernel/Lock/LockGuard.h>
|
||||
#include <kernel/Memory/Heap.h>
|
||||
#include <kernel/Memory/MemoryBackedRegion.h>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <kernel/Lock/LockGuard.h>
|
||||
#include <kernel/Memory/MemoryRegion.h>
|
||||
|
||||
namespace Kernel
|
||||
@@ -59,4 +60,24 @@ namespace Kernel
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MemoryRegion::pin()
|
||||
{
|
||||
LockGuard _(m_pinned_mutex);
|
||||
m_pinned_count++;
|
||||
}
|
||||
|
||||
void MemoryRegion::unpin()
|
||||
{
|
||||
LockGuard _(m_pinned_mutex);
|
||||
if (--m_pinned_count == 0)
|
||||
m_pinned_blocker.unblock();
|
||||
}
|
||||
|
||||
void MemoryRegion::wait_not_pinned()
|
||||
{
|
||||
LockGuard _(m_pinned_mutex);
|
||||
while (m_pinned_count)
|
||||
m_pinned_blocker.block_with_timeout_ms(100, &m_pinned_mutex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <kernel/Lock/LockGuard.h>
|
||||
#include <kernel/Memory/Heap.h>
|
||||
#include <kernel/Memory/VirtualRange.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user