forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 60
/
ioprio.h
63 lines (52 loc) · 1.38 KB
/
ioprio.h
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2016 Satoshi Nakamoto
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_UTIL_IOPRIO_H
#define BITCOIN_UTIL_IOPRIO_H
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <util/system.h>
#if defined(HAVE_IOPRIO_SYSCALL) || defined(HAVE_IOPOLICY)
int ioprio_get();
int ioprio_set(int ioprio);
int ioprio_set_idle();
class ioprio_idler {
private:
int orig;
public:
ioprio_idler(const bool actually_idle) {
if (!actually_idle) {
orig = -1;
return;
}
orig = ioprio_get();
if (orig == -1) {
return;
}
if (ioprio_set_idle() == -1) {
orig = -1;
}
}
~ioprio_idler() {
if (orig == -1) {
return;
}
if (ioprio_set(orig) == -1) {
LogPrintf("failed to restore ioprio\n");
}
}
};
#define IOPRIO_IDLER(actually_idle) ioprio_idler ioprio_idler_(actually_idle)
#else
#define ioprio_get() ((void)-1)
#define ioprio_set(ioprio) ((void)-1)
#define ioprio_set_idle() ((void)-1)
#define IOPRIO_IDLER(actually_idle) (void)actually_idle;
#endif
#ifdef HAVE_WINDOWS_IOPRIO
bool ioprio_set_file_idle(FILE *);
#else
#define ioprio_set_file_idle(f) ((void)false)
#endif
#endif // BITCOIN_UTIL_IOPRIO_H