static const char* version_number =
  "$Id: MutexRep.cc,v 1.4 1999/09/08 21:45:12 v2kea318 Exp $";

// $Log: MutexRep.cc,v $
// Revision 1.4  1999/09/08  21:45:12  v2kea318
// In the destructor, if there are no other references to the mutex, then
// destroy the mutex.
//
// Revision 1.3  1999/09/08  21:13:54  v2kea318
// Fixed a major bug in the destructor, which had rendered the class useless.
// We want to release the mutex when the reference count is greater than 1, not
// only at 2.
//
// Revision 1.2  1999/08/17  14:47:26  v2kea318
// *** empty log message ***
//
// Revision 1.1  1999/08/17  14:46:54  v2kea318
// Initial revision
//
//***************************************************************************

#include "MutexRep.h"

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

MutexRep::MutexRep(const MutexRep& mrep) : mut(mrep.mut)
{
    mut->grab();
}

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

MutexRep::~MutexRep() 
{
  size_t cnt = mut.count();

  /* If there is more than 1 reference to the pointer, release the mutex.
     If there is more than 2, the others will be blocked in the grab
     method of the mutex, i.e. they will be waiting for the mutex. */
  if (cnt > 1) mut->release();

  // if there is only 1 reference, destroy the mutex.
  if (cnt == 1) mut->destroy();
}

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

MutexRep& MutexRep::operator = (const MutexRep& r)
{
    if (this != &r) {
	mut = r.mut;
	mut->grab();
    }
    return *this;
}
