diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/thread.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/thread.c b/src/lib/thread.c index 47a23acd96..e62c5d7239 100644 --- a/src/lib/thread.c +++ b/src/lib/thread.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include <assert.h> #include <stddef.h> #include <stdint.h> #include <stdlib.h> @@ -377,3 +378,22 @@ void thread_coop_disable(void) current->can_yield--; } + +void thread_mutex_lock(struct thread_mutex *mutex) +{ + struct stopwatch sw; + + stopwatch_init(&sw); + + while (mutex->locked) + assert(thread_yield() == 0); + mutex->locked = true; + + printk(BIOS_SPEW, "took %lu us to acquire mutex\n", stopwatch_duration_usecs(&sw)); +} + +void thread_mutex_unlock(struct thread_mutex *mutex) +{ + assert(mutex->locked); + mutex->locked = 0; +} |