diff options
Diffstat (limited to 'kern/mutex_i.h')
-rw-r--r-- | kern/mutex_i.h | 65 |
1 files changed, 3 insertions, 62 deletions
diff --git a/kern/mutex_i.h b/kern/mutex_i.h index 5e78a4da..a161b1bb 100644 --- a/kern/mutex_i.h +++ b/kern/mutex_i.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Richard Braun. + * Copyright (c) 2013-2017 Richard Braun. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,24 +19,13 @@ #define _KERN_MUTEX_I_H #include <kern/assert.h> -#include <kern/list.h> #include <kern/mutex_types.h> -#include <kern/thread.h> #include <machine/atomic.h> #define MUTEX_UNLOCKED 0 #define MUTEX_LOCKED 1 #define MUTEX_CONTENDED 2 -struct mutex_waiter { - struct list node; - struct thread *thread; -}; - -void mutex_lock_slow(struct mutex *mutex); - -void mutex_unlock_slow(struct mutex *mutex); - static inline unsigned int mutex_tryacquire(struct mutex *mutex) { @@ -44,12 +33,6 @@ mutex_tryacquire(struct mutex *mutex) } static inline unsigned int -mutex_tryacquire_slow(struct mutex *mutex) -{ - return atomic_swap_uint(&mutex->state, MUTEX_CONTENDED); -} - -static inline unsigned int mutex_release(struct mutex *mutex) { unsigned int state; @@ -59,51 +42,9 @@ mutex_release(struct mutex *mutex) return state; } -static inline void -mutex_queue(struct mutex *mutex, struct mutex_waiter *waiter) -{ - list_insert_tail(&mutex->waiters, &waiter->node); -} - -static inline void -mutex_queue_list(struct mutex *mutex, struct list *waiters) -{ - list_concat(&mutex->waiters, waiters); -} - -static inline void -mutex_wait(struct mutex *mutex, struct mutex_waiter *waiter) -{ - unsigned int state; - - do { - thread_sleep(&mutex->lock, mutex, "mutex"); - state = mutex_tryacquire_slow(mutex); - } while (state != MUTEX_UNLOCKED); - - list_remove(&waiter->node); -} - -static inline void -mutex_signal(struct mutex *mutex) -{ - struct mutex_waiter *waiter; - - if (!list_empty(&mutex->waiters)) { - waiter = list_first_entry(&mutex->waiters, struct mutex_waiter, node); - thread_wakeup(waiter->thread); - } -} +void mutex_lock_slow(struct mutex *mutex); -static inline void -mutex_trydowngrade(struct mutex *mutex) -{ - if (list_empty(&mutex->waiters)) { - unsigned int state; +void mutex_unlock_slow(struct mutex *mutex); - state = atomic_swap_uint(&mutex->state, MUTEX_LOCKED); - assert(state == MUTEX_CONTENDED); - } -} #endif /* _KERN_MUTEX_I_H */ |