static const char* version_number =
  "$Id: Mutex.cc,v 2.6 1999/09/08 20:06:58 v2kea318 Exp $";

// $Log: Mutex.cc,v $
// Revision 2.6  1999/09/08  20:06:58  v2kea318
// Added more code to the destroy() method to do as much here and leave the
// truly OS specific code to the derived classes.
//
// Revision 2.5  1999/09/08  19:51:14  v2kea318
// *** empty log message ***
//
// Revision 2.4  1999/09/08  19:40:07  v2kea318
// *** empty log message ***
//
// Revision 2.3  1999/09/08  19:37:53  v2kea318
// Added the WindowsMutex type for the Windows operating system.
//
// Revision 2.2  1999/09/08  19:28:03  v2kea318
// *** empty log message ***
//
// Revision 2.1  1999/09/07  17:03:28  v2kea318
// Implement the new OS-independant design of the class.
//
// Revision 1.4  1999/08/12  19:18:42  v2kea318
// Added the RCS log.
//
//***************************************************************************

#include "Mutex.h"
#include <stdexcept>

//***************************************************************************

Mutex& Mutex::operator = (const Mutex& m)
{
  if (this != &m) {
    attrs = m.attrs; 
  } 
  return *this;
}

//***************************************************************************

void Mutex::grab()
{
  os_grab();  // do the OS specific stuff.
  mark_locked();
}

//***************************************************************************

void Mutex::release()
{
  if (!locked()) throw runtime_error("mutex not held!");
  os_release();
  mark_unlocked();
}

//***************************************************************************

void Mutex::destroy() 
{
  grab();
  if (os_do_destroy()) {  // we do want to destroy it.
    os_destroy();
    mark_unlocked();  /* pretend we don't have it locked to avoid 
			 destructor problems. */
  } else
    release();
}

//***************************************************************************

#if defined(unix) || #system(unix)
#include "PosixMutex.h"
#define OS_MUTEX_TYPE PosixMutex
#elif defined(_WIN32)
#include "WindowsMutex.h"
#define OS_MUTEX_TYPE WindowsMutex
#else
#error OS not recognized!
#endif

Mutex* Mutex::new_mutex() 
{
  return new OS_MUTEX_TYPE;
}

