kernel: add thread_wait, thread_block and mtx
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
071a5651e0
commit
9c50a1df92
6 changed files with 49 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include <kernel/common.h>
|
||||
#include <kernel/spinlock.h>
|
||||
#include <kernel/atomic.h>
|
||||
#include <arch/proc.h>
|
||||
|
||||
static uint64_t spinlock_attempt_acquire(spinlock_t *lock)
|
||||
{
|
||||
|
|
@ -24,3 +25,14 @@ void cleanup_spinlock(spinlock_t **lock_ptr)
|
|||
if (lock_ptr && *lock_ptr)
|
||||
spinlock_release(*lock_ptr);
|
||||
}
|
||||
|
||||
void mtx_lock(mtx_t *l)
|
||||
{
|
||||
while (spinlock_attempt_acquire(l))
|
||||
thread_wait();
|
||||
}
|
||||
|
||||
void mtx_unlock(mtx_t *l)
|
||||
{
|
||||
spinlock_release(l);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue