Panda3D
|
A standard mutex, or mutual exclusion lock. More...
#include "pmutex.h"
Public Member Functions | |
Mutex (const char *name) | |
Mutex (const string &name) | |
void | acquire () const |
Grabs the mutex if it is available. | |
void | clear_name () |
The mutex name is only defined when compiling in DEBUG_THREADS mode. | |
bool | debug_is_locked () const |
Returns true if the current thread has locked the Mutex, false otherwise. | |
string | get_name () const |
The mutex name is only defined when compiling in DEBUG_THREADS mode. | |
bool | has_name () const |
The mutex name is only defined when compiling in DEBUG_THREADS mode. | |
void | output (ostream &out) const |
This method is declared virtual in MutexDebug, but non-virtual in MutexDirect. | |
void | release () const |
Releases the mutex. | |
void | set_name (const string &name) |
The mutex name is only defined when compiling in DEBUG_THREADS mode. | |
bool | try_acquire () const |
Returns immediately, with a true value indicating the mutex has been acquired, and false indicating it has not. | |
Static Public Attributes | |
static Mutex | _notify_mutex |
A standard mutex, or mutual exclusion lock.
Only one thread can hold ("lock") a mutex at any given time; other threads trying to grab the mutex will block until the holding thread releases it.
The standard mutex is not reentrant: a thread may not attempt to lock it twice. Although this may happen to work on some platforms (e.g. Win32), it will not work on all platforms; on some platforms, a thread can deadlock itself by attempting to lock the same mutex twice. If your code requires a reentrant mutex, use the ReMutex class instead.
This class inherits its implementation either from MutexDebug or MutexDirect, depending on the definition of DEBUG_THREADS.
void MutexDirect::acquire | ( | ) | const [inline, inherited] |
Grabs the mutex if it is available.
If it is not available, blocks until it becomes available, then grabs it. In either case, the function does not return until the mutex is held; you should then call unlock().
This method is considered const so that you can lock and unlock const mutexes, mainly to allow thread-safe access to otherwise const data.
Also see MutexHolder.
Definition at line 70 of file mutexDirect.I.
Referenced by AsyncTaskManager::add(), AsyncTaskChain::cleanup_task(), AsyncTaskChain::do_cleanup(), AsyncTaskChain::do_stop_threads(), Texture::do_unlock_and_reload_ram_image(), MutexHolder::MutexHolder(), AsyncTaskManager::remove(), and AsyncTask::unlock_and_do_task().
void MutexDirect::clear_name | ( | ) | [inline, inherited] |
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition at line 136 of file mutexDirect.I.
bool MutexDirect::debug_is_locked | ( | ) | const [inline, inherited] |
Returns true if the current thread has locked the Mutex, false otherwise.
This method is only intended for use in debugging, hence the method name; in the MutexDirect case, it always returns true, since there's not a reliable way to determine this otherwise.
Definition at line 115 of file mutexDirect.I.
string MutexDirect::get_name | ( | ) | const [inline, inherited] |
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition at line 157 of file mutexDirect.I.
bool MutexDirect::has_name | ( | ) | const [inline, inherited] |
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition at line 146 of file mutexDirect.I.
void MutexDirect::output | ( | ostream & | out | ) | const [inherited] |
This method is declared virtual in MutexDebug, but non-virtual in MutexDirect.
Definition at line 26 of file mutexDirect.cxx.
void MutexDirect::release | ( | ) | const [inline, inherited] |
Releases the mutex.
It is an error to call this if the mutex was not already locked.
This method is considered const so that you can lock and unlock const mutexes, mainly to allow thread-safe access to otherwise const data.
Definition at line 99 of file mutexDirect.I.
Referenced by AsyncTaskManager::add(), AsyncTaskChain::cleanup_task(), AsyncTaskChain::do_cleanup(), AsyncTaskChain::do_stop_threads(), Texture::do_unlock_and_reload_ram_image(), AsyncTaskManager::remove(), and AsyncTask::unlock_and_do_task().
void MutexDirect::set_name | ( | const string & | name | ) | [inline, inherited] |
The mutex name is only defined when compiling in DEBUG_THREADS mode.
Definition at line 126 of file mutexDirect.I.
bool MutexDirect::try_acquire | ( | ) | const [inline, inherited] |
Returns immediately, with a true value indicating the mutex has been acquired, and false indicating it has not.
Definition at line 83 of file mutexDirect.I.