Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArMutex Class Reference

Mutex wrapper class. More...

#include <ArMutex.h>

List of all members.

Public Types

typedef pthread_mutex_t MutexType
enum  Status { STATUS_FAILED_INIT = 1, STATUS_FAILED, STATUS_ALREADY_LOCKED }

Public Member Functions

 ArMutex ()
 Constructor.
virtual const char * getError (int messageNumber) const
 Get a human readable error message from an error code.
virtual MutexType & getMutex ()
 Get a reference to the underlying mutex variable.
virtual int lock ()
 Lock the mutex.
void setLog (bool log)
 Sets a flag that will log out when we lock and unlock (not trylock).
void setLogName (const char *logName)
 Sets a name we'll use to log with.
virtual int tryLock ()
 Try to lock the mutex, but do not block.
virtual int unlock ()
 Unlock the mutex, allowing another thread to obtain the lock.
virtual ~ArMutex ()
 Destructor.

Protected Attributes

bool myFailedInit
bool myLog
std::string myLogName
MutexType myMutex
ArStrMap myStrMap


Detailed Description

Mutex wrapper class.

This class wraps the operating system's mutex functions. It allows mutualy exclusive access to a critical section. This is extremely useful for multiple threads which want to use the same variable. On Linux, ArMutex simply uses the POSIX pthread interface in an object oriented manner. It also applies the same concept to Windows using Windows' own abilities to restrict access to critical sections.

Definition at line 46 of file ArMutex.h.


Member Enumeration Documentation

enum ArMutex::Status
 

Enumeration values:
STATUS_FAILED_INIT  Failed to initialize.
STATUS_FAILED  General failure.
STATUS_ALREADY_LOCKED  Mutex already locked.

Definition at line 56 of file ArMutex.h.


Member Function Documentation

int ArMutex::lock  )  [virtual]
 

Lock the mutex.

Lock the mutex. This function will block until no other thread has this mutex locked. If it returns 0, then it obtained the lock and the thread is free to use the critical section that this mutex protects. Else it returns an error code. See getError().

Definition at line 72 of file ArMutex_LIN.cpp.

References ArThread::getThread(), ArThread::getThreadName(), ArLog::log(), ArThread::self(), STATUS_ALREADY_LOCKED, STATUS_FAILED, and STATUS_FAILED_INIT.

Referenced by Aria::addExitCallback(), ArDataLogger::addString(), ArSick::blockingConnect(), Aria::callExitCallbacks(), ArThread::cancel(), ArThread::cancelAll(), ArThread::create(), ArForbiddenRangeDevice::disable(), ArSick::disconnect(), ArForbiddenRangeDevice::enable(), Aria::exit(), ArActionTriangleDriveTo::findTriangle(), ArActionTriangleDriveTo::fire(), ArActionTriangleDriveTo::getData(), ArThread::init(), ArLog::init(), ArThread::join(), ArThread::joinAll(), ArVersalogicIO::lock(), ArThread::lock(), ArSoundsQueue::lock(), ArRobot::lock(), ArNetServer::lock(), ArMap::lock(), ArRangeDevice::lockDevice(), ArLog::log(), ArForbiddenRangeDevice::processMap(), ArForbiddenRangeDevice::processReadings(), ArASyncTask::runInThisThread(), ArSick::runOnce(), ArSick::runThread(), ArThread::self(), ArSick::setDeviceConnection(), Aria::shutdown(), Aria::signalHandlerCB(), ArThread::stopAll(), ArSick::switchState(), ArCondition::timedWait(), and ArCondition::wait().

int ArMutex::tryLock  )  [virtual]
 

Try to lock the mutex, but do not block.

Try to lock the mutex. This function will not block if another thread has the mutex locked. It will return instantly if that is the case. It will return STATUS_ALREADY_LOCKED if another thread has the mutex locked. If it obtains the lock, it will return 0.

Definition at line 111 of file ArMutex_LIN.cpp.

References STATUS_ALREADY_LOCKED, STATUS_FAILED, and STATUS_FAILED_INIT.

Referenced by ArVersalogicIO::tryLock(), ArThread::tryLock(), ArSoundsQueue::tryLock(), ArRobot::tryLock(), ArNetServer::tryLock(), ArMap::tryLock(), and ArRangeDevice::tryLockDevice().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:51 2005 for Aria by  doxygen 1.4.0