Added tag v0.15-rc4 for changeset 2a97f14b9016
[hvf.git] / cp / nucleus / spinlock.c
blob82f30f2314f5c2f35b6b78fed012ae4436f99577
1 /*
2 * (C) Copyright 2007-2010 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 <interrupt.h>
9 #include <spinlock.h>
11 void __spin_lock_wait(spinlock_t *lp, unsigned int pc)
13 while (1) {
14 if (__compare_and_swap(&lp->lock, 0, pc) == 0)
15 return;
19 int __spin_trylock_retry(spinlock_t *lp, unsigned int pc)
21 int count = SPIN_RETRY;
23 while (count-- > 0)
24 if (__compare_and_swap(&lp->lock, 0, pc) == 0)
25 return 1;
26 return 0;
29 /**
30 * spin_lock_intsave - disable interrupts and lock
31 * @lock: lock to lock
32 * @mask: pointer to where interrupt mask will be stored
34 void spin_lock_intsave(spinlock_t *lock, unsigned long *mask)
36 *mask = local_int_disable();
37 spin_lock(lock);
40 /**
41 * spin_unlock_intrestore - unlock and restore interrupt flags flags
42 * @lock: lock to unlock
43 * @mask: mask to restore
45 void spin_unlock_intrestore(spinlock_t *lock, unsigned long mask)
47 spin_unlock(lock);
48 local_int_restore(mask);