The x-kernel provides a readers/writers lock synchronization type, ReadWriteLock. This type is currently built on top of the x-kernel Semaphore type. Although originally developed for the machNetIPC
protocols, the lock can be used for more general synchronization. The
ReadWriteLock implementation favors writers (i.e., if queues of
readers and writers both exist, writers will always be favored.)
Note that we expect these locking operations to be used in a
multiprocessor environment, although we have not yet used them for
this purpose. Protocol developers working in an MP environment should
attempt to adhere to this interface. However, we consider locking on
an MP to be an unresolved issue, and so we are eager to hear about
experiences using these operations in such an environment.
Initializes the lock for subsequent operations.
void rwLockInit (ReadWriteLock *)
All threads waiting on this lock will be released and their locking
operations will return XK_FAILURE. When both the reader and writer
queue are empty, the user-supplied RwlDestroyFunc will be called
with a pointer to the lock and the void* argument.
void rwLockDestroy
( ReadWriteLock *, RwlDestroyFunc, void *)
typedef void (*RwlDestroyFunc )
( ReadWriteLock *, void * );
Acquires a reader lock. Many readers may hold the lock at one time,
but no writers will acquire the lock while at least one reader holds
the lock. Will return XK_FAILURE if the lock was destroyed before
the lock was acquired.
xkern_return_t readerLock ( ReadWriteLock * )
Releases a reader lock. It is an error to call readerUnlock
without holding a reader lock.
void readerUnlock ( ReadWriteLock * )
Acquires a writer lock. While a writer lock is held, no other reader
or writer may acquire the lock.
Will return XK_FAILURE if the lock was destroyed before
the lock was acquired.
xkern_return_t writerLock ( ReadWriteLock * )
Releases a writer lock. It is an error to call writerUnlock
without holding a writer lock.
void writerUnlock ( ReadWriteLock * )
rwLockInit
rwLockDestroy
readerLock
readerUnlock
writerLock
writerUnlock
Next: Usage Rules
Up: Thread Library
Previous: Delay