summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/os/tinysleep.c
blob: f04cbdadcb98d06017e730ce36f5bda17740bdec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// SPDX-License-Identifier: GPL-3.0-or-later

#include "../libnetdata.h"

#ifdef OS_WINDOWS
#include <windows.h>

void tinysleep(void) {
    // Improve the system timer resolution to 1 ms
    timeBeginPeriod(1);

    // Sleep for the desired duration
    Sleep(1);

    // Reset the system timer resolution
    timeEndPeriod(1);
}
#else
void tinysleep(void) {
    static const struct timespec ns = { .tv_sec = 0, .tv_nsec = 1 };
    nanosleep(&ns, NULL);
}
#endif