00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ace/Sched_Params.h"
00020
00021 #if !defined (__ACE_INLINE__)
00022 #include "ace/Sched_Params.inl"
00023 #endif
00024
00025 #if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
00026 # include "ace/OS_NS_string.h"
00027 # include <sys/priocntl.h>
00028 #endif
00029
00030 ACE_RCSID(ace, Sched_Params, "Sched_Params.cpp,v 4.37 2006/05/30 10:57:22 jwillemsen Exp")
00031
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033
00034 int
00035 ACE_Sched_Params::priority_min (const Policy policy,
00036 const int scope)
00037 {
00038 #if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
00039 ACE_UNUSED_ARG (scope);
00040
00041
00042
00043
00044
00045
00046
00047 if (scope == ACE_SCOPE_PROCESS || scope == ACE_SCOPE_LWP)
00048 {
00049 if (policy == ACE_SCHED_OTHER)
00050 {
00051
00052 pcinfo_t pcinfo;
00053
00054
00055 ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
00056 ACE_OS::strcpy (pcinfo.pc_clname, "TS");
00057
00058 if (ACE_OS::priority_control (P_ALL ,
00059 P_MYID ,
00060 PC_GETCID,
00061 (char *) &pcinfo) == -1)
00062
00063
00064 return -1;
00065
00066
00067
00068
00069
00070
00071 return -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri;
00072 }
00073 else
00074 return 0;
00075 }
00076 else
00077 {
00078
00079
00080
00081 switch (policy)
00082 {
00083 case ACE_SCHED_FIFO:
00084 return ACE_THR_PRI_FIFO_MIN;
00085 case ACE_SCHED_RR:
00086 return ACE_THR_PRI_RR_MIN;
00087 case ACE_SCHED_OTHER:
00088 default:
00089 return ACE_THR_PRI_OTHER_MIN;
00090 }
00091 }
00092 #elif defined(ACE_HAS_PTHREADS) && \
00093 (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00094 defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00095
00096 switch (scope)
00097 {
00098 case ACE_SCOPE_THREAD:
00099 switch (policy)
00100 {
00101 case ACE_SCHED_FIFO:
00102 return ACE_THR_PRI_FIFO_MIN;
00103 case ACE_SCHED_RR:
00104 return ACE_THR_PRI_RR_MIN;
00105 case ACE_SCHED_OTHER:
00106 default:
00107 return ACE_THR_PRI_OTHER_MIN;
00108 }
00109
00110 case ACE_SCOPE_PROCESS:
00111 default:
00112 switch (policy)
00113 {
00114 case ACE_SCHED_FIFO:
00115 return ACE_PROC_PRI_FIFO_MIN;
00116 case ACE_SCHED_RR:
00117 return ACE_PROC_PRI_RR_MIN;
00118 case ACE_SCHED_OTHER:
00119 default:
00120 return ACE_PROC_PRI_OTHER_MIN;
00121 }
00122 }
00123
00124 #elif defined (ACE_HAS_WTHREADS)
00125 ACE_UNUSED_ARG (policy);
00126 ACE_UNUSED_ARG (scope);
00127 return THREAD_PRIORITY_IDLE;
00128 #elif defined (ACE_VXWORKS)
00129 ACE_UNUSED_ARG (policy);
00130 ACE_UNUSED_ARG (scope);
00131 return 255;
00132 #else
00133 ACE_UNUSED_ARG (policy);
00134 ACE_UNUSED_ARG (scope);
00135 ACE_NOTSUP_RETURN (-1);
00136 #endif
00137 }
00138
00139 int
00140 ACE_Sched_Params::priority_max (const Policy policy,
00141 const int scope)
00142 {
00143 #if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
00144 ACE_UNUSED_ARG (scope);
00145
00146
00147
00148
00149 if (scope == ACE_SCOPE_PROCESS || scope == ACE_SCOPE_LWP)
00150 {
00151
00152
00153
00154
00155 pcinfo_t pcinfo;
00156
00157
00158 ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
00159 ACE_OS::strcpy (pcinfo.pc_clname,
00160 policy == ACE_SCHED_OTHER ? "TS" : "RT");
00161
00162 if (ACE_OS::priority_control (P_ALL ,
00163 P_MYID ,
00164 PC_GETCID,
00165 (char *) &pcinfo) == -1)
00166 return -1;
00167
00168
00169
00170
00171
00172 return policy == ACE_SCHED_OTHER
00173 ? ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri
00174 : ((rtinfo_t *) pcinfo.pc_clinfo)->rt_maxpri;
00175 }
00176 else
00177 {
00178
00179
00180
00181 switch (policy)
00182 {
00183 case ACE_SCHED_FIFO:
00184 return ACE_THR_PRI_FIFO_MAX;
00185 case ACE_SCHED_RR:
00186 return ACE_THR_PRI_RR_MAX;
00187 case ACE_SCHED_OTHER:
00188 default:
00189 return ACE_THR_PRI_OTHER_MAX;
00190 }
00191 }
00192 #elif defined(ACE_HAS_PTHREADS) && \
00193 (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00194 defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00195
00196 switch (scope)
00197 {
00198 case ACE_SCOPE_THREAD:
00199 switch (policy)
00200 {
00201 case ACE_SCHED_FIFO:
00202 return ACE_THR_PRI_FIFO_MAX;
00203 case ACE_SCHED_RR:
00204 return ACE_THR_PRI_RR_MAX;
00205 case ACE_SCHED_OTHER:
00206 default:
00207 return ACE_THR_PRI_OTHER_MAX;
00208 }
00209
00210 case ACE_SCOPE_PROCESS:
00211 default:
00212 switch (policy)
00213 {
00214 case ACE_SCHED_FIFO:
00215 return ACE_PROC_PRI_FIFO_MAX;
00216 case ACE_SCHED_RR:
00217 return ACE_PROC_PRI_RR_MAX;
00218 case ACE_SCHED_OTHER:
00219 default:
00220 return ACE_PROC_PRI_OTHER_MAX;
00221 }
00222 }
00223
00224 #elif defined (ACE_HAS_WTHREADS)
00225 ACE_UNUSED_ARG (policy);
00226 ACE_UNUSED_ARG (scope);
00227 return THREAD_PRIORITY_TIME_CRITICAL;
00228 #elif defined (ACE_VXWORKS)
00229 ACE_UNUSED_ARG (policy);
00230 ACE_UNUSED_ARG (scope);
00231 return 0;
00232 #else
00233 ACE_UNUSED_ARG (policy);
00234 ACE_UNUSED_ARG (scope);
00235 ACE_NOTSUP_RETURN (-1);
00236 #endif
00237 }
00238
00239 int
00240 ACE_Sched_Params::next_priority (const Policy policy,
00241 const int priority,
00242 const int scope)
00243 {
00244 #if defined (ACE_VXWORKS)
00245 return priority > priority_max (policy, scope)
00246 ? priority - 1
00247 : priority_max (policy, scope);
00248 #elif defined (ACE_HAS_WTHREADS)
00249 ACE_UNUSED_ARG (policy);
00250 ACE_UNUSED_ARG (scope);
00251 switch (priority)
00252 {
00253 case THREAD_PRIORITY_IDLE:
00254 return THREAD_PRIORITY_LOWEST;
00255 case THREAD_PRIORITY_LOWEST:
00256 return THREAD_PRIORITY_BELOW_NORMAL;
00257 case THREAD_PRIORITY_BELOW_NORMAL:
00258 return THREAD_PRIORITY_NORMAL;
00259 case THREAD_PRIORITY_NORMAL:
00260 return THREAD_PRIORITY_ABOVE_NORMAL;
00261 case THREAD_PRIORITY_ABOVE_NORMAL:
00262 return THREAD_PRIORITY_HIGHEST;
00263 case THREAD_PRIORITY_HIGHEST:
00264 return THREAD_PRIORITY_TIME_CRITICAL;
00265 case THREAD_PRIORITY_TIME_CRITICAL:
00266 return THREAD_PRIORITY_TIME_CRITICAL;
00267 default:
00268 return priority;
00269 }
00270 #elif defined(ACE_HAS_THREADS) && \
00271 (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00272 defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00273
00274 const int max = priority_max (policy, scope);
00275 return priority < max ? priority + 1 : max;
00276 #else
00277 ACE_UNUSED_ARG (policy);
00278 ACE_UNUSED_ARG (scope);
00279 ACE_UNUSED_ARG (priority);
00280 ACE_NOTSUP_RETURN (-1);
00281 #endif
00282 }
00283
00284 int
00285 ACE_Sched_Params::previous_priority (const Policy policy,
00286 const int priority,
00287 const int scope)
00288 {
00289 #if defined (ACE_VXWORKS)
00290 return priority < priority_min (policy, scope)
00291 ? priority + 1
00292 : priority_min (policy, scope);
00293 #elif defined (ACE_HAS_WTHREADS)
00294 ACE_UNUSED_ARG (policy);
00295 ACE_UNUSED_ARG (scope);
00296 switch (priority)
00297 {
00298 case THREAD_PRIORITY_IDLE:
00299 return THREAD_PRIORITY_IDLE;
00300 case THREAD_PRIORITY_LOWEST:
00301 return THREAD_PRIORITY_IDLE;
00302 case THREAD_PRIORITY_BELOW_NORMAL:
00303 return THREAD_PRIORITY_LOWEST;
00304 case THREAD_PRIORITY_NORMAL:
00305 return THREAD_PRIORITY_BELOW_NORMAL;
00306 case THREAD_PRIORITY_ABOVE_NORMAL:
00307 return THREAD_PRIORITY_NORMAL;
00308 case THREAD_PRIORITY_HIGHEST:
00309 return THREAD_PRIORITY_ABOVE_NORMAL;
00310 case THREAD_PRIORITY_TIME_CRITICAL:
00311 return THREAD_PRIORITY_HIGHEST;
00312 default:
00313 return priority;
00314 }
00315 #elif defined(ACE_HAS_THREADS) && \
00316 (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00317 defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00318
00319 const int min = priority_min (policy, scope);
00320
00321 return priority > min ? priority - 1 : min;
00322 #else
00323 ACE_UNUSED_ARG (policy);
00324 ACE_UNUSED_ARG (scope);
00325 ACE_UNUSED_ARG (priority);
00326 ACE_NOTSUP_RETURN (-1);
00327 #endif
00328 }
00329
00330 ACE_END_VERSIONED_NAMESPACE_DECL