/* Method to lock object's mutex.
* @exception ned21_Exception Thrown if this mutex is already locked
* by this thread.
*/
void SynchronisedObject::lock() throw( ned21_Exception & )
{
// mutex_lock() either returns success or EDEADLK
if( pthread_mutex_lock( &mutex_lock ) == EDEADLK )
{
/* if in debug mode, print out a message saying where exception
* occurred. Useful as C++ does not check exceptions like Java
* and so an uncaught exception just causes termination and the
* very helpful `Aborted' message!
*/
assert( cerr << "Exception in lock()" << endl );
throw( ned21_Exception("Trying to lock more than once! Deadlock
would have resulted") );
}
}