nidas  v1.2-1520
Public Member Functions | Private Member Functions | Private Attributes | List of all members
nidas::util::Mutex Class Reference

A C++ wrapper for a POSIX mutex. More...

#include <ThreadSupport.h>

Public Member Functions

 Mutex (int type=PTHREAD_MUTEX_DEFAULT) throw ()
 Construct a POSIX mutex of the given type. More...
 
 Mutex (const MutexAttributes &attr) throw (Exception)
 Construct a POSIX mutex with the given attributes. More...
 
 Mutex (const Mutex &x) throw ()
 Copy constructor. More...
 
 ~Mutex ()
 Destruct a Mutex. More...
 
void lock () throw (Exception)
 Lock the Mutex. More...
 
void unlock () throw (Exception)
 Unlock the Mutex. More...
 
pthread_mutex_t * ptr ()
 Get the pointer to the pthread_mutex_t. More...
 

Private Member Functions

Mutexoperator= (const Mutex &)
 No assignment allowed. More...
 

Private Attributes

pthread_mutex_t _p_mutex
 
MutexAttributes _attrs
 

Detailed Description

A C++ wrapper for a POSIX mutex.

Constructor & Destructor Documentation

Mutex::Mutex ( int  type = PTHREAD_MUTEX_DEFAULT)
throw (
)
explicit

Construct a POSIX mutex of the given type.

Parameters
typeOne of PTHREAD_MUTEX_NORMAL, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_DEFAULT (default). See man page for pthread_mutex_init, and pthread_mutexattr_settype. The following error conditions could occur in this constructor, but they are not thrown as exceptions. EAGAIN: system lacked resources ENOMEM: system lacked memory An exception will likely occur later when an lock attempt is made on this Mutex.
Mutex::Mutex ( const MutexAttributes attr)
throw (Exception
)

Construct a POSIX mutex with the given attributes.

This constructor can throw an exception in the following circumstances: EAGAIN: system lacked resources ENOMEM: system lacked memory EINVAL: invalid attributes

Mutex::Mutex ( const Mutex x)
throw (
)

Copy constructor.

Creates a new, unlocked mutex with the same attributes as x. The error handling is the same as with the default constructor.

Mutex::~Mutex ( )

Destruct a Mutex.

See man page for pthread_mutex_destroy. Mutex must not be locked, otherwise std::terminate() is called.

References _p_mutex, CLOG, and nidas::util::Exception::what().

Member Function Documentation

void nidas::util::Mutex::lock ( )
throw (Exception
)
inline

Lock the Mutex.

An exception will be thrown with error condition EDEADLK if this is a PTHREAD_MUTEX_ERRORCHECK type Mutex, and the current thread has already locked it. An exception for error EINVAL will be thrown if the Mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread’s priority is higher than the mutex’s current priority ceiling.

References _p_mutex.

Referenced by nidas::core::SensorHandler::add(), nidas::util::McSocketListener::add(), nidas::core::DerivedDataReader::addClient(), nidas::core::MultipleUDPSockets::addClient(), nidas::core::SensorHandler::addSensor(), nidas::core::Project::addSite(), nidas::core::MultipleUDPSockets::close(), nidas::util::McSocket< SocketT >::close(), nidas::core::DSMEngine::closeOutputs(), nidas::dynld::StatisticsProcessor::connectSource(), nidas::core::GetClocks::execute(), nidas::core::GetStatus::execute(), nidas::core::Project::findDSM(), nidas::core::Project::findSensor(), nidas::core::FsMount::finished(), nidas::dynld::StatisticsProcessor::flush(), nidas::core::CalFile::getAllPaths(), nidas::core::MultipleUDPSockets::handleChangedSockets(), nidas::core::SensorHandler::handlePollingChange(), nidas::core::Sample::holdReference(), nidas::core::SamplePipeline::interrupt(), nidas::util::McSocketMulticaster< SocketTT >::interrupt(), nidas::core::SamplePipeline::join(), nidas::util::McSocket< SocketT >::joinMulticaster(), nidas::core::SampleClientList::lock(), nidas::util::Cond::lock(), nidas::core::DerivedDataReader::notifyClients(), nidas::dynld::RawSampleService::printStatus(), nidas::util::Thread::pRun(), nidas::core::SensorHandler::remove(), nidas::core::SampleSourceSupport::removeAllSampleClients(), nidas::core::DerivedDataReader::removeClient(), nidas::core::Looper::removeClient(), nidas::util::McSocket< SocketT >::request(), nidas::core::Looper::run(), nidas::dynld::isff::GOESOutput::run(), nidas::core::SensorHandler::run(), nidas::util::McSocketListener::run(), nidas::util::McSocketMulticaster< SocketTT >::run(), nidas::core::SensorHandler::scheduleAdd(), nidas::core::SensorHandler::scheduleClose(), nidas::core::SensorHandler::scheduleReopen(), nidas::dynld::StatisticsProcessor::selectRequestedSampleTags(), nidas::core::SensorHandler::sensorIsOpen(), nidas::core::CalFile::setPath(), nidas::util::Thread::thr_cleanup_delete(), nidas::core::SampleArchiver::~SampleArchiver(), nidas::core::SamplePipeline::~SamplePipeline(), nidas::dynld::StatisticsProcessor::~StatisticsProcessor(), and nidas::dynld::raf::SyncRecordGenerator::~SyncRecordGenerator().

