|
Click
|
A read/write lock. More...
#include <sync.hh>
Public Member Functions | |
| ReadWriteLock () | |
| Creates a ReadWriteLock. | |
| void | acquire_read () |
| Acquires the ReadWriteLock for reading. | |
| bool | attempt_read () |
| Attempts to acquire the ReadWriteLock for reading. | |
| void | release_read () |
| Releases the ReadWriteLock for reading. | |
| void | acquire_write () |
| Acquires the ReadWriteLock for writing. | |
| bool | attempt_write () |
| Attempts to acquire the ReadWriteLock for writing. | |
| void | release_write () |
| Releases the ReadWriteLock for writing. | |
A read/write lock.
The ReadWriteLock class abstracts a read/write lock in SMP Click. Multiple SMP Click threads can hold read locks simultaneously, but if any thread holds a write lock, then no other thread holds any kind of lock. The read/write lock is implemented with Spinlock objects, so acquiring a lock is a polling operation. ReadWriteLocks can be used to synchronize access to shared data among multiple Click SMP threads. ReadWriteLocks should not be held for long periods of time.
ReadWriteLock operations do nothing unless Click was compiled with –enable-multithread. Therefore, ReadWriteLock should not be used to, for example, synchronize handlers with main element threads.
The main ReadWriteLock operations are acquire_read() and acquire_write(), which acquire the lock for reading or writing, respectively, and release_read() and release_write(), which similarly release the lock. attempt_read() and attempt_write() acquire 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.
ReadWriteLock objects are relatively large in terms of memory usage; don't create too many of them.
|
inline |
Creates a ReadWriteLock.
|
inline |
Acquires the ReadWriteLock for reading.
On return, this thread has acquired the lock for reading. 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 |
Attempts to acquire the ReadWriteLock for reading.
This function will acquire the lock for reading and return true only if the ReadWriteLock can be acquired right away, without retries.
|
inline |
Releases the ReadWriteLock for reading.
The ReadWriteLock must have been previously acquired by either ReadWriteLock::acquire_read or ReadWriteLock::attempt_read. Do not call release_read() on a lock that was acquired for writing.
|
inline |
Acquires the ReadWriteLock for writing.
On return, this thread has acquired the lock for writing. 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 |
Attempts to acquire the ReadWriteLock for writing.
This function will acquire the lock for writing and return true only if the ReadWriteLock can be acquired right away, without retries. Note, however, that acquiring a ReadWriteLock requires as many operations as there are CPUs.
|
inline |
Releases the ReadWriteLock for writing.
The ReadWriteLock must have been previously acquired by either ReadWriteLock::acquire_write or ReadWriteLock::attempt_write. Do not call release_write() on a lock that was acquired for reading.