diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-02-28 19:21:43 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-02-28 19:21:43 +0000 |
commit | 445c09803d3cdab7a5fcbae0e24a16df79eeb8fd (patch) | |
tree | 41ba037cf8971ad3ecc97e3050345290f63552ab | |
parent | cdd8bd3369913ccd8ad26b55dc3a77e228f4d93e (diff) | |
download | ATCD-445c09803d3cdab7a5fcbae0e24a16df79eeb8fd.tar.gz |
first cut at new thread priority scheme
-rw-r--r-- | ace/Makefile | 26 | ||||
-rw-r--r-- | ace/OS.cpp | 190 | ||||
-rw-r--r-- | ace/OS.h | 27 | ||||
-rw-r--r-- | ace/Sched_Params.cpp | 128 | ||||
-rw-r--r-- | ace/Sched_Params.h | 76 | ||||
-rw-r--r-- | ace/Sched_Params.i | 47 |
6 files changed, 378 insertions, 116 deletions
diff --git a/ace/Makefile b/ace/Makefile index 176de92a8cc..3bb55c28573 100644 --- a/ace/Makefile +++ b/ace/Makefile @@ -86,7 +86,7 @@ FILES = ACE \ SPIPE_Connector \ SPIPE_Stream \ SString \ - Scheduling_Params \ + Sched_Params \ Service_Config \ Service_Manager \ Service_Object \ @@ -112,7 +112,6 @@ FILES = ACE \ TLI_Stream \ Thread \ Thread_Manager \ - Thread_Priority \ Time_Request_Reply \ Timer_Heap \ Timer_List \ @@ -1386,8 +1385,7 @@ Svc_Conf_l.cpp: Svc_Conf.l $(WRAPPER_ROOT)/ace/ACE.h \ $(WRAPPER_ROOT)/ace/ACE.i \ $(WRAPPER_ROOT)/ace/Log_Record.i \ - $(WRAPPER_ROOT)/ace/Scheduling_Params.h \ - $(WRAPPER_ROOT)/ace/Thread_Priority.h \ + $(WRAPPER_ROOT)/ace/Sched_Params.h \ $(WRAPPER_ROOT)/ace/OS.i .obj/Parse_Node.o .shobj/Parse_Node.so: Parse_Node.cpp \ $(WRAPPER_ROOT)/ace/Service_Config.h \ @@ -2149,7 +2147,7 @@ Svc_Conf_l.cpp: Svc_Conf.l $(WRAPPER_ROOT)/ace/Svc_Conf_Tokens.h \ $(WRAPPER_ROOT)/ace/SString.h \ $(WRAPPER_ROOT)/ace/SString.i -.obj/Scheduling_Params.o .shobj/Scheduling_Params.so: Scheduling_Params.cpp \ +.obj/Sched_Params.o .shobj/Sched_Params.so: Sched_Params.cpp \ $(WRAPPER_ROOT)/ace/ACE.h \ $(WRAPPER_ROOT)/ace/OS.h \ $(WRAPPER_ROOT)/ace/config.h \ @@ -2160,9 +2158,8 @@ Svc_Conf_l.cpp: Svc_Conf.l $(WRAPPER_ROOT)/ace/Log_Priority.h \ $(WRAPPER_ROOT)/ace/Log_Record.i \ $(WRAPPER_ROOT)/ace/ACE.i \ - $(WRAPPER_ROOT)/ace/Scheduling_Params.h \ - $(WRAPPER_ROOT)/ace/Thread_Priority.h \ - $(WRAPPER_ROOT)/ace/Scheduling_Params.i + $(WRAPPER_ROOT)/ace/Sched_Params.h \ + $(WRAPPER_ROOT)/ace/Sched_Params.i .obj/Service_Config.o .shobj/Service_Config.so: Service_Config.cpp \ $(WRAPPER_ROOT)/ace/Svc_Conf.h \ $(WRAPPER_ROOT)/ace/Obstack.h \ @@ -2845,19 +2842,6 @@ Svc_Conf_l.cpp: Svc_Conf.l $(WRAPPER_ROOT)/ace/Synch_T.h \ $(WRAPPER_ROOT)/ace/Event_Handler.h \ $(WRAPPER_ROOT)/ace/Thread_Manager.i -.obj/Thread_Priority.o .shobj/Thread_Priority.so: Thread_Priority.cpp \ - $(WRAPPER_ROOT)/ace/Thread_Priority.h \ - $(WRAPPER_ROOT)/ace/OS.h \ - $(WRAPPER_ROOT)/ace/config.h \ - $(WRAPPER_ROOT)/ace/stdcpp.h \ - $(WRAPPER_ROOT)/ace/Trace.h \ - $(WRAPPER_ROOT)/ace/Log_Msg.h \ - $(WRAPPER_ROOT)/ace/Log_Record.h \ - $(WRAPPER_ROOT)/ace/Log_Priority.h \ - $(WRAPPER_ROOT)/ace/ACE.h \ - $(WRAPPER_ROOT)/ace/ACE.i \ - $(WRAPPER_ROOT)/ace/Log_Record.i \ - $(WRAPPER_ROOT)/ace/Thread_Priority.i .obj/Time_Request_Reply.o .shobj/Time_Request_Reply.so: Time_Request_Reply.cpp \ $(WRAPPER_ROOT)/ace/Time_Request_Reply.h \ $(WRAPPER_ROOT)/ace/Time_Value.h \ diff --git a/ace/OS.cpp b/ace/OS.cpp index 2043b08cd7f..6423f4c5c1b 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -3,7 +3,7 @@ // OS.cpp #define ACE_BUILD_DLL #include "ace/OS.h" -#include "ace/Scheduling_Params.h" +#include "ace/Sched_Params.h" #if defined (ACE_WIN32) #include "ace/ARGV.h" @@ -294,7 +294,7 @@ ACE_Countdown_Time::~ACE_Countdown_Time (void) this->stop (); } -#if defined (ACE_HAS_PENTIUM) && defined (linux) +#if defined (ACE_HAS_PENTIUM) && defined (__GNUC__) ACE_hrtime_t ACE_OS::gethrtime (void) { @@ -312,7 +312,7 @@ ACE_OS::gethrtime (void) return (unsigned long long) most << 32 | least; } -#endif /* ACE_HAS_PENTIUM && linux */ +#endif /* ACE_HAS_PENTIUM && __GNUC__ */ #if defined(ACE_MT_SAFE) && defined(ACE_LACKS_NETDB_REENTRANT_FUNCTIONS) @@ -533,34 +533,78 @@ ACE_OS::execlp (const char * /* file */, const char * /* arg0 */, ...) #endif /* ACE_HAS_STHREADS */ int -ACE_OS::set_sched_params (const ACE_Scheduling_Params &scheduling_params) +ACE_OS::thr_setprio (const ACE_Sched_Priority prio) { - // ACE_TRACE ("ACE_OS::set_sched_params"); + // Set the thread priority on the current thread. + ACE_hthread_t my_thread_id; + ACE_OS::thr_self (my_thread_id); + return ACE_OS::thr_setprio (my_thread_id, prio); +} + +int +ACE_OS::sched_params (const ACE_Sched_Params &sched_params) +{ + // ACE_TRACE ("ACE_OS::sched_params"); #if defined (ACE_HAS_STHREADS) // Set priority class, priority, and quantum of this LWP or process as - // specified in scheduling_params. + // specified in sched_params. + + // Get the priority class ID and attributes. + pcinfo_t pcinfo; + ACE_OS::strcpy (pcinfo.pc_clname, + sched_params.policy() == ACE_SCHED_OTHER ? "TS" : "RT"); + // The following is just to avoid Purify warnings about unitialized + // memory reads. + ACE_OS::memset (pcinfo.pc_clinfo, 0, PC_CLINFOSZ); + + if (::priocntl (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. pcparms_t pcparms; - pcparms.pc_cid = scheduling_params.priority ().os_priority_class (); + pcparms.pc_cid = pcinfo.pc_cid; - if (scheduling_params.priority ().priority_class () == - ACE_Thread_Priority::ACE_HIGH_PRIORITY_CLASS - || scheduling_params.priority ().priority_class () == - ACE_Thread_Priority::ACE_REALTIME_PRIORITY_CLASS) + if (sched_params.policy () == ACE_SCHED_OTHER && + sched_params.quantum () == ACE_Time_Value::zero) + // Solaris doesn't support non-zero quantums in time-sharing class: use + // real-time class instead. + { + tsparms_t tsparms; + // Don't change ts_uprilim (user priority limit) + tsparms.ts_uprilim = TS_NOCHANGE; + tsparms.ts_upri = sched_params.priority (); + + // Package up the TS class ID and parameters for the ::priocntl () + // call. + ACE_OS::memcpy (pcparms.pc_clparms, &tsparms, sizeof tsparms); + } + else if (sched_params.policy () == ACE_SCHED_FIFO || + (sched_params.policy () == ACE_SCHED_RR && + sched_params.quantum () != ACE_Time_Value::zero)) + // must have non-zero quantum for RR, to make it meaningful + // A zero quantum with FIFO has special significance: it actually + // means infinite time quantum, i.e., run-to-completion. { rtparms_t rtparms; - rtparms.rt_pri = - scheduling_params.priority ().os_default_thread_priority (); + rtparms.rt_pri = sched_params.priority (); - if (scheduling_params.quantum () == ACE_Time_Value::zero) + if (sched_params.quantum () == ACE_Time_Value::zero) { // rtparms.rt_tqsecs is ignored with RT_TQINF rtparms.rt_tqnsecs = RT_TQINF; } else { - rtparms.rt_tqsecs = (ulong) scheduling_params.quantum ().sec (); - rtparms.rt_tqnsecs = scheduling_params.quantum ().usec () * 1000; + rtparms.rt_tqsecs = (ulong) sched_params.quantum ().sec (); + rtparms.rt_tqnsecs = sched_params.quantum ().usec () * 1000; } // Package up the RT class ID and parameters for the ::priocntl () @@ -569,75 +613,107 @@ ACE_OS::set_sched_params (const ACE_Scheduling_Params &scheduling_params) } else { - tsparms_t tsparms; - // Don't change ts_uprilim (user priority limit) - tsparms.ts_uprilim = TS_NOCHANGE; - tsparms.ts_upri = scheduling_params.priority ().os_default_thread_priority (); - - // Package up the TS class ID and parameters for the ::priocntl () - // call. - ACE_OS::memcpy (pcparms.pc_clparms, &tsparms, sizeof tsparms); + errno = EINVAL; + return -1; } - if (::priocntl ((idtype_t) scheduling_params.scope (), P_MYID, PC_SETPARMS, + if (::priocntl ((idtype_t) sched_params.scope (), P_MYID, PC_SETPARMS, (char *) &pcparms) < 0) { return ACE_OS::last_error (); } + return 0; + #elif defined (ACE_WIN32) - // Set the priority class of this process to the real-time process class. - if (! ::SetPriorityClass (::GetCurrentProcess (), - scheduling_params.priority ().os_priority_class ())) - return -1; + if (sched_params.scope () != ACE_SCOPE_PROCESS || + sched_params.quantum () != ACE_Time_Value::zero) + { + // Win32 only allows setting priority class (therefore, policy) + // at the process level. I don't know of a way to set the quantum. + errno = EINVAL; + return -1; + } - // Set the thread priority on the current thread. - ACE_hthread_t my_thread_id; - ACE_OS::thr_self (my_thread_id); - if (ACE_OS::thr_setprio (my_thread_id, - scheduling_params.priority ().os_default_thread_priority ()) == -1) - return -1; + // Set the priority class of this process to the REALTIME process class + // _if_ the policy is ACE_SCHED_FIFO. Otherwise, set to NORMAL. + if (! ::SetPriorityClass ( + ::GetCurrentProcess (), + sched_params.policy () == ACE_SCHED_FIFO + ? REALTIME_PRIORITY_CLASS + : NORMAL_PRIORITY_CLASS)) + { + return -1; + } + // Set the thread priority on the current thread. + return ACE_OS::thr_setprio (sched_params.priority ()); #elif defined (VXWORKS) // There is only one class of priorities on VxWorks, and no // time quanta. So, just set the current thread's priority. - ACE_hthread_t my_thread_id; - ACE_OS::thr_self (&my_thread_id); - // this call should never fail on VxWorks - ACE_OS::thr_setprio (my_thread_id, - scheduling_params.priority ().os_default_thread_priority ()); + if (sched_params.policy () != ACE_SCHED_FIFO || + sched_params.scope () != ACE_SCOPE_PROCESS || + sched_params.quantum () != ACE_Time_Value::zero) + { + errno = EINVAL; + return -1; + } + + // Set the thread priority on the current thread. + return ACE_OS::thr_setprio (sched_params.priority ()); #elif (defined (ACE_HAS_DCETHREADS) || defined (ACE_HAS_PTHREADS)) && !defined (ACE_LACKS_SETSCHED) + if (sched_params.quantum () != ACE_Time_Value::zero) + { + // quantums not supported + errno = EINVAL; + return -1; + } + // Thanks to Thilo Kielmann <kielmann@informatik.uni-siegen.de> for // providing this code for 1003.1c PThreads. Please note that this // has only been tested for POSIX 1003.1c threads, and may cause problems // with other PThreads flavors! - struct sched_param param; - int policy, result; ACE_thread_t thr_id = ACE_OS::thr_self (); + int result; + struct sched_param param; + + param.sched_priority = sched_params.priority (); + + if (sched_params.scope () == ACE_SCOPE_PROCESS) + { + ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sched_setscheduler ( + thr_id, + sched_params.policy (), + ¶m), + result), + int, -1); + } + else if (sched_params.scope () == ACE_SCOPE_THREAD) + { + param.sched_priority = sched_params.priority (); - ACE_OSCALL (ACE_ADAPT_RETVAL (::pthread_getschedparam (thr_id, &policy, ¶m), - result), - int, -1, result); - if (result == -1) - return result; // error in pthread_getschedparam - - param.sched_priority = - scheduling_params.priority ().os_default_thread_priority (); - policy = scheduling_params.priority ().os_priority_class (); - - ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setschedparam (thr_id, policy,¶m), - result), - int, -1); + ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setschedparam ( + thr_id, + sched_params.policy (), + ¶m), + result), + int, -1); + } + else // sched_params.scope () == ACE_SCOPE_LWP, which isn't POSIX + { + errno = EINVAL; + return -1; + } + + return 0; #else ACE_NOTSUP_RETURN (ENOTSUP); #endif /* ACE_HAS_STHREADS */ - - return 0; } // = Static initialization. @@ -834,12 +834,24 @@ struct cancel_state #include /**/ <thread.h> #define ACE_SCOPE_PROCESS P_PID #define ACE_SCOPE_LWP P_LWPID +#define ACE_SCOPE_THREAD (ACE_SCOPE_LWP + 1) #else #define ACE_SCOPE_PROCESS 0 #define ACE_SCOPE_LWP 1 +#define ACE_SCOPE_THREAD 2 #endif /* ACE_HAS_STHREADS */ +#if ! (defined (ACE_HAS_DCETHREADS) || defined (ACE_HAS_PTHREADS)) +#define ACE_SCHED_OTHER 0 +#define ACE_SCHED_FIFO 1 +#define ACE_SCHED_RR 2 +#endif /* ! (ACE_HAS_DCETHREADS || ACE_HAS_PTHREADS) */ + #if defined (ACE_HAS_DCETHREADS) || defined (ACE_HAS_PTHREADS) +#define ACE_SCHED_OTHER SCHED_OTHER +#define ACE_SCHED_FIFO SCHED_FIFO +#define ACE_SCHED_RR SCHED_RR + // Definitions for mapping POSIX pthreads onto Solaris threads. #if defined (ACE_HAS_FSU_PTHREADS) @@ -1159,6 +1171,10 @@ private: // Give these things some reasonable value... #define ACE_SCOPE_PROCESS 0 #define ACE_SCOPE_LWP 1 +#define ACE_SCOPE_THREAD 2 +#define ACE_SCHED_OTHER 0 +#define ACE_SCHED_FIFO 1 +#define ACE_SCHED_RR 2 #define THR_CANCEL_DISABLE 0 #define THR_CANCEL_ENABLE 0 #define THR_CANCEL_DEFERRED 0 @@ -2262,8 +2278,13 @@ extern "C" int _xti_error(char *); #endif /* UNIXWARE */ #endif /* ACE_REDEFINES_XTI_FUNCTIONS */ +// = The ACE_Sched_Priority type should be used for platform- +// independent thread and process priorities, by convention. +// int should be used for OS-specific priorities. +typedef int ACE_Sched_Priority; + // forward declaration -class ACE_Scheduling_Params; +class ACE_Sched_Params; class ACE_Export ACE_OS // = TITLE @@ -2557,7 +2578,7 @@ public: static int semop (int int_id, struct sembuf *sops, size_t nsops); // = Thread scheduler interface. - static int set_sched_params (const ACE_Scheduling_Params &); + static int sched_params (const ACE_Sched_Params &); // = A set of wrappers for System V shared memory. static void *shmat (int int_id, void *shmaddr, int shmflg); @@ -2746,6 +2767,7 @@ public: static int thr_kill (ACE_Thread_ID thr_id, int signum); static ACE_Thread_ID thr_self (void); static int thr_setprio (ACE_Thread_ID thr_id, int prio); + static int thr_setprio (const ACE_Sched_Priority prio); static int thr_suspend (ACE_Thread_ID target_thread); static int thr_cancel (ACE_Thread_ID t_id); #endif /* 0 */ @@ -2767,6 +2789,7 @@ public: static ACE_thread_t thr_self (void); static void thr_self (ACE_hthread_t &); static int thr_setprio (ACE_hthread_t thr_id, int prio); + static int thr_setprio (const ACE_Sched_Priority prio); static int thr_suspend (ACE_hthread_t target_thread); static int thr_cancel (ACE_thread_t t_id); diff --git a/ace/Sched_Params.cpp b/ace/Sched_Params.cpp index f26eb2b1570..1b13a92f435 100644 --- a/ace/Sched_Params.cpp +++ b/ace/Sched_Params.cpp @@ -6,7 +6,7 @@ // ACE // // = FILENAME -// Scheduling_Params.cpp +// Sched_Params.cpp // // = CREATION DATE // 28 January 1997 @@ -19,9 +19,131 @@ #define ACE_BUILD_DLL #include "ace/ACE.h" -#include "ace/Scheduling_Params.h" +#include "ace/Sched_Params.h" #if !defined (__ACE_INLINE__) -#include "ace/Scheduling_Params.i" +#include "ace/Sched_Params.i" #endif /* __ACE_INLINE__ */ +#if defined (ACE_HAS_STHREADS) +#include <sys/rtpriocntl.h> +#include <sys/tspriocntl.h> +#endif /* ACE_HAS_STHREADS */ + +int +ACE_Sched_Params::priority_min (const Policy policy) +{ +#if defined (ACE_HAS_STHREADS) + // Assume that ACE_SCHED_OTHER indicates Solaris TS class, and that + // other policies indicate Solaris RT class. + + if (policy == ACE_SCHED_OTHER) + { + // Get the priority class ID and attributes. + pcinfo_t pcinfo; + ACE_OS::strcpy (pcinfo.pc_clname, "TS"); + // The following is just to avoid Purify warnings about unitialized + // memory reads. + ACE_OS::memset (pcinfo.pc_clinfo, 0, PC_CLINFOSZ); + + if (::priocntl (P_ALL /* ignored */, + P_MYID /* ignored */, + PC_GETCID, + (char *) &pcinfo) == -1) + { + return -1; // just hope that priority range wasn't configured + // from -1 .. 1 + } + + // OK, now we've got the class ID in pcinfo.pc_cid. In addition, + // the maximum configured real-time priority is in ((tsinfo_t *) + // pcinfo.pc_clinfo)->ts_maxupri. + + return -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri; + } + else + { + return 0; + } +#elif defined (ACE_HAS_DCETHREADS) || defined(ACE_HAS_PTHREADS) + return ::sched_get_priority_min (policy); +#elif defined (ACE_HAS_WTHREADS) + return THREAD_PRIORITY_IDLE; +#elif defined (VXWORKS) + return 255; +#elif + ACE_NOTSUP_RETURN (-1); +#endif /* ACE_HAS_STHREADS */ +} + +int +ACE_Sched_Params::priority_max (const Policy policy) +{ +#if defined (ACE_HAS_STHREADS) + // Assume that ACE_SCHED_OTHER indicates Solaris TS class, and that + // other policies indicate Solaris RT class. + + // Get the priority class ID and attributes. + pcinfo_t pcinfo; + ACE_OS::strcpy (pcinfo.pc_clname, + policy == ACE_SCHED_OTHER ? "TS" : "RT"); + // The following is just to avoid Purify warnings about unitialized + // memory reads. + ACE_OS::memset (pcinfo.pc_clinfo, 0, PC_CLINFOSZ); + + if (::priocntl (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; +#elif defined (ACE_HAS_DCETHREADS) || defined(ACE_HAS_PTHREADS) + return ::sched_get_priority_max (policy); +#elif defined (ACE_HAS_WTHREADS) + return THREAD_PRIORITY_TIME_CRITICAL; +#elif defined (VXWORKS) + return 0; +#elif + ACE_NOTSUP_RETURN (-1); +#endif /* ACE_HAS_STHREADS */ +} + +int +ACE_Sched_Params::next_priority (const Policy policy, const int priority) +{ +#if defined (VXWORKS) + ACE_UNUSED_ARG (policy); + return priority > priority_max (policy) ? priority - 1 + : priority_max (policy); +#elif defined (ACE_HAS_THREADS) + const int max = priority_max (policy); + return priority < max ? priority + 1 : max; +#elif + ACE_NOTSUP_RETURN (-1); +#endif /* ACE_HAS_THREADS */ +} + +int +ACE_Sched_Params::previous_priority (const Policy policy, + const int priority) +{ +#if defined (VXWORKS) + ACE_UNUSED_ARG (policy); + return priority < priority_min (policy) ? priority + 1 + : priority_min (policy); +#elif defined (ACE_HAS_THREADS) + const int min = priority_min (policy); + return priority > min ? priority - 1 : min; +#elif + ACE_NOTSUP_RETURN (-1); +#endif /* ACE_HAS_THREADS */ +} diff --git a/ace/Sched_Params.h b/ace/Sched_Params.h index dc823033cba..2faece3bed8 100644 --- a/ace/Sched_Params.h +++ b/ace/Sched_Params.h @@ -7,7 +7,7 @@ // ACE // // = FILENAME -// Scheduling_Params.h +// Sched_Params.h // // = CREATION DATE // 28 January 1997 @@ -17,19 +17,17 @@ // // ============================================================================ -#if !defined (ACE_SCHEDULING_PARAMS_H) -#define ACE_SCHEDULING_PARAMS_H +#if !defined (ACE_SCHED_PARAMS_H) +#define ACE_SCHED_PARAMS_H -#include "ace/Thread_Priority.h" -// for ACE_Time_Value and ACE_SCOPE_PROCESS #include "ace/OS.h" -class ACE_Export ACE_Scheduling_Params +class ACE_Export ACE_Sched_Params // = TITLE // Container for thread scheduling-related parameters. // // = DESCRIPTION - // ACE_Scheduling_Params are passed via + // ACE_Sched_Params are passed via // ACE_OS::set_sched_params () to the OS to specify scheduling // parameters. It is intended that ACE_OS::set_sched_params () // be called from main () before any threads have been spawned. @@ -39,39 +37,77 @@ class ACE_Export ACE_Scheduling_Params // 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::set_sched_params () will fail by returning -1 with EINVAL + // (available through ACE_OS::last_error ()). { public: + typedef int Policy; + // = Initialization and termination methods. - ACE_Scheduling_Params (const ACE_Thread_Priority &priority = ACE_Thread_Priority (), - const int scope = ACE_SCOPE_PROCESS, - const ACE_Time_Value &quantum = ACE_Time_Value::zero); + 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_Scheduling_Params (void); + ~ACE_Sched_Params (void); // Termination. // = Get/Set methods: + // = Get/Set policy + Policy policy (void) const; + void policy (const Policy); + // = Get/Set priority. - const ACE_Thread_Priority &priority (void) const; - void set_priority (const ACE_Thread_Priority &); + ACE_Sched_Priority priority (void) const; + void priority (const ACE_Sched_Priority); // = Get/Set scope. int scope (void) const; - void set_scope(const int); + void scope(const int); // = Get/Set quantum. const ACE_Time_Value &quantum (void) const; - void set_quantum (const ACE_Time_Value &); + void quantum (const ACE_Time_Value &); + + // = Accessors for OS-specific priorities. + static int priority_min (const Policy); + static int priority_max (const Policy); + + static int next_priority (const Policy, const int priority); + // 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.) + + static int previous_priority (const Policy, const int priority); + // 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.) private: - ACE_Thread_Priority priority_; + Policy policy_; + // Scheduling policy. + + ACE_Sched_Priority priority_; // Default <priority_>: sets the priority to be used for newly // spawned threads. int scope_; - // <scope_> must be either ACE_SCOPE_PROCESS or ACE_SCOPE_LWP (which - // is only used on Solaris, and ignored on Win32 and VxWorks) + // <scope_> must 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. ACE_Time_Value quantum_; // The <quantum_> is for time slicing. An ACE_Time_Value of 0 has @@ -83,7 +119,7 @@ private: }; #if defined (__ACE_INLINE__) -#include "ace/Scheduling_Params.i" +#include "ace/Sched_Params.i" #endif /* __ACE_INLINE__ */ -#endif /* ACE_SCHEDULING_PARAMS_H */ +#endif /* ACE_SCHED_PARAMS_H */ diff --git a/ace/Sched_Params.i b/ace/Sched_Params.i index 82b7f29b61a..08d4eb810b9 100644 --- a/ace/Sched_Params.i +++ b/ace/Sched_Params.i @@ -7,7 +7,7 @@ // ACE // // = FILENAME -// Scheduling_Params.i +// Sched_Params.i // // = CREATION DATE // 28 January 1997 @@ -18,47 +18,68 @@ // ============================================================================ ACE_INLINE -ACE_Scheduling_Params::ACE_Scheduling_Params (const ACE_Thread_Priority &priority, - const int scope, - const ACE_Time_Value &quantum) - : priority_ (priority), +ACE_Sched_Params::ACE_Sched_Params ( + const Policy policy, + const ACE_Sched_Priority priority, + const int scope, + const ACE_Time_Value &quantum) + : policy_ (policy), + priority_ (priority), scope_ (scope), quantum_ (quantum) { } -ACE_INLINE ACE_Scheduling_Params::~ACE_Scheduling_Params (void) +ACE_INLINE ACE_Sched_Params::~ACE_Sched_Params (void) { } -ACE_INLINE const ACE_Thread_Priority & -ACE_Scheduling_Params::priority (void) const +ACE_INLINE ACE_Sched_Params::Policy +ACE_Sched_Params::policy (void) const +{ + return this->policy_; +} + +ACE_INLINE void +ACE_Sched_Params::policy (const ACE_Sched_Params::Policy policy) +{ + this->policy_ = policy; +} + +ACE_INLINE ACE_Sched_Priority +ACE_Sched_Params::priority (void) const { return this->priority_; } +ACE_INLINE void +ACE_Sched_Params::priority (const ACE_Sched_Priority priority) +{ + this->priority_ = priority; +} + ACE_INLINE int -ACE_Scheduling_Params::scope (void) const +ACE_Sched_Params::scope (void) const { return this->scope_; } ACE_INLINE void -ACE_Scheduling_Params::set_scope (const int scope) +ACE_Sched_Params::scope (const int scope) { this->scope_ = scope; } ACE_INLINE const ACE_Time_Value & -ACE_Scheduling_Params::quantum (void) const +ACE_Sched_Params::quantum (void) const { return this->quantum_; } ACE_INLINE void -ACE_Scheduling_Params::set_quantum (const ACE_Time_Value &quantum) +ACE_Sched_Params::quantum (const ACE_Time_Value &quant) { - this->quantum_ = quantum; + this->quantum_ = quant; } |