/* $Id: PosixMutex.h,v 1.4 1999/09/08 20:44:27 v2kea318 Exp $

$Log: PosixMutex.h,v $
 * Revision 1.4  1999/09/08  20:44:27  v2kea318
 * Reimplement the class as derived from the MutexPtrIntermedRep template
 * class.  This new parent class will manage the pointer to the native
 * mutex object.
 *
 * Revision 1.3  1999/09/08  20:15:29  v2kea318
 * Removed the clone() method.
 *
 * Revision 1.2  1999/09/08  20:07:43  v2kea318
 * Added os_do_destroy.
 *
 * Revision 1.1  1999/09/07  16:57:04  v2kea318
 * Initial revision
 *
***************************************************************************

Define a wrapper class for POSIX mutices.  The destructor for the class
will automatically unlock the mutex, if it is currently locked.  The user
must explicitly destroy it.

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

#ifndef MLIBSPP_UNIXMUTEX_H
#define MLIBSPP_UNIXMUTEX_H

#include "Pthread.h"
#include "pointer.h"
#include "MutexPtrIntermedRep.h"

class PosixMutex : public MutexPtrIntermedRep<pthread_mutex_t> {
public:
  typedef MutexPtrIntermedRep<pthread_mutex_t> IntermedRep;
public:
  // constructors.
  PosixMutex();
  PosixMutex(const PosixMutex& m) : IntermedRep(m) {}

  // assignment operator.
  PosixMutex& operator = (const PosixMutex& m)
    {
      if (this != &m) {
	IntermedRep::operator = (m);
      }
      return *this;
    }
  
protected:
  // grap the mutex.
  void os_grab();

  // release the mutex.
  void os_release();

  // destroy the mutex.
  void os_destroy();
};
    
#endif
