ACE_Sched_Params Class Reference

Container for scheduling-related parameters. More...

#include <Sched_Params.h>

Collaboration diagram for ACE_Sched_Params:

Collaboration graph
[legend]
List of all members.

Public Types

typedef int Policy

Public Member Functions

 ACE_Sched_Params (const Policy policy, const ACE_Sched_Priority priority, const int scope=ACE_SCOPE_THREAD, const ACE_Time_Value &quantum=ACE_Time_Value::zero)
 Constructor.
 ~ACE_Sched_Params (void)
 Termination.
Policy policy (void) const
void policy (const Policy)
ACE_Sched_Priority priority (void) const
void priority (const ACE_Sched_Priority)
int scope (void) const
void scope (const int)
const ACE_Time_Valuequantum (void) const
void quantum (const ACE_Time_Value &)

Static Public Member Functions

static int priority_min (const Policy, const int scope=ACE_SCOPE_THREAD)
static int priority_max (const Policy, const int scope=ACE_SCOPE_THREAD)
static int next_priority (const Policy, const int priority, const int scope=ACE_SCOPE_THREAD)
static int previous_priority (const Policy, const int priority, const int scope=ACE_SCOPE_THREAD)

Private Attributes

Policy policy_
 Scheduling policy.
ACE_Sched_Priority priority_
int scope_
ACE_Time_Value quantum_

Detailed Description

Container for scheduling-related parameters.

ACE_Sched_Params are passed via <ACE_OS::sched_params> to the OS to specify scheduling parameters. These parameters include scheduling policy, such as FIFO (ACE_SCHED_FIFO), round-robin (ACE_SCHED_RR), or an implementation-defined "OTHER" (ACE_SCHED_OTHER), to which many systems default; priority; and a time-slice quantum for round-robin scheduling. A "scope" parameter specifies whether the ACE_Sched_Params applies to the current process, current lightweight process (LWP) (on Solaris), or current thread. Please see the "NOTE" below about not all combinations of parameters being legal on a particular platform. For the case of thread priorities, it is intended that <ACE_OS::sched_params> usually be called from <main> before any threads have been spawned. If spawned threads inherit their parent's priority (I think that's the default behavior for all of our platforms), then this sets the default base priority. Individual thread priorities can be adjusted as usual using <ACE_OS::thr_prio> or via the ACE_Thread interface. See the parameter descriptions in the private: section below.

Note:
This class does not do any checking of parameters. It is just a container class. If it is constructed with values that are not supported on a platform, the call to <ACE_OS::sched_params> will fail by returning -1 with EINVAL (available through <ACE_OS::last_error>).

Definition at line 60 of file Sched_Params.h.


Member Typedef Documentation

typedef int ACE_Sched_Params::Policy

Definition at line 74 of file Sched_Params.h.


Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_Sched_Params::ACE_Sched_Params ( const Policy  policy,
const ACE_Sched_Priority  priority,
const int  scope = ACE_SCOPE_THREAD,
const ACE_Time_Value quantum = ACE_Time_Value::zero 
)

Constructor.

Definition at line 17 of file Sched_Params.inl.

00022   : policy_ (policy),
00023     priority_ (priority),
00024     scope_ (scope),
00025     quantum_ (quantum)
00026 {
00027 }

ACE_INLINE ACE_Sched_Params::~ACE_Sched_Params ( void   ) 

Termination.

Definition at line 29 of file Sched_Params.inl.

00030 {
00031 }


Member Function Documentation

int ACE_Sched_Params::next_priority ( const   Policy,
const int  priority,
const int  scope = ACE_SCOPE_THREAD 
) [static]

The next higher priority. "Higher" refers to scheduling priority, not to the priority value itself. (On some platforms, higher scheduling priority is indicated by a lower priority value.) If "priority" is already the highest priority (for the specified policy), then it is returned.

Definition at line 242 of file Sched_Params.cpp.

References ACE_NOTSUP_RETURN, and priority_max().

Referenced by ACE_Sched_Priority_Iterator::next().

