Panda3D
Public Member Functions

ConditionVarFull Class Reference

This class implements a condition variable; see ConditionVar for a brief introduction to this class. More...

#include "conditionVarFull.h"

Inheritance diagram for ConditionVarFull:
ConditionVarFullDirect

List of all members.

Public Member Functions

 ConditionVarFull (Mutex &mutex)
 You must pass in a Mutex to the condition variable constructor.
Mutexget_mutex () const
 Returns the mutex associated with this condition variable.
void notify ()
 Informs one of the other threads who are currently blocked on wait() that the relevant condition has changed.
void notify_all ()
 Informs all of the other threads who are currently blocked on wait() that the relevant condition has changed.
void output (ostream &out) const
 This method is declared virtual in ConditionVarFullDebug, but non-virtual in ConditionVarFullDirect.
void wait (double timeout)
 Waits on the condition, with a timeout.
void wait ()
 Waits on the condition.

Detailed Description

This class implements a condition variable; see ConditionVar for a brief introduction to this class.

The ConditionVarFull class provides a more complete implementation than ConditionVar; in particular, it provides the notify_all() method, which is guaranteed to wake up all threads currently waiting on the condition (whereas notify() is guaranteed to wake up at least one thread, but may or may not wake up all of them).

This class exists because on certain platforms (e.g. Win32), implementing notify_all() requires more overhead, so you should use ConditionVar for cases when you do not require the notify_all() semantics.

There are still some minor semantics that POSIX condition variables provide which this implementation does not. For instance, it is required (not optional) that the caller of notify() or notify_all() is holding the condition variable's mutex before the call.

This class inherits its implementation either from ConditionVarFullDebug or ConditionVarFullDirect, depending on the definition of DEBUG_THREADS.

Definition at line 53 of file conditionVarFull.h.


Constructor & Destructor Documentation

ConditionVarFull::ConditionVarFull ( Mutex mutex) [inline]

You must pass in a Mutex to the condition variable constructor.

This mutex may be shared by other condition variables, if desired. It is the caller's responsibility to ensure the Mutex object does not destruct during the lifetime of the condition variable.

Definition at line 27 of file conditionVarFull.I.


Member Function Documentation

Mutex & ConditionVarFull::get_mutex ( ) const [inline]

Returns the mutex associated with this condition variable.

Reimplemented from ConditionVarFullDirect.

Definition at line 78 of file conditionVarFull.I.

void ConditionVarFullDirect::notify ( ) [inline, inherited]

Informs one of the other threads who are currently blocked on wait() that the relevant condition has changed.

If multiple threads are currently waiting, at least one of them will be woken up, although there is no way to predict which one. It is possible that more than one thread will be woken up.

The caller must be holding the mutex associated with the condition variable before making this call, which will not release the mutex.

If no threads are waiting, this is a no-op: the notify is lost.

Definition at line 142 of file conditionVarFullDirect.I.

Referenced by DatagramQueue::insert().

void ConditionVarFullDirect::notify_all ( ) [inline, inherited]

Informs all of the other threads who are currently blocked on wait() that the relevant condition has changed.

The caller must be holding the mutex associated with the condition variable before making this call, which will not release the mutex.

If no threads are waiting, this is a no-op: the notify event is lost.

Definition at line 162 of file conditionVarFullDirect.I.

Referenced by AsyncTaskChain::do_add(), AsyncTaskChain::do_poll(), AsyncTaskChain::do_stop_threads(), Texture::do_unlock_and_reload_ram_image(), DatagramQueue::extract(), AnimControl::fail_anim(), AsyncTaskChain::finish_sort_group(), AsyncTaskManager::poll(), AsyncTaskChain::service_one_task(), AnimControl::setup_anim(), and DatagramQueue::shutdown().

void ConditionVarFullDirect::output ( ostream &  out) const [inherited]

This method is declared virtual in ConditionVarFullDebug, but non-virtual in ConditionVarFullDirect.

Definition at line 26 of file conditionVarFullDirect.cxx.

void ConditionVarFullDirect::wait ( ) [inline, inherited]

Waits on the condition.

The caller must already be holding the lock associated with the condition variable before calling this function.

wait() will release the lock, then go to sleep until some other thread calls notify() on this condition variable. At that time at least one thread waiting on the same ConditionVarFullDirect will grab the lock again, and then return from wait().

It is possible that wait() will return even if no one has called notify(). It is the responsibility of the calling process to verify the condition on return from wait, and possibly loop back to wait again if necessary.

Note the semantics of a condition variable: the mutex must be held before wait() is called, and it will still be held when wait() returns. However, it will be temporarily released during the wait() call itself.

Definition at line 102 of file conditionVarFullDirect.I.

Referenced by Texture::do_unlock_and_reload_ram_image(), AsyncTaskChain::do_wait_for_tasks(), DatagramQueue::extract(), DatagramQueue::insert(), and AnimControl::wait_pending().

void ConditionVarFullDirect::wait ( double  timeout) [inline, inherited]

Waits on the condition, with a timeout.

The function will return when the condition variable is notified, or the timeout occurs. There is no way to directly tell which happened, and it is possible that neither in fact happened (spurious wakeups are possible).

See wait() with no parameters for more.

Definition at line 119 of file conditionVarFullDirect.I.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations