Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ReadWriteLock Class Reference

This class implements a read/write lock. More...

#include <rwlock.h>

Collaboration diagram for ReadWriteLock:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ReadWriteLock ()
 Set up a read/write lock.

 ~ReadWriteLock ()
 Destroy a read/write lock.

void ReadLock ()
 Lock for reading.

bool ReadTest ()
 Try to lock for reading.

void ReadUnlock ()
 Unlock for reading.

void WriteLock ()
 Lock for writing.

bool WriteTest ()
 Try to lock for writing.

void WriteUnlock ()
 Unlock for writing.


Private Attributes

GStaticRWLock l
 internally used lock structure


Detailed Description

This class implements a read/write lock.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
A read-write lock can be used for protecting data, that some portions of code only read from, while others also write. In such situations it is desirable, that several readers can read at once, whereas of course only one writer may write at a time.

Most of the time the writers should have precedence of readers. That means for this implementation, that as soon as a writer wants to lock the data, no other reader is allowed to lock the data, whereas of course the readers, that already have locked the data are allowed to finish their operation. As soon as the last reader unlocks the data, the writer will lock it. [quoted glib docu - thanks!]

Definition at line 46 of file rwlock.h.


Constructor & Destructor Documentation

ReadWriteLock::ReadWriteLock  )  [inline]
 

Set up a read/write lock.

Definition at line 53 of file rwlock.h.

References l.

ReadWriteLock::~ReadWriteLock  )  [inline]
 

Destroy a read/write lock.

Definition at line 57 of file rwlock.h.

References l.


Member Function Documentation

void ReadWriteLock::ReadLock  )  [inline]
 

Lock for reading.

There may be unlimited concurrent locks for reading at the same time. If the ReadWriteLock is already locked for writing by another thread or if another thread is already waiting to lock the ReadWriteLock for writing, then this function will block until the ReadWriteLock is unlocked by the other writing thread and no other writing threads want to lock the ReadWriteLock. [quoted glib docu - thanks!]

This lock has to be unlocked by ReadUnlock().

Definition at line 72 of file rwlock.h.

References l.

bool ReadWriteLock::ReadTest  )  [inline]
 

Try to lock for reading.

Tries to lock the ReadWriteLock for reading. If the ReadWriteLock is already locked for writing by another thread or if another thread is already waiting to lock the ReadWriteLock for writing, it immediately returns 0. Otherwise it locks the ReadWriteLock for reading and returns 1. [quoted glib docu - thanks!]

This lock has to be unlocked by ReadUnlock().

Definition at line 85 of file rwlock.h.

References l.

void ReadWriteLock::ReadUnlock  )  [inline]
 

Unlock for reading.

For more info, see ReadLock().

Definition at line 92 of file rwlock.h.

References l.

void ReadWriteLock::WriteLock  )  [inline]
 

Lock for writing.

If the ReadWriteLock is already locked for writing or reading by other threads, this function will block until the ReadWriteLock is completely unlocked and then lock the ReadWriteLock for writing. While this functions waits to lock the ReadWriteLock, no other thread can lock the ReadWriteLock for reading. When the ReadWriteLock is locked for writing, no other thread can lock the ReadWriteLock (neither for reading nor writing). [quoted glib docu - thanks!]

This lock has to be unlocked by WriteUnlock()

Definition at line 108 of file rwlock.h.

References l.

bool ReadWriteLock::WriteTest  )  [inline]
 

Try to lock for writing.

Tries to lock the ReadWriteLock for writing. If the ReadWriteLock is already locked (for either reading or writing) by another thread, it immediately returns 0. Otherwise it locks the ReadWriteLock for writing and returns 1. [quoted glib docu - thanks!]

This lock has to be unlocked by WriteUnlock()

Definition at line 121 of file rwlock.h.

References l.

void ReadWriteLock::WriteUnlock  )  [inline]
 

Unlock for writing.

For more info, see WriteLock().

Definition at line 128 of file rwlock.h.

References l.


Member Data Documentation

GStaticRWLock ReadWriteLock::l [private]
 

internally used lock structure

Definition at line 49 of file rwlock.h.

Referenced by ReadLock(), ReadTest(), ReadUnlock(), ReadWriteLock(), WriteLock(), WriteTest(), WriteUnlock(), and ~ReadWriteLock().


The documentation for this class was generated from the following file:
Generated on Sat Feb 19 22:35:35 2005 for Ray by doxygen 1.3.5