/**********************************************
 * File: ThreadBoost.cpp
 * Author: Keith Schwarz (htiek@cs.stanford.edu)
 *
 * Implementation of the Thread class using
 * Boost threads.
 */

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

namespace synch {

  /* Thread implementation is just a thread. */
  struct Thread::Impl {
    thread mThread;
    
    /* Constructors initialize the thread with the start routine. */
    Impl(void function(void)) : mThread(function) {
      // Handled in initializer list
    }
    Impl(void function(void*), void* data) : mThread(function, data) {
      // Handled in initializer list
    }
  };
  
  /* Ctors just fire off a new thread. */
  Thread::Thread(void routine(void)) : mImpl(new Impl(routine)) {
    // Handled in initializer list
  }
  Thread::Thread(void routine(void*), void* data) : mImpl(new Impl(routine, data)) {
    // Handled in initializer list
  }
  
  /* Dtor cleans up the thread. */
  Thread::~Thread() {
    delete mImpl;
  }
  
  /* Join joins the thread. */
  void Thread::join() {
    mImpl->mThread.join();
  }
  
}
