aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/nice.cpp
blob: 080e675e751489f0c2b079e91b697fb13d0ae7d8 (plain) (blame)
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
29
30
31
32
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "nice.h"

#include <unistd.h>
#include <algorithm>

namespace vespalib {

namespace {

void set_nice_value(double how_nice) {
    if (how_nice > 0.0) {
#ifndef __APPLE__
        int now = nice(0);
        int max = 19;
        int max_inc = (max - now);
        [[maybe_unused]] auto nice_result = nice(std::min(max_inc, int(how_nice * (max_inc + 1))));
#endif
    }
}

}

Runnable::init_fun_t be_nice(Runnable::init_fun_t init, double how_nice) {
    return [init,how_nice](Runnable &target) {
        set_nice_value(how_nice);
        return init(target);
    };
}

} // namespace