Change the semantics of proc_nice() for Windows to better match the values of the wmic output

This commit is contained in:
Kalle Sommer Nielsen 2016-10-16 05:21:30 +02:00
parent 64945e9387
commit 5c169af7c9

View file

@ -30,19 +30,25 @@
* +-----------------------+-----------------------------+
* | Expression | Priority type |
* +-----------------------+-----------------------------+
* | priority > 5 | REALTIME_PRIORITY_CLASS |
* | priority > 23 | REALTIME_PRIORITY_CLASS |
* +-----------------------+-----------------------------+
* | priority == 5 | HIGH_PRIORITY_CLASS |
* | priority > 12 | HIGH_PRIORITY_CLASS |
* +-----------------------+-----------------------------+
* | priority > 0 | ABOVE_NORMAL_PRIORITY_CLASS |
* | priority > 9 | ABOVE_NORMAL_PRIORITY_CLASS |
* +-----------------------+-----------------------------+
* | priority == 0 | NORMAL_PRIORITY_CLASS |
* | priority > 7 | NORMAL_PRIORITY_CLASS |
* +-----------------------+-----------------------------+
* | priority < -5 | BELOW_NORMAL_PRIORITY_CLASS |
* | priority > 5 | IDLE_PRIORITY_CLASS |
* +-----------------------+-----------------------------+
* | priority < -10 | IDLE_PRIORITY_CLASS |
* | priority > 3 | BELOW_NORMAL_PRIORITY_CLASS |
* +-----------------------+-----------------------------+
*
* Note, these values tries to mimic the outpof of wmic.
*
* 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.
*
* This is applied to the main process, not per thread, although this could
* be implemented using SetThreadPriority() at one point.
*/
@ -51,16 +57,16 @@ PHPAPI int nice(zend_long p)
{
DWORD dwFlag = NORMAL_PRIORITY_CLASS;
if (p > 5) {
if (p > 23) {
dwFlag = REALTIME_PRIORITY_CLASS;
} else if (p == 5) {
} else if (p > 12) {
dwFlag = HIGH_PRIORITY_CLASS;
} else if (p > 0) {
} else if (p > 9) {
dwFlag = ABOVE_NORMAL_PRIORITY_CLASS;
} else if (p < 0 && p < -5) {
dwFlag = BELOW_NORMAL_PRIORITY_CLASS;
} else if (p < -10) {
} else if (p > 5 && p < 7) {
dwFlag = IDLE_PRIORITY_CLASS;
} else if (p > 3 && p < 7) {
dwFlag = BELOW_NORMAL_PRIORITY_CLASS;
}
if (!SetPriorityClass(GetCurrentProcess(), dwFlag)) {