Changeset 571:17685531a0f3
- Timestamp:
- 06/02/08 01:50:10 (7 months ago)
- Author:
- David Anderson <dave@…>
- Branch:
- default
- Message:
-
Tweak the API of lock.h around a little.
Locking spinlocks by value instead of by ref through a macro was
treacherous, and so has been removed in favor of a more transparent
API. Unlocking is now an inline function instead of a macro.
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r384
|
r571
|
|
| 1 | 1 | /** @file lock.h |
| 2 | | * @brief Locking primitives |
| | 2 | * @brief Locking primitives. |
| 3 | 3 | */ |
| 4 | 4 | |
| 5 | | /* Copyright (C) 2007 the NxOS developers |
| | 5 | /* Copyright (c) 2007,2008 the NxOS developers |
| 6 | 6 | * |
| 7 | 7 | * See AUTHORS for a full list of the developers. |
| … |
… |
|
| 65 | 65 | * spinlock can be acquired. |
| 66 | 66 | * |
| 67 | | * @note This means that a spinlock is only useful when you need to |
| 68 | | * synchronize between the main execution context and an interrupt |
| 69 | | * handler, or some other form of preemption that can break free of the |
| 70 | | * spinlock's infinite loop. |
| | 67 | * @note These semantics mean that a spinlock is only useful when you |
| | 68 | * need to synchronize between the main execution context and an |
| | 69 | * interrupt handler, or some other form of preemption that can break |
| | 70 | * free of the spinlock's infinite loop. |
| 71 | 71 | */ |
| 72 | 72 | /*@{*/ |
| … |
… |
|
| 81 | 81 | #define SPINLOCK_INIT_LOCKED 1 |
| 82 | 82 | |
| 83 | | /** @cond DOXYGEN_SKIP */ |
| 84 | | void nx_spinlock_acquire_from_ref(spinlock *lock); |
| 85 | | bool nx_spinlock_try_acquire_from_ref(spinlock *lock); |
| 86 | | /** @endcond */ |
| 87 | | |
| 88 | 83 | /** Acquire @a lock and return. |
| 89 | 84 | * |
| 90 | 85 | * Will loop indefinitely until the spinlock can be acquired. |
| 91 | 86 | * |
| 92 | | * @param lock The spinlock to acquire. |
| | 87 | * @param lock Pointer to the spinlock to acquire. |
| 93 | 88 | */ |
| 94 | | #define nx_spinlock_acquire(lock) spinlock_acquire_from_ref(&(lock)) |
| | 89 | void nx_spinlock_acquire(spinlock *lock); |
| 95 | 90 | |
| 96 | 91 | /** Attempt to acquire @a lock and return the result. |
| … |
… |
|
| 99 | 94 | * fail to acquire the spinlock. |
| 100 | 95 | * |
| 101 | | * @param lock The spinlock to acquire. |
| | 96 | * @param lock Pointer to the spinlock to acquire. |
| 102 | 97 | * @return 1 if the spinlock was acquired, 0 if it was already locked. |
| 103 | 98 | */ |
| 104 | | #define nx_spinlock_try_acquire(lock) spinlock_try_acquire_from_ref(&(lock)) |
| | 99 | void nx_spinlock_try_acquire(spinlock *lock); |
| 105 | 100 | |
| 106 | 101 | /** Release @a lock. |
| … |
… |
|
| 108 | 103 | * Does not block. |
| 109 | 104 | * |
| 110 | | * @param lock The spinlock to release. |
| | 105 | * @param lock Pointer to the spinlock to release. |
| 111 | 106 | */ |
| 112 | | #define nx_spinlock_release(lock) { lock = 0; } |
| | 107 | void nx_spinlock_release(spinlock *lock); |
| | 108 | |
| | 109 | inline void nx_spinlock_release(spinlock *lock) { |
| | 110 | *lock = 0; |
| | 111 | } |
| 113 | 112 | |
| 114 | 113 | /*@}*/ |