|
Click
|
A recursive spinlock for SMP Click threads. More...
#include <sync.hh>
Public Member Functions | |
| Spinlock () | |
| Create a Spinlock. | |
| void | acquire () |
| Acquires the Spinlock. | |
| void | release () |
| Releases the Spinlock. | |
| bool | attempt () |
| Attempts to acquire the Spinlock. | |
| bool | nested () const |
| Returns true iff the Spinlock has been acquired more than once by the current thread. | |
A recursive spinlock for SMP Click threads.
The Spinlock class abstracts a recursive spinlock, or polling mutex, in SMP Click. This is a type of mutual-exclusion lock in which acquiring the lock is a polling operation (basically a "while (lock.acquired()) do nothing;" loop). Spinlocks can be used to synchronize access to shared data among multiple Click SMP threads. Spinlocks should not be held for long periods of time: use them for quick updates and such.
Spinlock operations do nothing unless Click was compiled with SMP support (with –enable-multithread). Therefore, Spinlock should not be used to, for example, synchronize handlers with main element threads. See also SpinlockIRQ.
The main Spinlock operations are acquire(), which acquires the lock, and release(), which releases the lock. attempt() acquires the lock only if it can be acquired instantaneously.
It is OK for a thread to acquire a lock it has already acquired, but you must release it as many times as you have acquired it.
|
inline |
Create a Spinlock.
|
inline |
Acquires the Spinlock.
On return, this thread has acquired the lock. The function will spin indefinitely until the lock is acquired. It is OK to acquire a lock you have already acquired, but you must release it as many times as you have acquired it.
|
inline |
Releases the Spinlock.
The Spinlock must have been previously acquired by either Spinlock::acquire or Spinlock::attempt.
|
inline |
|
inline |
Returns true iff the Spinlock has been acquired more than once by the current thread.