diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2005-01-25 22:45:11 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2005-01-25 22:45:11 +0000 |
commit | 72c1491bba149c8fbd9eb81a0a529aa8bad47bb5 (patch) | |
tree | 22544335c6c060175878b8bd05f459cbbe0d3fd0 /winsup/cygwin/miscfuncs.cc | |
parent | 17923424c4bc8d7f132e174939814baebdbae1a0 (diff) | |
download | cygnal-72c1491bba149c8fbd9eb81a0a529aa8bad47bb5.tar.gz cygnal-72c1491bba149c8fbd9eb81a0a529aa8bad47bb5.tar.bz2 cygnal-72c1491bba149c8fbd9eb81a0a529aa8bad47bb5.zip |
* cygwin.din: Export getpriority and setpriority.
* fork.cc (fork_parent): Copy parent's nice value into child.
* spawn.cc (spawn_guts): Ditto.
* miscfuncs.cc (winprio_to_nice): New function.
(nice_to_winprio): Ditto.
* pinfo.cc (pinfo_init): If parent is not a Cygwin process, set
default nice value according to current Win32 priority class.
* pinfo.h (class _pinfo): Add nice member.
* syscalls.cc (setpriority): New function, only implementing
PRIO_PROCESS for now.
(getpriority): Ditto.
(nice): Just call setpriority.
* wincap.h (wincaps::has_extended_priority_class): New element.
* wincap.cc: Implement above element throughout.
* winsup.h: Add prototypes for winprio_to_nice and nice_to_winprio.
* include/limits.h (NZERO): New define.
* include/cygwin/types.h (id_t): New datatype.
* include/cygwin/version.h: Bump API minor version.
* include/sys/resource.h: Add PRIO_XXX defines and prototypes for
getpriority and setpriority.
Diffstat (limited to 'winsup/cygwin/miscfuncs.cc')
-rw-r--r-- | winsup/cygwin/miscfuncs.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index dcbe7c1b8..720c0bb08 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -356,3 +356,87 @@ low_priority_sleep (DWORD secs) return curr_prio; } + +/* Get a default value for the nice factor. When changing these values, + have a look into the below function nice_to_winprio. The values must + match the layout of the static "priority" array. */ +int +winprio_to_nice (DWORD prio) +{ + switch (prio) + { + case REALTIME_PRIORITY_CLASS: + return -20; + case HIGH_PRIORITY_CLASS: + return -16; + case ABOVE_NORMAL_PRIORITY_CLASS: + return -8; + case NORMAL_PRIORITY_CLASS: + return 0; + case BELOW_NORMAL_PRIORITY_CLASS: + return 8; + case IDLE_PRIORITY_CLASS: + return 16; + } + return 0; +} + +/* Get a Win32 priority matching the incoming nice factor. The incoming + nice is limited to the interval [-NZERO,NZERO-1]. */ +DWORD +nice_to_winprio (int &nice) +{ + static const DWORD priority[] NO_COPY = + { + REALTIME_PRIORITY_CLASS, /* 0 */ + HIGH_PRIORITY_CLASS, /* 1 */ + HIGH_PRIORITY_CLASS, + HIGH_PRIORITY_CLASS, + HIGH_PRIORITY_CLASS, + HIGH_PRIORITY_CLASS, + HIGH_PRIORITY_CLASS, + HIGH_PRIORITY_CLASS, /* 7 */ + ABOVE_NORMAL_PRIORITY_CLASS, /* 8 */ + ABOVE_NORMAL_PRIORITY_CLASS, + ABOVE_NORMAL_PRIORITY_CLASS, + ABOVE_NORMAL_PRIORITY_CLASS, + ABOVE_NORMAL_PRIORITY_CLASS, + ABOVE_NORMAL_PRIORITY_CLASS, + ABOVE_NORMAL_PRIORITY_CLASS, + ABOVE_NORMAL_PRIORITY_CLASS, /* 15 */ + NORMAL_PRIORITY_CLASS, /* 16 */ + NORMAL_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, + NORMAL_PRIORITY_CLASS, /* 23 */ + BELOW_NORMAL_PRIORITY_CLASS, /* 24 */ + BELOW_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS, + BELOW_NORMAL_PRIORITY_CLASS, /* 31 */ + IDLE_PRIORITY_CLASS, /* 32 */ + IDLE_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS, + IDLE_PRIORITY_CLASS /* 39 */ + }; + if (nice < -NZERO) + nice = -NZERO; + else if (nice > NZERO - 1) + nice = NZERO - 1; + DWORD prio = priority[nice + NZERO]; + if (!wincap.has_extended_priority_class () + && (prio == BELOW_NORMAL_PRIORITY_CLASS + || prio == ABOVE_NORMAL_PRIORITY_CLASS)) + prio = NORMAL_PRIORITY_CLASS; + return prio; +} |