CPN
Computational Process Networks
PthreadMutex.cc
Go to the documentation of this file.
1 //=============================================================================
2 // PthreadMutex class
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 #ifdef EXTERNAL_TEMPLATES
24 # pragma implementation "PthreadMutex.h"
25 #endif
26 
28 #ifdef _POSIX_THREADS
29 #include <errno.h>
30 
31 
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 //: theMutex(PTHREAD_MUTEX_INITIALIZER)
36 {
37  TrapError(pthread_mutex_init(&theMutex, 0));
38 }
39 
40 
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 {
45  // It should simply be:
46 // TrapError(pthread_mutex_init(&theMutex, mAttr));
47 
48  // This is necessary because
49  // SGI's pthread_mutex_init is not const correct!!!
50 
51  pthread_mutexattr_t* myAttr = (PthreadMutexAttr&)mAttr;
52  TrapError(pthread_mutex_init(&theMutex, myAttr));
53 }
54 
55 
56 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
59 {
60  try {
61  TrapError(pthread_mutex_destroy(&theMutex));
62  } catch (...) {
63  std::terminate();
64  }
65 }
66 
67 
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 { int err = pthread_mutex_trylock(&theMutex);
72  if(err == EBUSY)
73  return false;
74  TrapError(err);
75  return true;
76 }
77 
78 
79 #endif
bool Poll(void)
Definition: PthreadMutex.cc:69
pthread_mutex_t theMutex
Definition: PthreadMutex.h:57
PthreadMutex(void)
Definition: PthreadMutex.cc:33
~PthreadMutex(void)
Definition: PthreadMutex.cc:57
void TrapError(int result)