Added tag v0.15-rc4 for changeset 2a97f14b9016
[hvf.git] / cp / nucleus / mutex.c
blob63a0c227d1e2f7dfbd5f057e5efb29afcfa7ba72
1 /*
2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #include <mutex.h>
10 /* slow-path mutex locking */
11 void __mutex_lock_slow(mutex_t *lock)
13 spin_lock(&lock->queue_lock);
15 if (unlikely(atomic_add_unless(&lock->state, -1, 0))) {
16 spin_unlock(&lock->queue_lock);
17 return; /* aha! someone released it & it's ours now! */
20 list_add_tail(&current->blocked_list, &lock->queue);
22 spin_unlock(&lock->queue_lock);
24 schedule_blocked();