File: ThreadPrioWindows.cpp

package info (click to toggle)
soapyremote 0.5.2-4.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 608 kB
  • sloc: cpp: 7,724; makefile: 13
file content (28 lines) | stat: -rw-r--r-- 935 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) 2015-2015 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#include "ThreadPrioHelper.hpp"
#include <windows.h>

std::string setThreadPrio(const double prio)
{
    int nPriority(THREAD_PRIORITY_NORMAL);

    if (prio > 0)
    {
        if      (prio > +0.75) nPriority = THREAD_PRIORITY_TIME_CRITICAL;
        else if (prio > +0.50) nPriority = THREAD_PRIORITY_HIGHEST;
        else if (prio > +0.25) nPriority = THREAD_PRIORITY_ABOVE_NORMAL;
        else                   nPriority = THREAD_PRIORITY_NORMAL;
    }
    else
    {
        if      (prio < -0.75) nPriority = THREAD_PRIORITY_IDLE;
        else if (prio < -0.50) nPriority = THREAD_PRIORITY_LOWEST;
        else if (prio < -0.25) nPriority = THREAD_PRIORITY_BELOW_NORMAL;
        else                   nPriority = THREAD_PRIORITY_NORMAL;
    }

    if (SetThreadPriority(GetCurrentThread(), nPriority)) return "";
    return "SetThreadPriority() fail";
}