CPN
Computational Process Networks
PthreadBase.cc
Go to the documentation of this file.
1 //=============================================================================
2 // PthreadBase 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 "PthreadErrorHandler.h"
25 # pragma implementation "PthreadBase.h"
26 # pragma implementation "PthreadScheduleParam.h"
27 #endif
28 
30 #ifdef _POSIX_THREADS
31 
32 
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
36 {
37  theThread = Self();
38 }
39 
40 
41 //-----------------------------------------------------------------------------
42 PthreadBase::PthreadBase(pthread_t thread)
43 //-----------------------------------------------------------------------------
44 {
45  theThread = thread;
46 }
47 
48 
49 //-----------------------------------------------------------------------------
50 PthreadBase::PthreadBase(void* (*entryFunc)(void*), void* arg)
51 //-----------------------------------------------------------------------------
52 {
53  TrapError( pthread_create( (pthread_t*)&theThread, 0, entryFunc, arg) );
54 }
55 
56 
57 //-----------------------------------------------------------------------------
58 PthreadBase::PthreadBase(PthreadAttr& attr, void* (*entryFunc)(void*), void* arg)
59 //-----------------------------------------------------------------------------
60 {
61  TrapError( pthread_create( (pthread_t*)&theThread, (pthread_attr_t*)attr, entryFunc, arg) );
62 }
63 
64 
65 //-----------------------------------------------------------------------------
66 void* PthreadBase::Join(void)
67 //-----------------------------------------------------------------------------
68 {
69  void* result = 0;
70  TrapError( pthread_join(theThread, &result) );
71  return result;
72 }
73 
74 
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
78 {
79  int oldState;
80  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldState);
81  return oldState;
82 }
83 
84 
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
88 {
89  int oldState;
90  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
91  return oldState;
92 }
93 
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
97 {
98  int oldState;
99  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldState);
100  return oldState;
101 }
102 
103 
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
107 {
108  int oldState;
109  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldState);
110  return oldState;
111 }
112 
113 
114 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
115 //-----------------------------------------------------------------------------
116 int PthreadBase::SchedulePolicy(void)
117 //-----------------------------------------------------------------------------
118 {
119  int policy;
121  TrapError( pthread_getschedparam(theThread, &policy, sp) );
122  return policy;
123 }
124 
125 
126 //-----------------------------------------------------------------------------
127 int PthreadBase::SchedulePriority(void)
128 //-----------------------------------------------------------------------------
129 {
130  int policy;
132  TrapError( pthread_getschedparam(theThread, &policy, sp) );
133  return sp.Priority();
134 }
135 
136 
137 //-----------------------------------------------------------------------------
138 void PthreadBase::GetScheduleParams(int& policy, int& priority)
139 //-----------------------------------------------------------------------------
140 {
142  TrapError( pthread_getschedparam(theThread, &policy, sp) );
143  priority = sp.Priority();
144 }
145 
146 
147 //-----------------------------------------------------------------------------
148 void PthreadBase::SetScheduleParams(int policy, int priority)
149 //-----------------------------------------------------------------------------
150 {
152  sp.Priority(priority);
153  TrapError( pthread_setschedparam(theThread, policy, sp) );
154 }
155 
156 
157 //-----------------------------------------------------------------------------
158 void PthreadBase::GetScheduleParams(int& policy, PthreadScheduleParam& sp)
159 //-----------------------------------------------------------------------------
160 {
161  TrapError( pthread_getschedparam(theThread, &policy, sp) );
162 }
163 
164 
165 //-----------------------------------------------------------------------------
166 void PthreadBase::SetScheduleParams(int policy, PthreadScheduleParam& sp)
167 //-----------------------------------------------------------------------------
168 {
169  TrapError( pthread_setschedparam(theThread, policy, sp) );
170 }
171 #endif
172 
173 
174 #endif
int Priority(int priority)
static int CancelEnable(void)
Definition: PthreadBase.cc:76
static int CancelDeferred(void)
Definition: PthreadBase.cc:95
static int CancelDisable(void)
Definition: PthreadBase.cc:86
void * Join(void)
Definition: PthreadBase.cc:66
static pthread_t Self(void)
Definition: PthreadBase.h:61
static int CancelAsynchronous(void)
Definition: PthreadBase.cc:105
void TrapError(int result)
PthreadBase(void)
Definition: PthreadBase.cc:34
pthread_t theThread
Definition: PthreadBase.h:126