]> granicus.if.org Git - php/commitdiff
Make proc_nice() more in line with that of Unix, as discussed with Anatol
authorKalle Sommer Nielsen <kalle@php.net>
Tue, 18 Oct 2016 21:25:59 +0000 (23:25 +0200)
committerKalle Sommer Nielsen <kalle@php.net>
Tue, 18 Oct 2016 21:25:59 +0000 (23:25 +0200)
ext/standard/tests/general_functions/proc_nice_basic-win.phpt
win32/nice.c

index 45d7c9245e346997b8e2391630ab7199205a565a..232389fd90231c6e0dbba02a9f57709268023525 100644 (file)
@@ -71,12 +71,12 @@ function get_priority_from_wmic() {
 $p = [
        /* '<verbose name>' => ['<wmic value>', '<proc_nice value>'] */
 
-       'Idle'          => [6, -10], 
-       'Below normal'  => [4, -3], 
+       'Idle'          => [4, 10], 
+       'Below normal'  => [6, 5], 
        'Normal'        => [8, 0], 
-       'Above normal'  => [10, 4], 
-       'High priority' => [13, 5], 
-       'Real time'     => [24, 8]
+       'Above normal'  => [10, -5], 
+       'High priority' => [13, -10], 
+       'Real time'     => [24, -16]
        ];
 
 foreach ($p as $test => $data) {
@@ -84,13 +84,13 @@ foreach ($p as $test => $data) {
 
        proc_nice($data[1]);
 
-       print (get_priority_from_wmic() === $data[0] ? 'Passed' : 'Failed') . PHP_EOL;
+       print (($wp = get_priority_from_wmic()) === $data[0] ? 'Passed' : 'Failed (' . $wp . ')') . PHP_EOL;
 }
 ?>
 --EXPECTF--
-Testing 'Idle' (-10): Passed
-Testing 'Below normal' (-3): Passed
+Testing 'Idle' (10): Passed
+Testing 'Below normal' (5): Passed
 Testing 'Normal' (0): Passed
-Testing 'Above normal' (4): Passed
-Testing 'High priority' (5): Passed
-Testing 'Real time' (8): Passed
+Testing 'Above normal' (-5): Passed
+Testing 'High priority' (-10): Passed
+Testing 'Real time' (-16): Passed
index 4a83faf78e4c9e14e9cc9308fbabc47988e3fc7e..db26cc1aa6a78e6ff1bec12bc7b3f8c22ea46ca6 100644 (file)
  *  +-----------------------+-----------------------------+
  *  | Expression            | Priority type                |
  *  +-----------------------+-----------------------------+
- *  | priority > 23         | REALTIME_PRIORITY_CLASS      |
+ *  | priority < -14        | REALTIME_PRIORITY_CLASS      |
  *  +-----------------------+-----------------------------+
- *  | priority > 12         | HIGH_PRIORITY_CLASS          |
+ *  | priority < -9         | HIGH_PRIORITY_CLASS          |
  *  +-----------------------+-----------------------------+
- *  | priority > 9          | ABOVE_NORMAL_PRIORITY_CLASS  |
+ *  | priority < -4         | ABOVE_NORMAL_PRIORITY_CLASS  |
  *  +-----------------------+-----------------------------+
- *  | priority > 7          | NORMAL_PRIORITY_CLASS        |
+ *  | priority > 4          | BELOW_NORMAL_PRIORITY_CLASS  |
  *  +-----------------------+-----------------------------+
- *  | priority > 5          | IDLE_PRIORITY_CLASS          |
- *  +-----------------------+-----------------------------+
- *  | priority > 3          | BELOW_NORMAL_PRIORITY_CLASS  |
+ *  | priority > 9          | IDLE_PRIORITY_CLASS          |
  *  +-----------------------+-----------------------------+
  *
- * Note, these values tries to mimic the outpof of wmic.
+ * If a value is between -4 and 4 (inclusive), then the priority will be set
+ * to NORMAL_PRIORITY_CLASS.
  *
- * If the value is below 4, then the process priority will default to 
- * NORMAL_PRIORITY_CLASS and anything above 23 will always be 
- * REALTIME_PRIORITY_CLASS.
+ * These values tries to mimic that of the UNIX version of nice().
  *
  * This is applied to the main process, not per thread, although this could 
  * be implemented using SetThreadPriority() at one point.
@@ -57,15 +54,15 @@ PHPAPI int nice(zend_long p)
 {
        DWORD dwFlag = NORMAL_PRIORITY_CLASS;
 
-       if (p > 23) {
+       if (p < -14) {
                dwFlag = REALTIME_PRIORITY_CLASS;
-       } else if (p > 12) { 
+       } else if (p < -9) { 
                dwFlag = HIGH_PRIORITY_CLASS;
-       } else if (p > 9) {
+       } else if (p < -4) {
                dwFlag = ABOVE_NORMAL_PRIORITY_CLASS;
-       } else if (p > 5 && p < 7) {
+       } else if (p > 9) {
                dwFlag = IDLE_PRIORITY_CLASS;
-       } else if (p > 3 && p < 7) {
+       } else if (p > 4) {
                dwFlag = BELOW_NORMAL_PRIORITY_CLASS;
        }