CPN
Computational Process Networks
PthreadMutexAttr.cc
Go to the documentation of this file.
1 //=============================================================================
2 // PthreadMutexAttr 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 "PthreadMutexAttr.h"
25 #endif
26 
28 #ifdef _POSIX_THREADS
29 
30 
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 {
35  TrapError(pthread_mutexattr_init(&theAttr));
36 }
37 
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
41 {
42  try {
43  TrapError(pthread_mutexattr_destroy(&theAttr));
44  } catch (...) {
45  std::terminate();
46  }
47 }
48 
49 
50 #if defined(_POSIX_THREAD_PRIO_PROTECT) && (_POSIX_THREAD_PRIO_PROTECT+0>0)
51 //-----------------------------------------------------------------------------
52 int PthreadMutexAttr::PriorityCeiling(void)
53 //-----------------------------------------------------------------------------
54 { int ceiling;
55  TrapError(pthread_mutexattr_getprioceiling(&theAttr, &ceiling));
56  return ceiling;
57 }
58 
59 //-----------------------------------------------------------------------------
60 PthreadMutexAttr& PthreadMutexAttr::PriorityCeiling(int ceiling)
61 //-----------------------------------------------------------------------------
62 { PriorityCeiling();
63  TrapError(pthread_mutexattr_setprioceiling(&theAttr, ceiling));
64  return *this;
65 }
66 #endif
67 
68 
69 #if (defined(_POSIX_THREAD_PRIO_PROTECT) && (_POSIX_THREAD_PRIO_PROTECT+0>0)) \
70  || (defined(_POSIX_THREAD_PRIO_INHERIT) && (_POSIX_THREAD_PRIO_INHERIT+0>0))
71 //-----------------------------------------------------------------------------
72 int PthreadMutexAttr::Protocol(void)
73 //-----------------------------------------------------------------------------
74 { int protocol;
75  TrapError(pthread_mutexattr_getprotocol(&theAttr, &protocol));
76  return protocol;
77 }
78 
79 //-----------------------------------------------------------------------------
80 PthreadMutexAttr& PthreadMutexAttr::Protocol(int protocol)
81 //-----------------------------------------------------------------------------
82 { TrapError(pthread_mutexattr_setprotocol(&theAttr, protocol));
83  return *this;
84 }
85 #endif
86 
87 
88 #if defined(_POSIX_THREAD_PROCESS_SHARED) && (_POSIX_THREAD_PROCESS_SHARED+0>0)
89 //-----------------------------------------------------------------------------
90 int PthreadMutexAttr::ProcessShared(void)
91 //-----------------------------------------------------------------------------
92 { int pshared;
93  TrapError(pthread_mutexattr_getpshared(&theAttr, &pshared));
94  return pshared == PTHREAD_PROCESS_SHARED;
95 }
96 
97 //-----------------------------------------------------------------------------
98 PthreadMutexAttr& PthreadMutexAttr::ProcessShared(int pshared)
99 //-----------------------------------------------------------------------------
100 { TrapError(pthread_mutexattr_setpshared(&theAttr, pshared ?
101  PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE));
102  return *this;
103 }
104 #endif
105 
106 
107 #endif
void TrapError(int result)
pthread_mutexattr_t theAttr