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

Sched_Params.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: Sched_Params.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $
00003 
00004 // ============================================================================
00005 //
00006 // = LIBRARY
00007 //    ACE
00008 //
00009 // = FILENAME
00010 //    Sched_Params.cpp
00011 //
00012 // = CREATION DATE
00013 //    28 January 1997
00014 //
00015 // = AUTHOR
00016 //    David Levine
00017 //
00018 // ============================================================================
00019 
00020 #include "ace/Sched_Params.h"
00021 
00022 #if !defined (__ACE_INLINE__)
00023 #include "ace/Sched_Params.i"
00024 #endif /* __ACE_INLINE__ */
00025 
00026 ACE_RCSID(ace, Sched_Params, "$Id: Sched_Params.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $")
00027 
00028 int
00029 ACE_Sched_Params::priority_min (const Policy policy,
00030                                 const int scope)
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 }
00134 
00135 int
00136 ACE_Sched_Params::priority_max (const Policy policy,
00137                                 const int scope)
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 }
00236 
00237 int
00238 ACE_Sched_Params::next_priority (const Policy policy,
00239                                  const int priority,
00240                                  const int scope)
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 }
00279 
00280 int
00281 ACE_Sched_Params::previous_priority (const Policy policy,
00282                                      const int priority,
00283                                      const int 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 }

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