Sched_Params.h

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

Generated on Thu Nov 9 09:42:02 2006 for ACE by doxygen 1.3.6