/*********************************************************
 * File: Mutex.hh
 * Author: Keith Schwarz (htiek@cs.stanford.edu)
 *
 * A mutex class that can be implemented with multiple
 * backends based on what libraries are available on the
 * system.  Ideally, this should work with:
 *
 * - C++0x
 * - Boost
 * - pthread
 * - Win32
 */
#ifndef Mutex_Included
#define Mutex_Included

#include "Lock.hh"

namespace synch {
  class Mutex: public synch::Lock {
  public:
    /**
     * Constructor: Mutex();
     * ----------------------------------------------------
     * Constructs a new Mutex object.
     */
    Mutex();
    
    /**
     * Destructor: ~Mutex();
     * ----------------------------------------------------
     * Cleans up any resources used by the mutex.  You must
     * not allow a mutex to be cleaned up while it is use
     * or you risk undefined behavior.
     */
    ~Mutex();
    
    /**
     * void lock();
     * -----------------------------------------------------
     * Locks the mutex, blocking until it becomes available.
     */
    void lock();
    
    /**
     * void unlock();
     * -----------------------------------------------------
     * Unlocks the mutex.  The calling thread must have a
     * lock on the mutex or the result is undefined.
     */
    void unlock();
    
  private:
    /* pImpl idiom to hide implementation. */
    struct Impl;
    Impl* mImpl;
  };
}

#endif
