Inheritance diagram for smtk::conditional:

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> | |
| T | invalidate (T t) |
| invalidate the object | |
| void | invalidate (void) |
| invalidate the object | |
| template<class T> | |
| T | validate (T t) |
| validate the object | |
| void | validate (void) |
| validate the object | |
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.
| conditional::conditional | ( | struct conditional_struct * | cond = 0, |
|
| MODE | flag = GET | |||
| ) |
Create a conditional object.
| 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
| 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).
| 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.
| 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. |
| T smtk::validation::invalidate | ( | T | t | ) | [inline, protected, inherited] |
invalidate the object
Make the object invalid.
| 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
| bool smtk::validation::is_valid | ( | void | ) | const [inline, inherited] |
see if the object is valid
| int conditional::release_mutex | ( | void | ) |
release the mutex
| int conditional::signal | ( | void | ) |
brief signal the waiting processes
Signal the waiting processes (or threads) to continue.
| 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.
| T smtk::validation::validate | ( | T | t | ) | [inline, protected, inherited] |
validate the object
Make the object valid.
| 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).
| have_mutex | should be set to true if you called get_mutex() before this. |
1.5.2