1 |
/* |
2 |
* IA-64 basic spinlock operations |
3 |
* |
4 |
* $Id: spinlock.h.in,v 1.1 2007/05/24 12:46:41 mbuna Exp $ |
5 |
*/ |
6 |
#ifndef INCLUDED_PEAK_SPINLOCK_H_ |
7 |
#define INCLUDED_PEAK_SPINLOCK_H_ |
8 |
|
9 |
#include "atomic.h" /* ia64_cmpxchg4_acq */ |
10 |
|
11 |
/* PEAK INTERNAL SPIN LOCK |
12 |
* |
13 |
* _peak_spinlock_lock(lockp) |
14 |
* _peak_spinlock_lock_try(lockp) - returns 0 (busy) or 1 (got the lock) |
15 |
* _peak_spinlock_unlock(lockp) |
16 |
* |
17 |
*/ |
18 |
|
19 |
extern int _peak_is_threaded; |
20 |
|
21 |
typedef struct { |
22 |
volatile unsigned int lock; |
23 |
} peak_spinlock_t; |
24 |
#define PEAK_SPINLOCK_INITIALIZER (peak_spinlock_t){ (0) } |
25 |
#define ia64_barrier() asm volatile ("":::"memory") |
26 |
|
27 |
|
28 |
static inline void |
29 |
_peak_spinlock_lock(peak_spinlock_t *lockp) |
30 |
{ |
31 |
__u32 *ia64_spinlock_ptr = (__u32 *)lockp; |
32 |
__u64 ia64_spinlock_val; |
33 |
ia64_spinlock_val = ia64_cmpxchg4_acq(ia64_spinlock_ptr, 1, 0); |
34 |
if (ia64_spinlock_val) { |
35 |
do { |
36 |
while (*ia64_spinlock_ptr) |
37 |
ia64_barrier(); |
38 |
ia64_spinlock_val = ia64_cmpxchg4_acq(ia64_spinlock_ptr, 1, 0); |
39 |
} while (ia64_spinlock_val); |
40 |
} |
41 |
} |
42 |
|
43 |
static inline int |
44 |
_peak_spinlock_lock_try(peak_spinlock_t *lockp) |
45 |
{ |
46 |
__u32 *ia64_spinlock_ptr = (__u32 *)lockp; |
47 |
return (int) (ia64_cmpxchg4_acq(ia64_spinlock_ptr, 1, 0) == 0); |
48 |
} |
49 |
|
50 |
static inline void |
51 |
_peak_spinlock_unlock(peak_spinlock_t *lockp) |
52 |
{ |
53 |
ia64_barrier(); |
54 |
lockp->lock = 0; |
55 |
} |
56 |
|
57 |
/* |
58 |
static inline void |
59 |
_peak_spinlock_unlock_wait(peak_spinlock_t *lockp) |
60 |
{ |
61 |
do { |
62 |
ia64_barrier(); |
63 |
} while (lockp->lock); |
64 |
} |
65 |
*/ |
66 |
|
67 |
#endif /* INCLUDED_PEAK_SPINLOCK_H_ */ |