Annotation of sys/arch/sparc64/include/lock.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: lock.h,v 1.1 2007/05/01 18:56:31 miod Exp $ */
2:
3: /* public domain */
4:
5: #ifndef _SPARC64_LOCK_H_
6: #define _SPARC64_LOCK_H_
7:
8: typedef volatile u_int8_t __cpu_simple_lock_t;
9:
10: #define __SIMPLELOCK_LOCKED 0xff
11: #define __SIMPLELOCK_UNLOCKED 0x00
12:
13: static __inline__ void
14: __cpu_simple_lock_init(__cpu_simple_lock_t *l)
15: {
16: *l = __SIMPLELOCK_UNLOCKED;
17: }
18:
19: static __inline__ void
20: __cpu_simple_lock(__cpu_simple_lock_t *l)
21: {
22: __cpu_simple_lock_t old;
23:
24: do {
25: old = __SIMPLELOCK_LOCKED;
26: __asm__ __volatile__
27: ("ldstub %0, %1" : "=m" (*l), "=r" (old) : "0" (*l));
28: } while (old != __SIMPLELOCK_UNLOCKED);
29: }
30:
31: static __inline__ int
32: __cpu_simple_lock_try(__cpu_simple_lock_t *l)
33: {
34: __cpu_simple_lock_t old = __SIMPLELOCK_LOCKED;
35:
36: __asm__ __volatile__
37: ("ldstub %0, %1" : "=m" (*l), "=r" (old) : "0" (*l));
38:
39: return (old == __SIMPLELOCK_UNLOCKED);
40: }
41:
42: static __inline__ void
43: __cpu_simple_unlock(__cpu_simple_lock_t *l)
44: {
45: *l = __SIMPLELOCK_UNLOCKED;
46: }
47:
48: #endif /* _SPARC64_LOCK_H_ */
CVSweb