iopriority.cmake raw
1 # Copyright (c) 2025-present The Limenka Knots developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or https://opensource.org/license/mit/.
4
5 include(CheckCXXSourceCompiles)
6
7 check_cxx_source_compiles([[
8 #include <sys/resource.h>
9
10 int main()
11 {
12 int x = getiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD);
13 setiopolicy_np(IOPOL_TYPE_DISK, IOPOL_SCOPE_THREAD, x);
14 return x;
15 }
16 ]] HAVE_IOPOLICY
17 )
18
19 check_cxx_source_compiles([[
20 #define _GNU_SOURCE
21 #include <unistd.h>
22 #include <sys/syscall.h>
23
24 int main()
25 {
26 int x = syscall(SYS_ioprio_get, 1, 0);
27 syscall(SYS_ioprio_set, 1, 0, x);
28 return x;
29 }
30 ]] HAVE_IOPRIO_SYSCALL
31 )
32
33 check_cxx_source_compiles([[
34 #define _WIN32_WINNT 0x0601
35 #include <windows.h>
36 #include <io.h>
37 #include <stddef.h>
38 #include <stdint.h>
39 #include <stdio.h>
40
41 int main()
42 {
43 FILE_IO_PRIORITY_HINT_INFO priorityHint = {
44 .PriorityHint = IoPriorityHintLow,
45 };
46 FILE * const F = fopen("test", "r");
47 intptr_t osfhandle = _get_osfhandle(_fileno(F));
48 if (osfhandle == (intptr_t)INVALID_HANDLE_VALUE) osfhandle = 0;
49 HANDLE hFile = (HANDLE)osfhandle;
50
51 bool rv = SetFileInformationByHandle(hFile, FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
52 return rv;
53 }
54 ]] HAVE_WINDOWS_IOPRIO
55 )
56