smtk::conditional Class Reference

a conditional wrapper class More...

Inheritance diagram for smtk::conditional:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 conditional (struct conditional_struct *cond=0, MODE flag=GET)
int get_mutex (void)
 get the mutex before a call to wait() or release_mutex()
int init (struct conditional_struct *cond, MODE flag=GET)
bool is_invalid (void) const
 see if the object is invalid
bool is_valid (void) const
 see if the object is valid
int release_mutex (void)
 release the mutex
int signal (void)
 brief signal the waiting processes
int signal_self (void)
 signal itself if it is blocking in a call to conditional::wait()
int wait (bool have_mutex=false)
 wait for the signal
virtual ~conditional (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

a conditional wrapper class

This class uses a mutex and a conditional to make a usable conditional for the special case that we needed for the SmTk shared memory blocking read function and other functions.


Constructor & Destructor Documentation

conditional::conditional ( struct conditional_struct *  cond = 0,
MODE  flag = GET 
)

Create a conditional object.

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

conditional::~conditional ( void   )  [virtual]

virtual destructor


Member Function Documentation

int conditional::get_mutex ( void   ) 

get the mutex before a call to wait() or release_mutex()

You can use this to block a signal before you call wait() to avoid a race condition. The next call to wait() will release the mutex. You must call wait(have_mutex=true) with the argument being true (not the default of have_mutex=false).

Returns:
0 on success, and -1 on error (and spews once).

int conditional::init ( struct conditional_struct *  cond,
MODE  flag = GET 
)

Initialize a conditional object.

This may be used to reuse an old object with a new conditional. Do not call this if this object is not in a call to wait(), signal(), or signal_self(), as could be the case in a signal catcher or other jumping function call.

Parameters:
cond is a pointer to a user provided struct conditional_struct. If the points to data in a shared memory file than this conditional may be shared between processes.
flag If flag is GET then the conditional will be created if it does not exist, else if flag is CONNECT than the conditional must exist before this call, or else if flag is CREATE the conditional must not exist before this call and it will be created.
Returns:
0 on success and returns 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 conditional::release_mutex ( void   ) 

release the mutex

Returns:
0 on success, and -1 on error (and spews once).

int conditional::signal ( void   ) 

brief signal the waiting processes

Signal the waiting processes (or threads) to continue.

Returns:
0 on success, and -1 on error (and spews once).

int conditional::signal_self ( void   ) 

signal itself if it is blocking in a call to conditional::wait()

This is handy to use in a signal catcher so that the your program can signal itself if it is blocking in a call to conditional::wait(). This works the same as conditional::signal(), but without the possiblity of a mutex deadlock that calling conditional::signal() from within conditional::wait() would have.

This will not signal if the object is not in a call to conditional::signal() or it fails to acquire the conditional mutex.

Q: Why not just have this release the current objects conditional::wait() call? Ans: That would require a much larger data structure in shared memory, and so it's less taxing to have users check for signal wake-ups that where not wanted events than add the addition structure to the conditional data structure in shared memory.

Returns:
0 if it does signal, returns 1 and spews if the mutex was not acquired and it could not signal, and -1 on error and spews.

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 conditional::wait ( bool  have_mutex = false  ) 

wait for the signal

This call will block until conditional::signal() is called by another process (or thread).

Parameters:
have_mutex should be set to true if you called get_mutex() before this.
Returns:
0 on success, and -1 on error (and spews once).


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