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

Sched_Params.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Sched_Params.h
00006  *
00007  *  $Id: Sched_Params.h,v 1.1.1.3 2001/12/04 14:33:08 chad Exp $
00008  *
00009  *  @author David Levine <levine@cs.wustl.edu>
00010  *  @author Carlos O'Ryan <coryan@uci.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_SCHED_PARAMS_H
00015 #define ACE_SCHED_PARAMS_H
00016 #include "ace/pre.h"
00017 
00018 #include "ace/OS.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 /**
00025  * @class ACE_Sched_Params
00026  *
00027  * @brief Container for scheduling-related parameters.
00028  *
00029  * ACE_Sched_Params are passed via <ACE_OS::sched_params> to the
00030  * OS to specify scheduling parameters.  These parameters include
00031  * scheduling policy, such as FIFO (ACE_SCHED_FIFO), round-robin
00032  * (ACE_SCHED_RR), or an implementation-defined "OTHER"
00033  * (ACE_SCHED_OTHER), to which many systems default; priority;
00034  * and a time-slice quantum for round-robin scheduling.  A
00035  * "scope" parameter specifies whether the ACE_Sched_Params
00036  * applies to the current process, current lightweight process
00037  * (LWP) (on Solaris), or current thread.  Please see the "NOTE"
00038  * below about not all combinations of parameters being legal on
00039  * a particular platform.
00040  * For the case of thread priorities, it is intended that
00041  * <ACE_OS::sched_params> usually be called from <main> before
00042  * any threads have been spawned.  If spawned threads inherit
00043  * their parent's priority (I think that's the default behavior
00044  * for all of our platforms), then this sets the default base
00045  * priority.  Individual thread priorities can be adjusted as
00046  * usual using <ACE_OS::thr_prio> or via the ACE_Thread
00047  * interface.  See the parameter descriptions in the private:
00048  * section below.
00049  * NOTE: this class does not do any checking of parameters.  It
00050  * is just a container class.  If it is constructed with values
00051  * that are not supported on a platform, the call to
00052  * <ACE_OS::sched_params> will fail by returning -1 with EINVAL
00053  * (available through <ACE_OS::last_error>).
00054  */
00055 class ACE_Export ACE_Sched_Params
00056 {
00057   //    NOTE: Solaris 2.5.x threads in the RT class must set the
00058   //    priority of their LWP.  The only way to do that through ACE is
00059   //    for the RT thread itself to call <ACE_OS::thr_setprio> with
00060   //    it's own priority.
00061 
00062   //    OS Scheduling parameters are complicated and often confusing.
00063   //    Many thanks to Thilo Kielmann
00064   //    <kielmann@informatik.uni-siegen.de> for his careful review of
00065   //    this class design, thoughtful comments, and assistance with
00066   //    implementation, especially for PTHREADS platforms.  Please
00067   //    send any comments or corrections to the ACE developers.
00068 public:
00069   typedef int Policy;
00070 
00071   // = Initialization and termination methods.
00072   /// Constructor.
00073   ACE_Sched_Params (const Policy policy,
00074                     const ACE_Sched_Priority priority,
00075                     const int scope = ACE_SCOPE_THREAD,
00076                     const ACE_Time_Value &quantum = ACE_Time_Value::zero);
00077 
00078   /// Termination.
00079   ~ACE_Sched_Params (void);
00080 
00081   // = Get/Set methods:
00082 
00083   // = Get/Set policy
00084   Policy policy (void) const;
00085   void policy (const Policy);
00086 
00087   // = Get/Set priority.
00088   ACE_Sched_Priority priority (void) const;
00089   void priority (const ACE_Sched_Priority);
00090 
00091   // = Get/Set scope.
00092   int scope (void) const;
00093   void scope(const int);
00094 
00095   // = Get/Set quantum.
00096   const ACE_Time_Value &quantum (void) const;
00097   void quantum (const ACE_Time_Value &);
00098 
00099   // = Accessors for OS-specific priorities.
00100   // These return priority values for ACE_SCHED_OTHER if the Policy value
00101   // is invalid.
00102   static int priority_min (const Policy,
00103                            const int scope = ACE_SCOPE_THREAD);
00104   static int priority_max (const Policy,
00105                            const int scope = ACE_SCOPE_THREAD);
00106 
00107   /**
00108    * The next higher priority.  "Higher" refers to scheduling priority,
00109    * not to the priority value itself.  (On some platforms, higher scheduling
00110    * priority is indicated by a lower priority value.)  If "priority" is
00111    * already the highest priority (for the specified policy), then it is
00112    * returned.
00113    */
00114   static int next_priority (const Policy,
00115                             const int priority,
00116                             const int scope = ACE_SCOPE_THREAD);
00117 
00118   /**
00119    * The previous, lower priority.  "Lower" refers to scheduling priority,
00120    * not to the priority value itself.  (On some platforms, lower scheduling
00121    * priority is indicated by a higher priority value.)  If "priority" is
00122    * already the lowest priority (for the specified policy), then it is
00123    * returned.
00124    */
00125   static int previous_priority (const Policy,
00126                                 const int priority,
00127                                 const int scope = ACE_SCOPE_THREAD);
00128 
00129 private:
00130   /// Scheduling policy.
00131   Policy policy_;
00132 
00133   /// Default <priority_>: for setting the priority for the process, LWP,
00134   /// or thread, as indicated by the scope_ parameter.
00135   ACE_Sched_Priority priority_;
00136 
00137   /**
00138    * <scope_> must be one of the following:
00139    *   ACE_SCOPE_PROCESS:  sets the scheduling policy for the
00140    *     process, and the process priority.  On some platforms,
00141    *     such as Win32, the scheduling policy can _only_ be
00142    *     set at process scope.
00143    *   ACE_SCOPE_LWP: lightweight process scope, only used with
00144    *     Solaris threads.
00145    *   ACE_SCOPE_THREAD: sets the scheduling policy for the thread,
00146    *     if the OS supports it, such as with Posix threads, and the
00147    *     thread priority.
00148    * NOTE:  I don't think that these are the same as POSIX
00149    *        contention scope.  POSIX users who are interested in,
00150    *        and understand, contention scope will have to set it
00151    *        by using system calls outside of ACE.
00152    */
00153   int scope_;
00154 
00155   /**
00156    * The <quantum_> is for time slicing.  An ACE_Time_Value of 0 has
00157    * special significance: it means time-slicing is disabled; with
00158    * that, a thread that is running on a CPU will continue to run
00159    * until it blocks or is preempted.  Currently ignored if the OS
00160    * doesn't directly support time slicing, such as on VxWorks, or
00161    * setting the quantum (can that be done on Win32?).
00162    */
00163   ACE_Time_Value quantum_;
00164 };
00165 
00166 /**
00167  * @class ACE_Sched_Priority_Iterator
00168  *
00169  * @brief An iterator over the OS-defined scheduling priorities.
00170  *
00171  * The order of priorities (numeric value vs. importance) is OS
00172  * dependant, it can be the case that the priorities are not even
00173  * contigous.  This class permits iteration over priorities using
00174  * the iterator pattern.
00175  */
00176 class ACE_Export ACE_Sched_Priority_Iterator
00177 {
00178 public:
00179   /// Initialize the iterator, the arguments define the scheduling
00180   /// policy and scope for the priorities (see ACE_Sched_Param).
00181   ACE_Sched_Priority_Iterator (const ACE_Sched_Params::Policy &policy,
00182                                int scope = ACE_SCOPE_THREAD);
00183 
00184   /// Default dtor.
00185   ~ACE_Sched_Priority_Iterator (void);
00186 
00187   /// Check if there are more priorities.
00188   int more (void) const;
00189 
00190   /// Return the current priority.
00191   int priority (void) const;
00192 
00193   /// Move to the next priority.
00194   /// The iteration is from lowest to highest importance.
00195   void next (void);
00196 
00197   /// Accessor for the scheduling policy over which we are iterating.
00198   const ACE_Sched_Params::Policy &policy (void) const;
00199 
00200   /// Accessor for the scheduling
00201   int scope (void) const;
00202 
00203 private:
00204   /// The Scheduling policy (FIFO, RR, etc.) and scheduling scope
00205   /// (PROCESS, SYSTEM) we are iterating on.
00206   ACE_Sched_Params::Policy policy_;
00207   int scope_;
00208 
00209   /// The current priority.
00210   int priority_;
00211 
00212   /**
00213    * This is set to 1 when there are no more priorities. Cannot easily
00214    * compare against the highest priority on platforms were priorities
00215    * are non-contigous or descending.
00216    */
00217   int done_;
00218 };
00219 
00220 #if defined (__ACE_INLINE__)
00221 #include "ace/Sched_Params.i"
00222 #endif /* __ACE_INLINE__ */
00223 
00224 #include "ace/post.h"
00225 #endif /* ACE_SCHED_PARAMS_H */

Generated on Mon Jun 16 11:21:06 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002