Mutex& nidas::util::Mutex::operator= ( const Mutex )
private

No assignment allowed.

pthread_mutex_t * Mutex::ptr ( )

Get the pointer to the pthread_mutex_t.

References _p_mutex.

Referenced by nidas::util::Thread::pRun(), and nidas::util::Cond::wait().

void nidas::util::Mutex::unlock ( )
throw (Exception
)
inline

Unlock the Mutex.

An exception will be thrown for error condition EPERM if this is an PTHREAD_MUTEX_ERRORCHECK Mutex and the current thread does not hold a lock.

References _p_mutex.

Referenced by nidas::core::SensorHandler::add(), nidas::util::McSocketListener::add(), nidas::core::DerivedDataReader::addClient(), nidas::core::MultipleUDPSockets::addClient(), nidas::core::SensorHandler::addSensor(), nidas::core::Project::addSite(), nidas::core::MultipleUDPSockets::close(), nidas::util::McSocket< SocketT >::close(), nidas::core::DSMEngine::closeOutputs(), nidas::dynld::StatisticsProcessor::connectSource(), nidas::core::GetClocks::execute(), nidas::core::GetStatus::execute(), nidas::core::Project::findDSM(), nidas::core::Project::findSensor(), nidas::core::FsMount::finished(), nidas::dynld::StatisticsProcessor::flush(), nidas::core::CalFile::getAllPaths(), nidas::core::MultipleUDPSockets::handleChangedSockets(), nidas::core::SensorHandler::handlePollingChange(), nidas::core::Sample::holdReference(), nidas::core::SamplePipeline::interrupt(), nidas::util::McSocketMulticaster< SocketTT >::interrupt(), nidas::core::SamplePipeline::join(), nidas::util::McSocket< SocketT >::joinMulticaster(), nidas::core::DerivedDataReader::notifyClients(), nidas::dynld::RawSampleService::printStatus(), nidas::core::SensorHandler::remove(), nidas::core::SampleSourceSupport::removeAllSampleClients(), nidas::core::DerivedDataReader::removeClient(), nidas::core::Looper::removeClient(), nidas::util::McSocket< SocketT >::request(), nidas::core::Looper::run(), nidas::dynld::isff::GOESOutput::run(), nidas::core::SensorHandler::run(), nidas::util::McSocketListener::run(), nidas::util::McSocketMulticaster< SocketTT >::run(), nidas::core::SensorHandler::scheduleAdd(), nidas::core::SensorHandler::scheduleClose(), nidas::core::SensorHandler::scheduleReopen(), nidas::dynld::StatisticsProcessor::selectRequestedSampleTags(), nidas::core::SensorHandler::sensorIsOpen(), nidas::core::CalFile::setPath(), nidas::util::Thread::thr_cleanup_delete(), nidas::core::SampleClientList::unlock(), nidas::util::Cond::unlock(), nidas::core::SampleArchiver::~SampleArchiver(), nidas::core::SamplePipeline::~SamplePipeline(), nidas::dynld::StatisticsProcessor::~StatisticsProcessor(), and nidas::dynld::raf::SyncRecordGenerator::~SyncRecordGenerator().

Member Data Documentation

MutexAttributes nidas::util::Mutex::_attrs
private
pthread_mutex_t nidas::util::Mutex::_p_mutex
private

Referenced by lock(), ptr(), unlock(), and ~Mutex().


The documentation for this class was generated from the following files: