Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 Methods

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

 ~ACE_Sched_Params (void)
 Termination. More...

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 Methods

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

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

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 55 of file Sched_Params.h.


Member Typedef Documentation

typedef int ACE_Sched_Params::Policy
 

Definition at line 69 of file Sched_Params.h.

Referenced by ACE_Sched_Priority_Iterator::ACE_Sched_Priority_Iterator, and policy.


Constructor & Destructor Documentation

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 21 of file Sched_Params.i.

References ACE_Sched_Priority.

00026   : policy_ (policy),
00027     priority_ (priority),
00028     scope_ (scope),
00029     quantum_ (quantum)
00030 {
00031 }

ACE_INLINE ACE_Sched_Params::~ACE_Sched_Params void   
 

Termination.

Definition at line 33 of file Sched_Params.i.

References ACE_INLINE.

00034 {
00035 }


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

References policy, priority, priority_max, and scope.

Referenced by ACE_Sched_Priority_Iterator::next.

00241 {
00242 #if defined (VXWORKS)
00243   return priority > priority_max (policy, scope)
00244            ?  priority - 1
00245            :  priority_max (policy, scope);
00246 #elif 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) && !defined(ACE_LACKS_SETSCHED)
00269   // including STHREADS, and PTHREADS
00270   const int max = priority_max (policy, scope);
00271   return priority < max  ?  priority + 1  :  max;
00272 #else
00273   ACE_UNUSED_ARG (policy);
00274   ACE_UNUSED_ARG (scope);
00275   ACE_UNUSED_ARG (priority);
00276   ACE_NOTSUP_RETURN (-1);
00277 #endif /* ACE_HAS_THREADS */
00278 }

ACE_INLINE void ACE_Sched_Params::policy const    Policy
 

Definition at line 44 of file Sched_Params.i.

References policy, Policy, and policy_.

00045 {
00046   this->policy_ = policy;
00047 }

ACE_INLINE ACE_Sched_Params::Policy ACE_Sched_Params::policy void    const
 

Definition at line 38 of file Sched_Params.i.

References policy_.

Referenced by ACE_OS::lwp_getparams, next_priority, policy, previous_priority, priority_max, priority_min, ACE_OS::sched_params, ACE_OS::set_scheduling_params, and ACE_OS::thr_setprio.

00039 {
00040   return this->policy_;
00041 }

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

References policy, priority, priority_min, and scope.

00284 {
00285 #if defined (VXWORKS)
00286   return priority < priority_min (policy, scope)
00287            ?  priority + 1
00288            :  priority_min (policy, scope);
00289 #elif defined (ACE_HAS_WTHREADS)
00290   ACE_UNUSED_ARG (policy);
00291   ACE_UNUSED_ARG (scope);
00292   switch (priority)
00293     {
00294       case THREAD_PRIORITY_IDLE:
00295         return THREAD_PRIORITY_IDLE;
00296       case THREAD_PRIORITY_LOWEST:
00297         return THREAD_PRIORITY_IDLE;
00298       case THREAD_PRIORITY_BELOW_NORMAL:
00299         return THREAD_PRIORITY_LOWEST;
00300       case THREAD_PRIORITY_NORMAL:
00301         return THREAD_PRIORITY_BELOW_NORMAL;
00302       case THREAD_PRIORITY_ABOVE_NORMAL:
00303         return THREAD_PRIORITY_NORMAL;
00304       case THREAD_PRIORITY_HIGHEST:
00305         return THREAD_PRIORITY_ABOVE_NORMAL;
00306       case THREAD_PRIORITY_TIME_CRITICAL:
00307         return THREAD_PRIORITY_HIGHEST;
00308       default:
00309         return priority;  // unknown priority:  should never get here
00310     }
00311 #elif defined (ACE_HAS_THREADS) && !defined(ACE_LACKS_SETSCHED)
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 56 of file Sched_Params.i.

References ACE_Sched_Priority, priority, and priority_.

00057 {
00058   this->priority_ = priority;
00059 }

ACE_INLINE ACE_Sched_Priority ACE_Sched_Params::priority void    const
 

Definition at line 50 of file Sched_Params.i.

References priority_.

Referenced by ACE_OS::lwp_getparams, next_priority, previous_priority, priority, ACE_OS::sched_params, ACE_OS::set_scheduling_params, and ACE_OS::thr_setprio.

00051 {
00052   return this->priority_;
00053 }

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

Definition at line 136 of file Sched_Params.cpp.

References ACE_SCHED_FIFO, ACE_SCHED_OTHER, ACE_SCHED_RR, ACE_SCOPE_LWP, ACE_SCOPE_PROCESS, ACE_SCOPE_THREAD, ACE_OS_String::memset, policy, ACE_OS::priority_control, scope, and ACE_OS_String::strcpy.

Referenced by next_priority.

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

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_SCHED_FIFO, ACE_SCHED_OTHER, ACE_SCHED_RR, ACE_SCOPE_LWP, ACE_SCOPE_PROCESS, ACE_SCOPE_THREAD, ACE_OS_String::memset, policy, ACE_OS::priority_control, scope, and ACE_OS_String::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) && !defined(ACE_LACKS_SETSCHED)
00087 
00088   switch (scope)
00089     {
00090     case ACE_SCOPE_THREAD:
00091       switch (policy)
00092         {
00093           case ACE_SCHED_FIFO:
00094             return ACE_THR_PRI_FIFO_MIN;
00095           case ACE_SCHED_RR:
00096             return ACE_THR_PRI_RR_MIN;
00097 #if !defined (CHORUS)   // SCHED_OTHRE and SCHED_RR have same value
00098            case ACE_SCHED_OTHER:
00099 #endif /* CHORUS */
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 #if !defined (CHORUS)   // SCHED_OTHRE and SCHED_RR have same value
00113            case ACE_SCHED_OTHER:
00114 #endif /* CHORUS */
00115           default:
00116             return ACE_PROC_PRI_OTHER_MIN;
00117         }
00118     }
00119 
00120 #elif defined (ACE_HAS_WTHREADS)
00121   ACE_UNUSED_ARG (policy);
00122   ACE_UNUSED_ARG (scope);
00123   return THREAD_PRIORITY_IDLE;
00124 #elif defined (VXWORKS)
00125   ACE_UNUSED_ARG (policy);
00126   ACE_UNUSED_ARG (scope);
00127   return 255;
00128 #else
00129   ACE_UNUSED_ARG (policy);
00130   ACE_UNUSED_ARG (scope);
00131   ACE_NOTSUP_RETURN (-1);
00132 #endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
00133 }

ACE_INLINE void ACE_Sched_Params::quantum const ACE_Time_Value  
 

Definition at line 80 of file Sched_Params.i.

References quantum_.

00081 {
00082   this->quantum_ = quant;
00083 }

ACE_INLINE const ACE_Time_Value & ACE_Sched_Params::quantum void    const
 

Definition at line 74 of file Sched_Params.i.

References quantum_.

Referenced by ACE_OS::lwp_getparams, ACE_OS::sched_params, and ACE_OS::set_scheduling_params.

00075 {
00076   return this->quantum_;
00077 }

ACE_INLINE void ACE_Sched_Params::scope const    int
 

Definition at line 68 of file Sched_Params.i.

References scope, and scope_.

00069 {
00070   this->scope_ = scope;
00071 }

ACE_INLINE int ACE_Sched_Params::scope void    const
 

Definition at line 62 of file Sched_Params.i.

References scope_.

Referenced by ACE_OS::lwp_getparams, ACE_OS::lwp_setparams, next_priority, previous_priority, priority_max, priority_min, ACE_OS::sched_params, scope, and ACE_OS::set_scheduling_params.

00063 {
00064   return this->scope_;
00065 }


Member Data Documentation

Policy ACE_Sched_Params::policy_ [private]
 

Scheduling policy.

Definition at line 131 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 135 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 163 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 153 of file Sched_Params.h.

Referenced by scope.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:55:31 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002