Public Types | Public Member Functions | Static Public Member Functions | Private Attributes

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

static int priority_min (const Policy, const int scope=ACE_SCOPE_THREAD)
static int priority_max (const Policy, const int scope=ACE_SCOPE_THREAD)
static int next_priority (const Policy, const int priority, const int scope=ACE_SCOPE_THREAD)
static 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 <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 60 of file Sched_Params.h.


Member Typedef Documentation

Definition at line 74 of file Sched_Params.h.


Constructor & Destructor Documentation

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.

  : policy_ (policy),
    priority_ (priority),
    scope_ (scope),
    quantum_ (quantum)
{
}

ACE_Sched_Params::~ACE_Sched_Params ( void   ) 

Termination.

Definition at line 29 of file Sched_Params.inl.

{
}


Member Function Documentation

int ACE_Sched_Params::next_priority ( const Policy  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 250 of file Sched_Params.cpp.

{
#if defined (ACE_HAS_WTHREADS) && !defined (ACE_HAS_WINCE)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  switch (priority)
    {
      case THREAD_PRIORITY_IDLE:
        return THREAD_PRIORITY_LOWEST;
      case THREAD_PRIORITY_LOWEST:
        return THREAD_PRIORITY_BELOW_NORMAL;
      case THREAD_PRIORITY_BELOW_NORMAL:
        return THREAD_PRIORITY_NORMAL;
      case THREAD_PRIORITY_NORMAL:
        return THREAD_PRIORITY_ABOVE_NORMAL;
      case THREAD_PRIORITY_ABOVE_NORMAL:
        return THREAD_PRIORITY_HIGHEST;
      case THREAD_PRIORITY_HIGHEST:
        return THREAD_PRIORITY_TIME_CRITICAL;
      case THREAD_PRIORITY_TIME_CRITICAL:
        return THREAD_PRIORITY_TIME_CRITICAL;
      default:
        return priority;  // unknown priority:  should never get here
    }
#elif defined(ACE_HAS_THREADS) && \
      (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
       defined (ACE_HAS_PTHREAD_SCHEDPARAM))
  // including STHREADS, and PTHREADS
  int const max = priority_max (policy, scope);
  return priority < max  ?  priority + 1  :  max;
#elif defined (ACE_VXWORKS) || defined (ACE_HAS_WINCE)
  int const max = priority_max (policy, scope);
  return priority > max ?  priority - 1 :  max;
#else
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  ACE_UNUSED_ARG (priority);
  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}

ACE_Sched_Params::Policy ACE_Sched_Params::policy ( void   )  const

Definition at line 34 of file Sched_Params.inl.

{
  return this->policy_;
}

void ACE_Sched_Params::policy ( const  Policy  ) 

Definition at line 40 of file Sched_Params.inl.

{
  this->policy_ = policy;
}

int ACE_Sched_Params::previous_priority ( const Policy  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 294 of file Sched_Params.cpp.

{
#if defined (ACE_HAS_WTHREADS) && !defined (ACE_HAS_WINCE)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  switch (priority)
    {
      case THREAD_PRIORITY_IDLE:
        return THREAD_PRIORITY_IDLE;
      case THREAD_PRIORITY_LOWEST:
        return THREAD_PRIORITY_IDLE;
      case THREAD_PRIORITY_BELOW_NORMAL:
        return THREAD_PRIORITY_LOWEST;
      case THREAD_PRIORITY_NORMAL:
        return THREAD_PRIORITY_BELOW_NORMAL;
      case THREAD_PRIORITY_ABOVE_NORMAL:
        return THREAD_PRIORITY_NORMAL;
      case THREAD_PRIORITY_HIGHEST:
        return THREAD_PRIORITY_ABOVE_NORMAL;
      case THREAD_PRIORITY_TIME_CRITICAL:
        return THREAD_PRIORITY_HIGHEST;
      default:
        return priority;  // unknown priority:  should never get here
    }
#elif defined(ACE_HAS_THREADS) && \
      (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
       defined (ACE_HAS_PTHREAD_SCHEDPARAM))
  // including STHREADS and PTHREADS
  int const min = priority_min (policy, scope);
  return priority > min ? priority - 1 : min;
#elif defined (ACE_VXWORKS) || defined (ACE_HAS_WINCE)
  int const min = priority_min (policy, scope);
  return priority < min ?  priority + 1 :  min;
#else
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  ACE_UNUSED_ARG (priority);
  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_THREADS */
}

void ACE_Sched_Params::priority ( const ACE_Sched_Priority  priority  ) 

Definition at line 52 of file Sched_Params.inl.

{
  this->priority_ = priority;
}

ACE_Sched_Priority ACE_Sched_Params::priority ( void   )  const

Definition at line 46 of file Sched_Params.inl.

{
  return this->priority_;
}

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

Definition at line 142 of file Sched_Params.cpp.

{
#if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
  ACE_UNUSED_ARG (scope);

  // Call ACE_OS::priority_control only for processes (lightweight
  // or otherwise). Calling ACE_OS::priority_control for thread
  // priorities gives incorrect results.
  if (scope == ACE_SCOPE_PROCESS || scope == ACE_SCOPE_LWP)
    {
      // Assume that ACE_SCHED_OTHER indicates TS class, and that other
      // policies indicate RT class.

      // Get the priority class ID and attributes.
      pcinfo_t pcinfo;
      // The following is just to avoid Purify warnings about unitialized
      // memory reads.
      ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
      ACE_OS::strcpy (pcinfo.pc_clname,
                      policy == ACE_SCHED_OTHER  ?  "TS"  :  "RT");

      if (ACE_OS::priority_control (P_ALL /* ignored */,
                                    P_MYID /* ignored */,
                                    PC_GETCID,
                                    (char *) &pcinfo) == -1)
        return -1;

      // OK, now we've got the class ID in pcinfo.pc_cid.  In addition,
      // the maximum configured real-time priority is in ((rtinfo_t *)
      // pcinfo.pc_clinfo)->rt_maxpri, or similarly for the TS class.

      return policy == ACE_SCHED_OTHER
        ? ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri
        : ((rtinfo_t *) pcinfo.pc_clinfo)->rt_maxpri;
    }
  else
    {
      // Here we handle the case for ACE_SCOPE_THREAD. Calling
      // ACE_OS::priority_control for thread scope gives incorrect
      // results.
      switch (policy)
        {
        case ACE_SCHED_FIFO:
          return ACE_THR_PRI_FIFO_MAX;
        case ACE_SCHED_RR:
          return ACE_THR_PRI_RR_MAX;
        case ACE_SCHED_OTHER:
        default:
          return ACE_THR_PRI_OTHER_MAX;
        }
    }
#elif defined(ACE_HAS_PTHREADS) && \
      (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
       defined (ACE_HAS_PTHREAD_SCHEDPARAM))

  switch (scope)
    {
    case ACE_SCOPE_THREAD:
      switch (policy)
        {
          case ACE_SCHED_FIFO:
            return ACE_THR_PRI_FIFO_MAX;
          case ACE_SCHED_RR:
            return ACE_THR_PRI_RR_MAX;
          case ACE_SCHED_OTHER:
          default:
            return ACE_THR_PRI_OTHER_MAX;
        }

    case ACE_SCOPE_PROCESS:
    default:
      switch (policy)
        {
          case ACE_SCHED_FIFO:
            return ACE_PROC_PRI_FIFO_MAX;
          case ACE_SCHED_RR:
            return ACE_PROC_PRI_RR_MAX;
          case ACE_SCHED_OTHER:
          default:
            return ACE_PROC_PRI_OTHER_MAX;
        }
    }

#elif defined (ACE_HAS_WTHREADS) && !defined (ACE_HAS_WINCE)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  return THREAD_PRIORITY_TIME_CRITICAL;
#elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WINCE)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  return 0;
#elif defined (ACE_VXWORKS)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
# if defined (VX_TASK_PRIORITY_MIN)
  return VX_TASK_PRIORITY_MIN;
# else
  return 0;
# endif
#else
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
}

int ACE_Sched_Params::priority_min ( const Policy  policy,
const int  scope = ACE_SCOPE_THREAD 
) [static]

Definition at line 29 of file Sched_Params.cpp.

{
#if defined (ACE_HAS_PRIOCNTL) && defined (ACE_HAS_STHREADS)
  ACE_UNUSED_ARG (scope);

  // Assume that ACE_SCHED_OTHER indicates TS class, and that other
  // policies indicate RT class.

  // Call ACE_OS::priority_control only for processes (lightweight
  // or otherwise). Calling ACE_OS::priority_control for thread
  // priorities gives incorrect results.
  if (scope == ACE_SCOPE_PROCESS || scope == ACE_SCOPE_LWP)
    {
      if (policy == ACE_SCHED_OTHER)
        {
          // Get the priority class ID and attributes.
          pcinfo_t pcinfo;
          // The following is just to avoid Purify warnings about unitialized
          // memory reads.
          ACE_OS::memset (&pcinfo, 0, sizeof pcinfo);
          ACE_OS::strcpy (pcinfo.pc_clname, "TS");

          if (ACE_OS::priority_control (P_ALL /* ignored */,
                                        P_MYID /* ignored */,
                                        PC_GETCID,
                                        (char *) &pcinfo) == -1)
            // Just hope that priority range wasn't configured from -1
            // .. 1
            return -1;

          // OK, now we've got the class ID in pcinfo.pc_cid.  In
          // addition, the maximum configured time-share priority is in
          // ((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri.  The minimum
          // priority is just the negative of that.

          return -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri;
        }
      else
        return 0;
    }
  else
    {
      // Here we handle the case for ACE_SCOPE_THREAD. Calling
      // ACE_OS::priority_control for thread scope gives incorrect
      // results.
      switch (policy)
        {
        case ACE_SCHED_FIFO:
          return ACE_THR_PRI_FIFO_MIN;
        case ACE_SCHED_RR:
          return ACE_THR_PRI_RR_MIN;
        case ACE_SCHED_OTHER:
        default:
          return ACE_THR_PRI_OTHER_MIN;
        }
    }
#elif defined(ACE_HAS_PTHREADS) && \
      (!defined(ACE_LACKS_SETSCHED) || defined (ACE_TANDEM_T1248_PTHREADS) || \
       defined (ACE_HAS_PTHREAD_SCHEDPARAM))

  switch (scope)
    {
    case ACE_SCOPE_THREAD:
      switch (policy)
        {
          case ACE_SCHED_FIFO:
            return ACE_THR_PRI_FIFO_MIN;
          case ACE_SCHED_RR:
            return ACE_THR_PRI_RR_MIN;
          case ACE_SCHED_OTHER:
          default:
            return ACE_THR_PRI_OTHER_MIN;
        }

    case ACE_SCOPE_PROCESS:
    default:
      switch (policy)
        {
          case ACE_SCHED_FIFO:
            return ACE_PROC_PRI_FIFO_MIN;
          case ACE_SCHED_RR:
            return ACE_PROC_PRI_RR_MIN;
          case ACE_SCHED_OTHER:
          default:
            return ACE_PROC_PRI_OTHER_MIN;
        }
    }

#elif defined (ACE_HAS_WTHREADS) && !defined (ACE_HAS_WINCE)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  return THREAD_PRIORITY_IDLE;
#elif defined (ACE_HAS_WTHREADS) && defined (ACE_HAS_WINCE)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  return 255;
#elif defined (ACE_VXWORKS)
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
# if defined (VX_TASK_PRIORITY_MAX)
  return VX_TASK_PRIORITY_MAX;
# else
  return 255;
# endif
#else
  ACE_UNUSED_ARG (policy);
  ACE_UNUSED_ARG (scope);
  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_PRIOCNTL && defined (ACE_HAS_STHREADS) */
}

const ACE_Time_Value & ACE_Sched_Params::quantum ( void   )  const

Definition at line 70 of file Sched_Params.inl.

{
  return this->quantum_;
}

void ACE_Sched_Params::quantum ( const ACE_Time_Value quant  ) 

Definition at line 76 of file Sched_Params.inl.

{
  this->quantum_ = quant;
}

int ACE_Sched_Params::scope ( void   )  const

Definition at line 58 of file Sched_Params.inl.

{
  return this->scope_;
}

void ACE_Sched_Params::scope ( const int  scope  ) 

Definition at line 64 of file Sched_Params.inl.

{
  this->scope_ = scope;
}


Member Data Documentation

Scheduling policy.

Definition at line 136 of file Sched_Params.h.

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

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

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


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines