// @(#)root/thread:$Id$
// Author: Fons Rademakers   25/06/97

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TPosixMutex                                                          //
//                                                                      //
// This class provides an interface to the posix mutex routines.        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TThread.h"
#include "TPosixMutex.h"
#include "PosixThreadInc.h"

ClassImp(TPosixMutex)

//______________________________________________________________________________
TPosixMutex::TPosixMutex(Bool_t recursive) : TMutexImp()
{
   // Create a posix mutex lock.

   if (recursive) {

      int rc;
      pthread_mutexattr_t attr;

      rc = pthread_mutexattr_init(&attr);

      if (!rc) {
         rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
         if (!rc) {
            rc = pthread_mutex_init(&fMutex, &attr);
            if (rc)
               SysError("TPosixMutex", "pthread_mutex_init error");
         } else
            SysError("TPosixMutex", "pthread_mutexattr_settype error");
      } else
         SysError("TPosixMutex", "pthread_mutex_init error");

      pthread_mutexattr_destroy(&attr);

   } else {

      int rc = pthread_mutex_init(&fMutex, 0);
      if (rc)
         SysError("TPosixMutex", "pthread_mutex_init error");

   }
}

//______________________________________________________________________________
TPosixMutex::~TPosixMutex()
{
   // TMutex dtor.

   int rc = pthread_mutex_destroy(&fMutex);
   if (rc)
      SysError("~TPosixMutex", "pthread_mutex_destroy error");
}

//______________________________________________________________________________
Int_t TPosixMutex::Lock()
{
   // Lock the mutex.

   return pthread_mutex_lock(&fMutex);
}

//______________________________________________________________________________
Int_t TPosixMutex::TryLock()
{
   // Try locking the mutex. Returns 0 if mutex can be locked.

   return pthread_mutex_trylock(&fMutex);
}

//______________________________________________________________________________
Int_t TPosixMutex::UnLock(void)
{
   // Unlock the mutex.

   return pthread_mutex_unlock(&fMutex);
}
 TPosixMutex.cxx:1
 TPosixMutex.cxx:2
 TPosixMutex.cxx:3
 TPosixMutex.cxx:4
 TPosixMutex.cxx:5
 TPosixMutex.cxx:6
 TPosixMutex.cxx:7
 TPosixMutex.cxx:8
 TPosixMutex.cxx:9
 TPosixMutex.cxx:10
 TPosixMutex.cxx:11
 TPosixMutex.cxx:12
 TPosixMutex.cxx:13
 TPosixMutex.cxx:14
 TPosixMutex.cxx:15
 TPosixMutex.cxx:16
 TPosixMutex.cxx:17
 TPosixMutex.cxx:18
 TPosixMutex.cxx:19
 TPosixMutex.cxx:20
 TPosixMutex.cxx:21
 TPosixMutex.cxx:22
 TPosixMutex.cxx:23
 TPosixMutex.cxx:24
 TPosixMutex.cxx:25
 TPosixMutex.cxx:26
 TPosixMutex.cxx:27
 TPosixMutex.cxx:28
 TPosixMutex.cxx:29
 TPosixMutex.cxx:30
 TPosixMutex.cxx:31
 TPosixMutex.cxx:32
 TPosixMutex.cxx:33
 TPosixMutex.cxx:34
 TPosixMutex.cxx:35
 TPosixMutex.cxx:36
 TPosixMutex.cxx:37
 TPosixMutex.cxx:38
 TPosixMutex.cxx:39
 TPosixMutex.cxx:40
 TPosixMutex.cxx:41
 TPosixMutex.cxx:42
 TPosixMutex.cxx:43
 TPosixMutex.cxx:44
 TPosixMutex.cxx:45
 TPosixMutex.cxx:46
 TPosixMutex.cxx:47
 TPosixMutex.cxx:48
 TPosixMutex.cxx:49
 TPosixMutex.cxx:50
 TPosixMutex.cxx:51
 TPosixMutex.cxx:52
 TPosixMutex.cxx:53
 TPosixMutex.cxx:54
 TPosixMutex.cxx:55
 TPosixMutex.cxx:56
 TPosixMutex.cxx:57
 TPosixMutex.cxx:58
 TPosixMutex.cxx:59
 TPosixMutex.cxx:60
 TPosixMutex.cxx:61
 TPosixMutex.cxx:62
 TPosixMutex.cxx:63
 TPosixMutex.cxx:64
 TPosixMutex.cxx:65
 TPosixMutex.cxx:66
 TPosixMutex.cxx:67
 TPosixMutex.cxx:68
 TPosixMutex.cxx:69
 TPosixMutex.cxx:70
 TPosixMutex.cxx:71
 TPosixMutex.cxx:72
 TPosixMutex.cxx:73
 TPosixMutex.cxx:74
 TPosixMutex.cxx:75
 TPosixMutex.cxx:76
 TPosixMutex.cxx:77
 TPosixMutex.cxx:78
 TPosixMutex.cxx:79
 TPosixMutex.cxx:80
 TPosixMutex.cxx:81
 TPosixMutex.cxx:82
 TPosixMutex.cxx:83
 TPosixMutex.cxx:84
 TPosixMutex.cxx:85
 TPosixMutex.cxx:86
 TPosixMutex.cxx:87
 TPosixMutex.cxx:88
 TPosixMutex.cxx:89
 TPosixMutex.cxx:90
 TPosixMutex.cxx:91
 TPosixMutex.cxx:92