#ifndef TMCONTROLMutex_H
#define TMCONTROLMutex_H

#include <Rtypes.h>
#include <pthread.h>

typedef unsigned long int pthread_t; // needed to make rootcint happy :)

class TMControlMutex {

  public :

  virtual ~TMControlMutex();
  static TMControlMutex* Instance();

  virtual void   ITakeLock();
  virtual void   IReleaseLock();
  virtual Bool_t DoIHaveLock();

  virtual void   ResetMutex();
  
  virtual Bool_t IsLocked() {return fMutexLocked;}
  virtual pthread_t GetThreadLocked() {return fThreadLocked;}

  // these are not used at the moment:
  virtual Bool_t Lock();
  virtual void   UnLock();

 private:
  
  TMControlMutex();
  static Bool_t instanceFlag;
  static TMControlMutex *single;

  Bool_t    fMutexLocked;
  pthread_t fThreadLocked;


};

#endif