00245 {
00246 #if defined (ACE_HAS_WTHREADS)
00247   ACE_UNUSED_ARG (policy);
00248   ACE_UNUSED_ARG (scope);
00249   switch (priority)
00250     {
00251       case THREAD_PRIORITY_IDLE:
00252         return THREAD_PRIORITY_LOWEST;
00253       case THREAD_PRIORITY_LOWEST:
00254         return THREAD_PRIORITY_BELOW_NORMAL;
00255       case THREAD_PRIORITY_BELOW_NORMAL:
00256         return THREAD_PRIORITY_NORMAL;
00257       case THREAD_PRIORITY_NORMAL:
00258         return THREAD_PRIORITY_ABOVE_NORMAL;
00259       case THREAD_PRIORITY_ABOVE_NORMAL:
00260         return THREAD_PRIORITY_HIGHEST;
00261       case THREAD_PRIORITY_HIGHEST:
00262         return THREAD_PRIORITY_TIME_CRITICAL;
00263       case THREAD_PRIORITY_TIME_CRITICAL:
00264         return THREAD_PRIORITY_TIME_CRITICAL;
00265       default:
00266         return priority;  // unknown priority:  should never get here
00267     }
00268 #elif defined(ACE_HAS_THREADS) && \
00269       (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00270        defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00271   // including STHREADS, and PTHREADS
00272   int const max = priority_max (policy, scope);
00273   return priority < max  ?  priority + 1  :  max;
00274 #elif defined (ACE_VXWORKS)
00275   return priority > priority_max (policy, scope)
00276            ?  priority - 1
00277            :  priority_max (policy, scope);
00278 #else
00279   ACE_UNUSED_ARG (policy);
00280   ACE_UNUSED_ARG (scope);
00281   ACE_UNUSED_ARG (priority);
00282   ACE_NOTSUP_RETURN (-1);
00283 #endif /* ACE_HAS_THREADS */
00284 }

ACE_INLINE void ACE_Sched_Params::policy ( const   Policy  ) 

Definition at line 40 of file Sched_Params.inl.

References policy_.

00041 {
00042   this->policy_ = policy;
00043 }

ACE_INLINE ACE_Sched_Params::Policy ACE_Sched_Params::policy ( void   )  const

Definition at line 34 of file Sched_Params.inl.

References policy_.

00035 {
00036   return this->policy_;
00037 }

int ACE_Sched_Params::previous_priority ( const   Policy,
const int  priority,
const int  scope = ACE_SCOPE_THREAD 
) [static]

The previous, lower priority. "Lower" refers to scheduling priority, not to the priority value itself. (On some platforms, lower scheduling priority is indicated by a higher priority value.) If "priority" is already the lowest priority (for the specified policy), then it is returned.

Definition at line 287 of file Sched_Params.cpp.

References ACE_NOTSUP_RETURN, and priority_min().

00290 {
00291 #if defined (ACE_HAS_WTHREADS)
00292   ACE_UNUSED_ARG (policy);
00293   ACE_UNUSED_ARG (scope);
00294   switch (priority)
00295     {
00296       case THREAD_PRIORITY_IDLE:
00297         return THREAD_PRIORITY_IDLE;
00298       case THREAD_PRIORITY_LOWEST:
00299         return THREAD_PRIORITY_IDLE;
00300       case THREAD_PRIORITY_BELOW_NORMAL:
00301         return THREAD_PRIORITY_LOWEST;
00302       case THREAD_PRIORITY_NORMAL:
00303         return THREAD_PRIORITY_BELOW_NORMAL;
00304       case THREAD_PRIORITY_ABOVE_NORMAL:
00305         return THREAD_PRIORITY_NORMAL;
00306       case THREAD_PRIORITY_HIGHEST:
00307         return THREAD_PRIORITY_ABOVE_NORMAL;
00308       case THREAD_PRIORITY_TIME_CRITICAL:
00309         return THREAD_PRIORITY_HIGHEST;
00310       default:
00311         return priority;  // unknown priority:  should never get here
00312     }
00313 #elif defined(ACE_HAS_THREADS) && \
00314       (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00315        defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00316   // including STHREADS and PTHREADS
00317   int const min = priority_min (policy, scope);
00318 
00319   return priority > min ? priority - 1 : min;
00320 #elif defined (ACE_VXWORKS)
00321   return priority < priority_min (policy, scope)
00322            ?  priority + 1
00323            :  priority_min (policy, scope);
00324 #else
00325   ACE_UNUSED_ARG (policy);
00326   ACE_UNUSED_ARG (scope);
00327   ACE_UNUSED_ARG (priority);
00328   ACE_NOTSUP_RETURN (-1);
00329 #endif /* ACE_HAS_THREADS */
00330 }

ACE_INLINE void ACE_Sched_Params::priority ( const   ACE_Sched_Priority  ) 

Definition at line 52 of file Sched_Params.inl.

References priority_.

00053 {
00054   this->priority_ = priority;
00055 }

ACE_INLINE ACE_Sched_Priority ACE_Sched_Params::priority ( void   )  const

Definition at line 46 of file Sched_Params.inl.

References priority_.

00047 {
00048   return this->priority_;
00049 }

int ACE_Sched_Params::priority_max ( const   Policy,
const int  scope = ACE_SCOPE_THREAD 
) [static]

Definition at line 138 of file Sched_Params.cpp.

References ACE_NOTSUP_RETURN, ACE_SCHED_FIFO, ACE_SCHED_OTHER, ACE_SCHED_RR, ACE_SCOPE_LWP, ACE_SCOPE_PROCESS, ACE_SCOPE_THREAD, ACE_OS::memset(), ACE_OS::priority_control(), and ACE_OS::strcpy().

Referenced by next_priority().

00140 {
00141 #if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
00142   ACE_UNUSED_ARG (scope);
00143 
00144   // Call ACE_OS::priority_control only for processes (lightweight
00145   // or otherwise). Calling ACE_OS::priority_control for thread
00146   // priorities gives incorrect results.
00147   if (scope == ACE_SCOPE_PROCESS || scope == ACE_SCOPE_LWP)
00148     {
00149       // Assume that ACE_SCHED_OTHER indicates TS class, and that other
00150       // policies indicate RT class.
00151 
00152       // Get the priority class ID and attributes.
00153       pcinfo_t pcinfo;
00154       // The following is just to avoid Purify warnings about unitialized
00155       // memory reads.
00156       ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
00157       ACE_OS::strcpy (pcinfo.pc_clname,
00158                       policy == ACE_SCHED_OTHER  ?  "TS"  :  "RT");
00159 
00160       if (ACE_OS::priority_control (P_ALL /* ignored */,
00161                                     P_MYID /* ignored */,
00162                                     PC_GETCID,
00163                                     (char *) &pcinfo) == -1)
00164         return -1;
00165 
00166       // OK, now we've got the class ID in pcinfo.pc_cid.  In addition,
00167       // the maximum configured real-time priority is in ((rtinfo_t *)
00168       // pcinfo.pc_clinfo)->rt_maxpri, or similarly for the TS class.
00169 
00170       return policy == ACE_SCHED_OTHER
00171         ? ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri
00172         : ((rtinfo_t *) pcinfo.pc_clinfo)->rt_maxpri;
00173     }
00174   else
00175     {
00176       // Here we handle the case for ACE_SCOPE_THREAD. Calling
00177       // ACE_OS::priority_control for thread scope gives incorrect
00178       // results.
00179       switch (policy)
00180         {
00181         case ACE_SCHED_FIFO:
00182           return ACE_THR_PRI_FIFO_MAX;
00183         case ACE_SCHED_RR:
00184           return ACE_THR_PRI_RR_MAX;
00185         case ACE_SCHED_OTHER:
00186         default:
00187           return ACE_THR_PRI_OTHER_MAX;
00188         }
00189     }
00190 #elif defined(ACE_HAS_PTHREADS) && \
00191       (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00192        defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00193 
00194   switch (scope)
00195     {
00196     case ACE_SCOPE_THREAD:
00197       switch (policy)
00198         {
00199           case ACE_SCHED_FIFO:
00200             return ACE_THR_PRI_FIFO_MAX;
00201           case ACE_SCHED_RR:
00202             return ACE_THR_PRI_RR_MAX;
00203           case ACE_SCHED_OTHER:
00204           default:
00205             return ACE_THR_PRI_OTHER_MAX;
00206         }
00207 
00208     case ACE_SCOPE_PROCESS:
00209     default:
00210       switch (policy)
00211         {
00212           case ACE_SCHED_FIFO:
00213             return ACE_PROC_PRI_FIFO_MAX;
00214           case ACE_SCHED_RR:
00215             return ACE_PROC_PRI_RR_MAX;
00216           case ACE_SCHED_OTHER:
00217           default:
00218             return ACE_PROC_PRI_OTHER_MAX;
00219         }
00220     }
00221 
00222 #elif defined (ACE_HAS_WTHREADS)
00223   ACE_UNUSED_ARG (policy);
00224   ACE_UNUSED_ARG (scope);
00225   return THREAD_PRIORITY_TIME_CRITICAL;
00226 #elif defined (ACE_VXWORKS)
00227   ACE_UNUSED_ARG (policy);
00228   ACE_UNUSED_ARG (scope);
00229 # if defined (VX_TASK_PRIORITY_MIN)
00230   return VX_TASK_PRIORITY_MIN;
00231 # else
00232   return 0;
00233 # endif
00234 #else
00235   ACE_UNUSED_ARG (policy);
00236   ACE_UNUSED_ARG (scope);
00237   ACE_NOTSUP_RETURN (-1);
00238 #endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
00239 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL int ACE_Sched_Params::priority_min ( const   Policy,
const int  scope = ACE_SCOPE_THREAD 
) [static]

Definition at line 29 of file Sched_Params.cpp.

References ACE_NOTSUP_RETURN, ACE_SCHED_FIFO, ACE_SCHED_OTHER, ACE_SCHED_RR, ACE_SCOPE_LWP, ACE_SCOPE_PROCESS, ACE_SCOPE_THREAD, ACE_OS::memset(), ACE_OS::priority_control(), and ACE_OS::strcpy().

Referenced by ACE_Sched_Priority_Iterator::ACE_Sched_Priority_Iterator(), and previous_priority().

00031 {
00032 #if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
00033   ACE_UNUSED_ARG (scope);
00034 
00035   // Assume that ACE_SCHED_OTHER indicates TS class, and that other
00036   // policies indicate RT class.
00037 
00038   // Call ACE_OS::priority_control only for processes (lightweight
00039   // or otherwise). Calling ACE_OS::priority_control for thread
00040   // priorities gives incorrect results.
00041   if (scope == ACE_SCOPE_PROCESS || scope == ACE_SCOPE_LWP)
00042     {
00043       if (policy == ACE_SCHED_OTHER)
00044         {
00045           // Get the priority class ID and attributes.
00046           pcinfo_t pcinfo;
00047           // The following is just to avoid Purify warnings about unitialized
00048           // memory reads.
00049           ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
00050           ACE_OS::strcpy (pcinfo.pc_clname, "TS");
00051 
00052           if (ACE_OS::priority_control (P_ALL /* ignored */,
00053                                         P_MYID /* ignored */,
00054                                         PC_GETCID,
00055                                         (char *) &pcinfo) == -1)
00056             // Just hope that priority range wasn't configured from -1
00057             // .. 1
00058             return -1;
00059 
00060           // OK, now we've got the class ID in pcinfo.pc_cid.  In
00061           // addition, the maximum configured time-share priority is in
00062           // ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri.  The minimum
00063           // priority is just the negative of that.
00064 
00065           return -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri;
00066         }
00067       else
00068         return 0;
00069     }
00070   else
00071     {
00072       // Here we handle the case for ACE_SCOPE_THREAD. Calling
00073       // ACE_OS::priority_control for thread scope gives incorrect
00074       // results.
00075       switch (policy)
00076         {
00077         case ACE_SCHED_FIFO:
00078           return ACE_THR_PRI_FIFO_MIN;
00079         case ACE_SCHED_RR:
00080           return ACE_THR_PRI_RR_MIN;
00081         case ACE_SCHED_OTHER:
00082         default:
00083           return ACE_THR_PRI_OTHER_MIN;
00084         }
00085     }
00086 #elif defined(ACE_HAS_PTHREADS) && \
00087       (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
00088        defined (ACE_HAS_PTHREAD_SCHEDPARAM))
00089 
00090   switch (scope)
00091     {
00092     case ACE_SCOPE_THREAD:
00093       switch (policy)
00094         {
00095           case ACE_SCHED_FIFO:
00096             return ACE_THR_PRI_FIFO_MIN;
00097           case ACE_SCHED_RR:
00098             return ACE_THR_PRI_RR_MIN;
00099           case ACE_SCHED_OTHER:
00100           default:
00101             return ACE_THR_PRI_OTHER_MIN;
00102         }
00103 
00104     case ACE_SCOPE_PROCESS:
00105     default:
00106       switch (policy)
00107         {
00108           case ACE_SCHED_FIFO:
00109             return ACE_PROC_PRI_FIFO_MIN;
00110           case ACE_SCHED_RR:
00111             return ACE_PROC_PRI_RR_MIN;
00112           case ACE_SCHED_OTHER:
00113           default:
00114             return ACE_PROC_PRI_OTHER_MIN;
00115         }
00116     }
00117 
00118 #elif defined (ACE_HAS_WTHREADS)
00119   ACE_UNUSED_ARG (policy);
00120   ACE_UNUSED_ARG (scope);
00121   return THREAD_PRIORITY_IDLE;
00122 #elif defined (ACE_VXWORKS)
00123   ACE_UNUSED_ARG (policy);
00124   ACE_UNUSED_ARG (scope);
00125 # if defined (VX_TASK_PRIORITY_MAX)
00126   return VX_TASK_PRIORITY_MAX;
00127 # else
00128   return 255;
00129 # endif
00130 #else
00131   ACE_UNUSED_ARG (policy);
00132   ACE_UNUSED_ARG (scope);
00133   ACE_NOTSUP_RETURN (-1);
00134 #endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
00135 }

ACE_INLINE void ACE_Sched_Params::quantum ( const ACE_Time_Value  ) 

Definition at line 76 of file Sched_Params.inl.

References quantum_.

00077 {
00078   this->quantum_ = quant;
00079 }

ACE_INLINE const ACE_Time_Value & ACE_Sched_Params::quantum ( void   )  const

Definition at line 70 of file Sched_Params.inl.

References quantum_.

00071 {
00072   return this->quantum_;
00073 }

ACE_INLINE void ACE_Sched_Params::scope ( const   int  ) 

Definition at line 64 of file Sched_Params.inl.

References scope_.

00065 {
00066   this->scope_ = scope;
00067 }

ACE_INLINE int ACE_Sched_Params::scope ( void   )  const

Definition at line 58 of file Sched_Params.inl.

References scope_.

Referenced by ACE_OS::lwp_setparams().

00059 {
00060   return this->scope_;
00061 }


Member Data Documentation

Policy ACE_Sched_Params::policy_ [private]

Scheduling policy.

Definition at line 136 of file Sched_Params.h.

Referenced by policy().

ACE_Sched_Priority ACE_Sched_Params::priority_ [private]

Default <priority_>: for setting the priority for the process, LWP, or thread, as indicated by the scope_ parameter.

Definition at line 140 of file Sched_Params.h.

Referenced by priority().

ACE_Time_Value ACE_Sched_Params::quantum_ [private]

The <quantum_> is for time slicing. An ACE_Time_Value of 0 has special significance: it means time-slicing is disabled; with that, a thread that is running on a CPU will continue to run until it blocks or is preempted. Currently ignored if the OS doesn't directly support time slicing, such as on VxWorks, or setting the quantum (can that be done on Win32?).

Definition at line 168 of file Sched_Params.h.

Referenced by quantum().

int ACE_Sched_Params::scope_ [private]

<scope_> must be one of the following: ACE_SCOPE_PROCESS: sets the scheduling policy for the process, and the process priority. On some platforms, such as Win32, the scheduling policy can _only_ be set at process scope. ACE_SCOPE_LWP: lightweight process scope, only used with Solaris threads. ACE_SCOPE_THREAD: sets the scheduling policy for the thread, if the OS supports it, such as with Posix threads, and the thread priority. NOTE: I don't think that these are the same as POSIX contention scope. POSIX users who are interested in, and understand, contention scope will have to set it by using system calls outside of ACE.

Definition at line 158 of file Sched_Params.h.

Referenced by scope().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:32 2010 for ACE by  doxygen 1.4.7