diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-01-29 04:01:33 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-01-29 04:01:33 +0000 |
commit | 45f6114ba2581a7d1dec2bd8a9b84aeb876e052a (patch) | |
tree | 0680ad1b72afefe67e5c973324783b5553f32e11 /ace/OS.cpp | |
parent | c01e57bb9e0e5e2e88bb885d24aa7b56bf0e0660 (diff) | |
download | ATCD-45f6114ba2581a7d1dec2bd8a9b84aeb876e052a.tar.gz |
added ACE_OS::set_sched_params (), and ACE_Scheduling_Parameters and ACE_Thread_Priority classes
Diffstat (limited to 'ace/OS.cpp')
-rw-r--r-- | ace/OS.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/ace/OS.cpp b/ace/OS.cpp index 0f378aaed9a..53063b2a271 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -3,6 +3,7 @@ // OS.cpp #define ACE_BUILD_DLL #include "ace/OS.h" +#include "ace/Scheduling_Params.h" #if defined (ACE_WIN32) #include "ace/ARGV.h" @@ -448,6 +449,98 @@ ACE_OS::execlp (const char * /* file */, const char * /* arg0 */, ...) #endif /* ACE_WIN32 */ } +#if defined (ACE_HAS_STHREADS) +#include <sys/rtpriocntl.h> +#include <sys/tspriocntl.h> +#endif /* ACE_HAS_STHREADS */ + +int +ACE_OS::set_sched_params (const ACE_Scheduling_Params &scheduling_params) +{ + // ACE_TRACE ("ACE_OS::set_sched_params"); +#if defined (ACE_HAS_STHREADS) + // Set priority class, priority, and quantum of this LWP or process as + // specified in scheduling_params. + + pcparms_t pcparms; + pcparms.pc_cid = scheduling_params.priority ().os_priority_class (); + + 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) + { + rtparms_t rtparms; + rtparms.rt_pri = + scheduling_params.priority ().os_default_thread_priority (); + if (scheduling_params.quantum () == ACE_Time_Value::zero) + { + rtparms.rt_tqsecs = 0ul; + rtparms.rt_tqnsecs = RT_TQINF; + } + else + { + rtparms.rt_tqsecs = (ulong) scheduling_params.quantum ().sec (); + rtparms.rt_tqnsecs = scheduling_params.quantum ().usec () * 1000; + } + + // Package up the RT class ID and parameters for the ::priocntl () call. + ACE_OS::memcpy (pcparms.pc_clparms, &rtparms, sizeof rtparms); + } + else + { + tsparms_t tsparms; + // Don't bother changing ts_uprilim (user priority limit) from its + // default of 0. + tsparms.ts_uprilim = 0; + 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); + } + + if (::priocntl ((idtype_t) scheduling_params.scope (), P_MYID, PC_SETPARMS, + (char *) &pcparms) < 0) + { + return ACE_OS::last_error (); + } + +#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; + } + + // Set the thread priority on the current thread. + if (! ::SetThreadPriority ( + ::GetCurrentThread (), + scheduling_params.priority ().os_default_thread_priority ()) + { + return -1; + } + + +#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_htread_t my_thread_id; + ACE_OS::thr_self (&my_thread_id); + ACE_OS::thr_setprio ( + my_thread_id, + scheduling_params.priority ().os_default_thread_priority ()); + + +#else + ACE_NOTSUP_RETURN (ENOTSUP); +#endif /* ACE_HAS_STHREADS */ + + return 0; +} + // = Static initialization. // This is necessary to deal with POSIX pthreads insanity. This |