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

int priority_min (const Policy, const int scope=ACE_SCOPE_THREAD)
int priority_max (const Policy, const int scope=ACE_SCOPE_THREAD)
int next_priority (const Policy, const int priority, const int scope=ACE_SCOPE_THREAD)
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 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.

Referenced by ACE_Sched_Params(), ACE_Sched_Priority_Iterator::ACE_Sched_Priority_Iterator(), next_priority(), policy(), previous_priority(), priority_max(), and priority_min().


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.

References ACE_Sched_Priority, and Policy.

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.

References ACE_INLINE.

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 234 of file Sched_Params.cpp.

References ACE_NOTSUP_RETURN, Policy, and priority_max().

Referenced by ACE_Sched_Priority_Iterator::next().

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

ACE_INLINE void ACE_Sched_Params::policy const  Policy  ) 
 

Definition at line 40 of file Sched_Params.inl.

References Policy, and 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 279 of file Sched_Params.cpp.

References ACE_NOTSUP_RETURN, Policy, and priority_min().

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

ACE_INLINE void ACE_Sched_Params::priority const  ACE_Sched_Priority  ) 
 

Definition at line 52 of file Sched_Params.inl.

References ACE_Sched_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.

00047 {
00048   return this->priority_;
00049 }

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

Definition at line 134 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(), Policy, ACE_OS::priority_control(), and ACE_OS::strcpy().

Referenced by next_priority().

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

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(), Policy, 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   return 255;
00126 #else
00127   ACE_UNUSED_ARG (policy);
00128   ACE_UNUSED_ARG (scope);
00129   ACE_NOTSUP_RETURN (-1);
00130 #endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
00131 }

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 : 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.

ACE_Time_Value ACE_Sched_Params::quantum_ [private]
 

The 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]
 

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 Sun Jan 27 12:57:01 2008 for ACE by doxygen 1.3.6