Lines Matching refs:lock
10 void mutex_init(mutex_t *lock) in mutex_init() argument
12 atomic_set(&lock->count, 1); in mutex_init()
13 spin_init(&lock->wait_lock); in mutex_init()
14 list_init(&lock->wait_list); in mutex_init()
24 static void __mutex_acquire(mutex_t *lock) in __mutex_acquire() argument
32 void mutex_lock(mutex_t *lock) in mutex_lock() argument
38 spin_lock(&lock->wait_lock); in mutex_lock()
39 if (likely(mutex_is_locked(lock))) in mutex_lock()
45 spin_unlock(&lock->wait_lock); in mutex_lock()
51 list_append(&lock->wait_list, &waiter->list); in mutex_lock()
53 spin_unlock(&lock->wait_lock); in mutex_lock()
59 atomic_dec(&lock->count); in mutex_lock()
60 spin_unlock(&lock->wait_lock); in mutex_lock()
71 void mutex_unlock(mutex_t *lock) in mutex_unlock() argument
73 if (unlikely(!mutex_is_locked(lock))) in mutex_unlock()
76 spin_lock(&lock->wait_lock); in mutex_unlock()
78 if (mutex_is_locked(lock)) in mutex_unlock()
80 if (!list_empty(&lock->wait_list)) in mutex_unlock()
81 wt = container_of(list_next(&lock->wait_list), struct mutex_waiter_t, list); in mutex_unlock()
83 atomic_inc(&lock->count); in mutex_unlock()
88 spin_unlock(&lock->wait_lock); in mutex_unlock()
104 int mutex_trylock(mutex_t *lock) in mutex_trylock() argument
106 if (mutex_is_locked(lock)) in mutex_trylock()
109 spin_lock(&lock->wait_lock); in mutex_trylock()
110 if (mutex_is_locked(lock)) in mutex_trylock()
112 spin_unlock(&lock->wait_lock); in mutex_trylock()
117 atomic_dec(&lock->count); in mutex_trylock()
118 spin_unlock(&lock->wait_lock); in mutex_trylock()