1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// $Id$
// ============================================================================
//
// = LIBRARY
// ACE
//
// = FILENAME
// Sched_Params.cpp
//
// = CREATION DATE
// 28 January 1997
//
// = AUTHOR
// David Levine
//
// ============================================================================
#define ACE_BUILD_DLL
#include "ace/ACE.h"
#include "ace/Sched_Params.h"
#if !defined (__ACE_INLINE__)
#include "ace/Sched_Params.i"
#endif /* __ACE_INLINE__ */
#if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
# include /**/ <sys/rtpriocntl.h>
# include /**/ <sys/tspriocntl.h>
#endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
ACE_RCSID(ace, Sched_Params, "$Id$")
int
ACE_Sched_Params::priority_min (const Policy policy,
const int scope)
{
#if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
ACE_UNUSED_ARG (scope);
// Assume that ACE_SCHED_OTHER indicates TS class, and that other
// policies indicate RT class.
if (policy == ACE_SCHED_OTHER)
{
// Get the priority class ID and attributes.
pcinfo_t pcinfo;
// The following is just to avoid Purify warnings about unitialized
// memory reads.
ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
ACE_OS::strcpy (pcinfo.pc_clname, "TS");
if (ACE_OS::priority_control (P_ALL /* ignored */,
P_MYID /* ignored */,
PC_GETCID,
(char *) &pcinfo) == -1)
// Just hope that priority range wasn't configured from -1
// .. 1
return -1;
// OK, now we've got the class ID in pcinfo.pc_cid. In
// addition, the maximum configured time-share priority is in
// ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri. The minimum
// priority is just the negative of that.
return -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri;
}
else
return 0;
#elif defined (ACE_HAS_PTHREADS) && !defined(ACE_LACKS_SETSCHED)
switch (scope)
{
case ACE_SCOPE_THREAD:
switch (policy)
{
case ACE_SCHED_FIFO:
return ACE_THR_PRI_FIFO_MIN;
case ACE_SCHED_RR:
return ACE_THR_PRI_RR_MIN;
#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value
case ACE_SCHED_OTHER:
#endif /* CHORUS */
default:
return ACE_THR_PRI_OTHER_MIN;
}
case ACE_SCOPE_PROCESS:
default:
switch (policy)
{
case ACE_SCHED_FIFO:
return ACE_PROC_PRI_FIFO_MIN;
case ACE_SCHED_RR:
return ACE_PROC_PRI_RR_MIN;
#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value
case ACE_SCHED_OTHER:
#endif /* CHORUS */
default:
return ACE_PROC_PRI_OTHER_MIN;
}
}
#elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
return THREAD_PRIORITY_IDLE;
#elif defined (VXWORKS)
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
return 255;
#else
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
}
int
ACE_Sched_Params::priority_max (const Policy policy,
const int scope)
{
#if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
ACE_UNUSED_ARG (scope);
// Assume that ACE_SCHED_OTHER indicates TS class, and that other
// policies indicate RT class.
// Get the priority class ID and attributes.
pcinfo_t pcinfo;
// The following is just to avoid Purify warnings about unitialized
// memory reads.
ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
ACE_OS::strcpy (pcinfo.pc_clname,
policy == ACE_SCHED_OTHER ? "TS" : "RT");
if (ACE_OS::priority_control (P_ALL /* ignored */,
P_MYID /* ignored */,
PC_GETCID,
(char *) &pcinfo) == -1)
return -1;
// OK, now we've got the class ID in pcinfo.pc_cid. In addition,
// the maximum configured real-time priority is in ((rtinfo_t *)
// pcinfo.pc_clinfo)->rt_maxpri, or similarly for the TS class.
return policy == ACE_SCHED_OTHER
? ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri
: ((rtinfo_t *) pcinfo.pc_clinfo)->rt_maxpri;
#elif defined(ACE_HAS_PTHREADS) && !defined(ACE_LACKS_SETSCHED)
switch (scope)
{
case ACE_SCOPE_THREAD:
switch (policy)
{
case ACE_SCHED_FIFO:
return ACE_THR_PRI_FIFO_MAX;
case ACE_SCHED_RR:
return ACE_THR_PRI_RR_MAX;
#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value
case ACE_SCHED_OTHER:
#endif /* CHORUS */
default:
return ACE_THR_PRI_OTHER_MAX;
}
case ACE_SCOPE_PROCESS:
default:
switch (policy)
{
case ACE_SCHED_FIFO:
return ACE_PROC_PRI_FIFO_MAX;
case ACE_SCHED_RR:
return ACE_PROC_PRI_RR_MAX;
#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value
case ACE_SCHED_OTHER:
#endif /* CHORUS */
default:
return ACE_PROC_PRI_OTHER_MAX;
}
}
#elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
return THREAD_PRIORITY_TIME_CRITICAL;
#elif defined (VXWORKS)
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
return 0;
#else
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
}
int
ACE_Sched_Params::next_priority (const Policy policy,
const int priority,
const int scope)
{
#if defined (VXWORKS)
return priority > priority_max (policy, scope)
? priority - 1
: priority_max (policy, scope);
#elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
switch (priority)
{
case THREAD_PRIORITY_IDLE:
return THREAD_PRIORITY_LOWEST;
case THREAD_PRIORITY_LOWEST:
return THREAD_PRIORITY_BELOW_NORMAL;
case THREAD_PRIORITY_BELOW_NORMAL:
return THREAD_PRIORITY_NORMAL;
case THREAD_PRIORITY_NORMAL:
return THREAD_PRIORITY_ABOVE_NORMAL;
case THREAD_PRIORITY_ABOVE_NORMAL:
return THREAD_PRIORITY_HIGHEST;
case THREAD_PRIORITY_HIGHEST:
return THREAD_PRIORITY_TIME_CRITICAL;
case THREAD_PRIORITY_TIME_CRITICAL:
return THREAD_PRIORITY_TIME_CRITICAL;
default:
return priority; // unknown priority: should never get here
}
#elif defined(ACE_HAS_THREADS) && !defined(ACE_LACKS_SETSCHED)
// including STHREADS, and PTHREADS
const int max = priority_max (policy, scope);
return priority < max ? priority + 1 : max;
#else
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
ACE_UNUSED_ARG (priority);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
int
ACE_Sched_Params::previous_priority (const Policy policy,
const int priority,
const int scope)
{
#if defined (VXWORKS)
return priority < priority_min (policy, scope)
? priority + 1
: priority_min (policy, scope);
#elif defined (ACE_HAS_WTHREADS)
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
switch (priority)
{
case THREAD_PRIORITY_IDLE:
return THREAD_PRIORITY_IDLE;
case THREAD_PRIORITY_LOWEST:
return THREAD_PRIORITY_IDLE;
case THREAD_PRIORITY_BELOW_NORMAL:
return THREAD_PRIORITY_LOWEST;
case THREAD_PRIORITY_NORMAL:
return THREAD_PRIORITY_BELOW_NORMAL;
case THREAD_PRIORITY_ABOVE_NORMAL:
return THREAD_PRIORITY_NORMAL;
case THREAD_PRIORITY_HIGHEST:
return THREAD_PRIORITY_ABOVE_NORMAL;
case THREAD_PRIORITY_TIME_CRITICAL:
return THREAD_PRIORITY_HIGHEST;
default:
return priority; // unknown priority: should never get here
}
#elif defined (ACE_HAS_THREADS) && !defined(ACE_LACKS_SETSCHED)
// including STHREADS and PTHREADS
const int min = priority_min (policy, scope);
return priority > min ? priority - 1 : min;
#else
ACE_UNUSED_ARG (policy);
ACE_UNUSED_ARG (scope);
ACE_UNUSED_ARG (priority);
ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}
|