smtk::rwlock Class Reference

read-write lock wrapper More...

Inheritance diagram for smtk::rwlock:

Inheritance graph
[legend]
List of all members.

Public Member Functions

int init (struct rwlock_struct *lock, MODE flag=GET)
 initialize the lock
bool is_invalid (void) const
 see if the object is invalid
bool is_valid (void) const
 see if the object is valid
int rlock (void)
 acquire the read lock
int runlock (void)
 release the read lock
 rwlock (struct rwlock_struct *lock=0, MODE flag=GET)
int try_rlock (void)
 try to get the read lock
int try_wlock (void)
 try to get the write lock
int wlock (void)
 acquire the write lock
int wunlock (void)
 release the write lock
virtual ~rwlock (void)

Protected Member Functions

template<class T>
invalidate (T t)
 invalidate the object
void invalidate (void)
 invalidate the object
template<class T>
validate (T t)
 validate the object
void validate (void)
 validate the object

Detailed Description

read-write lock wrapper

This is a read-write lock wrapper. In GNU/Linux systems it wraps pthreads read-write locks. These are setup to be inter-process read-write locks, with the intent of using them to provide consistent inter-process shared memory.


Constructor & Destructor Documentation

rwlock::rwlock ( struct rwlock_struct *  lock = 0,
MODE  flag = GET 
)

Create a read-write lock object.

Parameters:
lock is a pointer to a user provided struct rwlock_struct. If the points to data in a shared memory file than this lock may be shared between processes. If lock=0 you can call conditional::init() later to initialize this object.
flag If flag is GET then the read-write lock will be created if it does not exist, else if flag is CONNECT than the read-write lock must exist before this call, or else if flag is CREATE the read-write lock must not exist before this call and it will be created.

rwlock::~rwlock ( void   )  [virtual]

virtual destructor


Member Function Documentation

int rwlock::init ( struct rwlock_struct *  lock,
MODE  flag = GET 
)

initialize the lock

This will work the same as the constructor.

This may be used to reuse an old object with a new read-write lock. Do not call this if this object is not in a call to rlock(), wlock() try_rlock(), or try_wlock(), as could be the case in a signal catcher or other jumping function call.

Parameters:
lock is a pointer to a user provided struct rwlock_struct. If the points to data in a shared memory file than this lock may be shared between processes.
flag If flag is GET then the read-write lock will be created if it does not exist, else if flag is CONNECT than the read-write lock must exist before this call, or else if flag is CREATE the read-write lock must not exist before this call and it will be created.
Returns:
0 on success and 1 on error (and spews).

template<class T>
T smtk::validation::invalidate ( t  )  [inline, protected, inherited]

invalidate the object

Make the object invalid.

Returns:
t the argument the user passed.

void smtk::validation::invalidate ( void   )  [inline, protected, inherited]

invalidate the object

Make the object invalid.

bool smtk::validation::is_invalid ( void   )  const [inline, inherited]

see if the object is invalid

Returns:
true if the object is invalid, and false if not.

bool smtk::validation::is_valid ( void   )  const [inline, inherited]

see if the object is valid

Returns:
true if the object is valid, and false if not.

int rwlock::rlock ( void   ) 

acquire the read lock

The rlock() method shall apply a read lock to the read-write lock referenced by rwlock. The calling thread (or process) acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock.

Returns:
0 on success, and -1 on error

int rwlock::runlock ( void   ) 

release the read lock

Returns:
0 on success, and -1 on error

int rwlock::try_rlock ( void   ) 

try to get the read lock

This will not block.

Returns:
0 on success and acquires the read lock, returns 1 if not, and returns -1 when the lock was not acquired do to an error.

int rwlock::try_wlock ( void   ) 

try to get the write lock

This will not block.

Returns:
0 on success and acquires the read lock, returns 1 if not, and returns -1 when the lock was not acquired do to an error.

template<class T>
T smtk::validation::validate ( t  )  [inline, protected, inherited]

validate the object

Make the object valid.

Returns:
t the argument the user passed.

void smtk::validation::validate ( void   )  [inline, protected, inherited]

validate the object

Make the object valid.

int rwlock::wlock ( void   ) 

acquire the write lock

The wlock() method shall apply a write lock to the read-write lock referenced by object. The calling thread acquires the write lock if no other thread (or process) (reader or writer) holds the read-write lock rwlock. Otherwise, the thread shall block until it can acquire the lock. The calling thread may deadlock if at the time the call is made it holds the read-write lock (whether a read or write lock).

Returns:
0 on success, and -1 on error

int rwlock::wunlock ( void   ) 

release the write lock

Returns:
0 on success, and -1 on error


The documentation for this class was generated from the following files:
Generated on Sat Aug 11 22:25:57 2007 for Simulation Toolkit (SmTk) by  doxygen 1.5.2