Rev 625 | Rev 1104 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 625 | Rev 1100 | ||
|---|---|---|---|
| Line 31... | Line 31... | ||
| 31 | 31 | ||
| 32 | #include <arch/types.h> |
32 | #include <arch/types.h> |
| 33 | #include <typedefs.h> |
33 | #include <typedefs.h> |
| 34 | #include <preemption.h> |
34 | #include <preemption.h> |
| 35 | #include <arch/atomic.h> |
35 | #include <arch/atomic.h> |
| - | 36 | #include <debug.h> |
|
| 36 | 37 | ||
| 37 | #ifdef CONFIG_SMP |
38 | #ifdef CONFIG_SMP |
| 38 | struct spinlock { |
39 | struct spinlock { |
| 39 | #ifdef CONFIG_DEBUG_SPINLOCK |
40 | #ifdef CONFIG_DEBUG_SPINLOCK |
| 40 | char *name; |
41 | char *name; |
| Line 64... | Line 65... | ||
| 64 | .val = { 0 } \ |
65 | .val = { 0 } \ |
| 65 | } |
66 | } |
| 66 | #endif |
67 | #endif |
| 67 | 68 | ||
| 68 | extern void spinlock_initialize(spinlock_t *sl, char *name); |
69 | extern void spinlock_initialize(spinlock_t *sl, char *name); |
| 69 | extern void spinlock_lock(spinlock_t *sl); |
- | |
| 70 | extern int spinlock_trylock(spinlock_t *sl); |
70 | extern int spinlock_trylock(spinlock_t *sl); |
| 71 | extern void spinlock_unlock(spinlock_t *sl); |
71 | extern void spinlock_lock_debug(spinlock_t *sl); |
| - | 72 | ||
| - | 73 | #ifdef CONFIG_DEBUG_SPINLOCK |
|
| - | 74 | # define spinlock_lock(x) spinlock_lock_debug(x) |
|
| - | 75 | #else |
|
| - | 76 | # define spinlock_lock(x) atomic_lock_arch(&(x)->val) |
|
| - | 77 | #endif |
|
| - | 78 | ||
| - | 79 | /** Unlock spinlock |
|
| - | 80 | * |
|
| - | 81 | * Unlock spinlock. |
|
| - | 82 | * |
|
| - | 83 | * @param sl Pointer to spinlock_t structure. |
|
| - | 84 | */ |
|
| - | 85 | static inline void spinlock_unlock(spinlock_t *sl) |
|
| - | 86 | { |
|
| - | 87 | ASSERT(atomic_get(&sl->val) != 0); |
|
| - | 88 | ||
| - | 89 | /* |
|
| - | 90 | * Prevent critical section code from bleeding out this way down. |
|
| - | 91 | */ |
|
| - | 92 | CS_LEAVE_BARRIER(); |
|
| - | 93 | ||
| - | 94 | atomic_set(&sl->val,0); |
|
| - | 95 | preemption_enable(); |
|
| - | 96 | } |
|
| 72 | 97 | ||
| 73 | #else |
98 | #else |
| 74 | 99 | ||
| 75 | /* On UP systems, spinlocks are effectively left out. */ |
100 | /* On UP systems, spinlocks are effectively left out. */ |
| 76 | #define SPINLOCK_DECLARE(name) |
101 | #define SPINLOCK_DECLARE(name) |