ROOT logo
// $Id: GMutex.h 2367 2010-04-18 20:50:40Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

#ifndef GledCore_GMutex_H
#define GledCore_GMutex_H

#include <Rtypes.h>
#ifndef __CINT__
#include <pthread.h>
#endif

class ZGlass;

/**************************************************************************/
// GMutex
/**************************************************************************/

class GMutex
{
protected:
#ifndef __CINT__
  pthread_mutex_t	mMut;	// X{P}
#endif

public:
  enum Init_e { fast, recursive, error_checking };
  enum Lock_e { ok=0, bad_init, deadlock, busy, perm_fail };

  GMutex(Init_e e=fast);
  ~GMutex();

  Lock_e Lock();
  Lock_e TryLock();
  Lock_e Unlock();

#ifndef __CINT__
#include "GMutex.h7"
#endif
  ClassDefNV(GMutex, 0);
}; // endclass GMutex


/**************************************************************************/
// GMutexHolder / AntiHolder
/**************************************************************************/

class GMutexHolder
{
  GMutex& mMutex;
public:
  GMutexHolder(GMutex& m) : mMutex(m) { mMutex.Lock();   }
  virtual ~GMutexHolder()             { mMutex.Unlock(); }

  ClassDef(GMutexHolder, 0);
};

// Usability of AntiHolder limited to cases when you're sure
// the mutex is locked exactly once.

class GMutexAntiHolder
{
  GMutex& mMutex;
public:
  GMutexAntiHolder(GMutex& m) : mMutex(m) { mMutex.Unlock();   }
  virtual ~GMutexAntiHolder()             { mMutex.Lock(); }

  ClassDef(GMutexAntiHolder, 0);
};

/**************************************************************************/
// GLensRead/WriteHolders
/**************************************************************************/

class GLensReadHolder
{
  ZGlass* mLens;
public:
  GLensReadHolder(ZGlass* lens);
  virtual ~GLensReadHolder();

  ClassDef(GLensReadHolder, 0);
};

class GLensWriteHolder
{
  ZGlass* mLens;
public:
  GLensWriteHolder(ZGlass* lens);
  virtual ~GLensWriteHolder();

  ClassDef(GLensWriteHolder, 0);
};

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