/*****************************************
 * File: MutexBoost.cpp
 * Author: Keith Schwarz (htiek@cs.stanford.edu)
 *
 * An implementation of the Mutex interface
 * using the Boost libraries.
 */

#include "Mutex.hh"
#include <boost/thread.hpp>
using namespace boost;

namespace synch {
  
  /* Implementation is just a wrapper around a boost::mutex. */
  struct Mutex::Impl {
    mutex mMutex; // The mutex itself
  };
  
  /* Constructor sets up a new implementation. */
  Mutex::Mutex() : mImpl(new Impl) {
    // Handled in initializer list
  }
  
  /* Destructor cleans up the implementation. */
  Mutex::~Mutex() {
    delete mImpl;
  }
  
  /* Lock just locks the underlying mutex. */
  void Mutex::lock() {
    mImpl->mMutex.lock();
  }
  
  /* Unlock just unlocks the underlying mutex. */
  void Mutex::unlock() {
    mImpl->mMutex.unlock();
  }
}
