CPN
Computational Process Networks
PthreadMutex.h
Go to the documentation of this file.
1 //=============================================================================
2 // PthreadMutex and PthreadMutexProtected classes
3 //-----------------------------------------------------------------------------
4 // POSIX Pthread class library
5 // Copyright (C) 1997-1999 The University of Texas
6 //
7 // This library is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // The GNU Public License is available in the file LICENSE, or you
18 // can write to the Free Software Foundation, Inc., 59 Temple Place -
19 // Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
20 // World Wide Web at http://www.fsf.org.
21 //=============================================================================
22 
23 
24 #ifndef PthreadMutex_h
25 #define PthreadMutex_h
26 #pragma once
27 
28 #ifdef EXTERNAL_TEMPLATES
29 # pragma interface
30 #endif
31 
32 #include <cpn/common.h>
34 #ifdef _POSIX_THREADS
35 
38 
39 
41  public:
42  PthreadMutex(void);
43  PthreadMutex(const PthreadMutexAttr& attr);
44  ~PthreadMutex(void);
45 
46  inline operator pthread_mutex_t* () { return &theMutex; }
47  inline operator const pthread_mutex_t* () const { return &theMutex; }
48 
49  PthreadMutex& Lock(void) { TrapError(pthread_mutex_lock(&theMutex)); return *this; }
50  PthreadMutex& Unlock(void) { TrapError(pthread_mutex_unlock(&theMutex)); return *this; }
51  PthreadMutex& Take(void) { return Lock(); }
52  PthreadMutex& Give(void) { return Unlock(); }
53 
54  bool Poll(void);
55 
56 private:
57  pthread_mutex_t theMutex;
58 };
59 
60 
62  public:
65  private:
67 };
68 
69 
70 #endif
71 #endif
PthreadMutex & Lock(void)
Definition: PthreadMutex.h:49
bool Poll(void)
Definition: PthreadMutex.cc:69
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
PthreadMutex(void)
Definition: PthreadMutex.cc:33
PthreadMutex & Give(void)
Definition: PthreadMutex.h:52
PthreadMutexProtected(PthreadMutex &tm)
Definition: PthreadMutex.h:63
~PthreadMutex(void)
Definition: PthreadMutex.cc:57
PthreadMutex & Unlock(void)
Definition: PthreadMutex.h:50
PthreadMutex * theMutex
Definition: PthreadMutex.h:66
void TrapError(int result)
PthreadMutex & Take(void)
Definition: PthreadMutex.h:51