|
Click
|
A non-recursive spinlock for SMP Click threads. More...
#include <sync.hh>
Public Member Functions | |
| SimpleSpinlock () | |
| Create a SimpleSpinlock. | |
| void | acquire () |
| Acquires the SimpleSpinlock. | |
| void | release () |
| Releases the SimpleSpinlock. | |
| bool | attempt () |
| Attempts to acquire the SimpleSpinlock. | |
A non-recursive spinlock for SMP Click threads.
The Spinlock class abstracts a non-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 NOT OK for a thread to acquire a lock it has already acquired.
|
inline |
Create a SimpleSpinlock.
|
inline |
Acquires the SimpleSpinlock.
On return, this thread has acquired the lock. The function will spin indefinitely until the lock is acquired.
|
inline |
Releases the SimpleSpinlock.
The SimpleSpinlock must have been previously acquired by either SimpleSpinlock::acquire or SimpleSpinlock::attempt.
|
inline |
Attempts to acquire the SimpleSpinlock.
This function will acquire the lock and return true only if the SimpleSpinlock can be acquired right away, without retries.