diff options
author | Christopher Faylor <me@cgf.cx> | 2003-09-27 03:44:31 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-09-27 03:44:31 +0000 |
commit | aff963076710f29348ae1e0249df94a27cde942d (patch) | |
tree | 90726cc8ea8c606ac3f4eb5afc01fffb7aacf7a9 /winsup/cygwin/sched.cc | |
parent | a3cbb4a7e09732e34e6a7d194f314aab6c35e4d0 (diff) | |
download | newlib-aff963076710f29348ae1e0249df94a27cde942d.zip newlib-aff963076710f29348ae1e0249df94a27cde942d.tar.gz newlib-aff963076710f29348ae1e0249df94a27cde942d.tar.bz2 |
* Makefile.in: Add libusr32.a to DLL_IMPORTS.
* wincap.h (wincaps::is_server): New flag.
(wincapc::version): Change type to OSVERSIONINFOEX.
(wincapc::is_server): New function.
* wincap.cc (wincap_unknown::is_server): New initializer.
(wincap_95): Ditto.
(wincap_95osr2): Ditto.
(wincap_98): Ditto.
(wincap_me): Ditto.
(wincap_nt3): Ditto.
(wincap_nt4): Ditto.
(wincap_nt4sp4): Ditto.
(wincap_2000): Ditto.
(wincap_xp): Ditto.
(wincapc::init): Adapt to OSVERSIONINFOEX. Add detection of NT server systems.
* sched.cc: Include windows.h and registry.h.
(sched_rr_get_interval): Re-implement for NT systems.
Diffstat (limited to 'winsup/cygwin/sched.cc')
-rw-r--r-- | winsup/cygwin/sched.cc | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc index b29d7a4..548c659 100644 --- a/winsup/cygwin/sched.cc +++ b/winsup/cygwin/sched.cc @@ -14,6 +14,7 @@ # include "config.h" #endif +#define _WIN32_WINNT 0x300 #include "winsup.h" #include <limits.h> #include "cygerrno.h" @@ -24,6 +25,9 @@ #include "pinfo.h" /* for getpid */ #include <unistd.h> +#include "registry.h" + +extern "C" HWND WINAPI GetForegroundWindow(); /* Win32 priority to UNIX priority Mapping. For now, I'm just following the spec: any range of priorities is ok. @@ -249,21 +253,75 @@ sched_getscheduler (pid_t pid) /* get the time quantum for pid - We can't return -11, errno ENOSYS, because that implies that - sched_get_priority_max & min are also not supported (according to the spec) - so some spec-driven autoconf tests will likely assume they aren't present either - - returning ESRCH might confuse some applications (if they assumed that when - rr_get_interval is called on pid 0 it always works). - - If someone knows the time quanta for the various win32 platforms, then a - simple check for the os we're running on will finish this function + Implemented only for NT systems, it fails and sets errno to ESRCH + for non-NT systems. */ int sched_rr_get_interval (pid_t pid, struct timespec *interval) { - set_errno (ESRCH); - return -1; + static const char quantable[2][2][3] = + {{{12, 24, 36}, { 6, 12, 18}}, + {{36, 36, 36}, {18, 18, 18}}}; + /* FIXME: Clocktickinterval can be 15 ms for multi-processor system. */ + static const int clocktickinterval = 10; + static const int quantapertick = 3; + + HWND forwin; + DWORD forprocid; + int vfindex, slindex, qindex, prisep; + long nsec; + + if (!wincap.is_winnt ()) + { + set_errno (ESRCH); + return -1; + } + + forwin = GetForegroundWindow (); + if (!forwin) + GetWindowThreadProcessId (forwin, &forprocid); + else + forprocid = 0; + + reg_key reg (HKEY_LOCAL_MACHINE, KEY_READ, "SYSTEM", "CurrentControlSet", + "Control", "PriorityControl", NULL); + if (reg.error ()) + { + set_errno (ESRCH); + return -1; + } + prisep = reg.get_int ("Win32PrioritySeparation", 2); + pinfo pi (pid ? pid : myself->pid); + if (!pi) + { + set_errno (ESRCH); + return -1; + } + + if (pi->dwProcessId == forprocid) + { + qindex = prisep & 3; + qindex = qindex == 3 ? 2 : qindex; + } + else + qindex = 0; + vfindex = ((prisep >> 2) & 3) % 3; + if (vfindex == 0) + vfindex = wincap.is_server () || prisep & 3 == 0 ? 1 : 0; + else + vfindex -= 1; + slindex = ((prisep >> 4) & 3) % 3; + if (slindex == 0) + slindex = wincap.is_server () ? 1 : 0; + else + slindex -= 1; + + nsec = quantable[vfindex][slindex][qindex] / quantapertick + * clocktickinterval * 1000000; + interval->tv_sec = nsec / 1000000000; + interval->tv_nsec = nsec % 1000000000; + + return 0; } /* set the scheduling parameters */ |