LLVM OpenMP 20.0.0git
omp_my_sleep.h
Go to the documentation of this file.
1#ifndef MY_SLEEP_H
2#define MY_SLEEP_H
3
4/*! Utility function to have a sleep function with better resolution and
5 * which only stops one thread. */
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <errno.h>
10#include <time.h>
11
12#if defined(_WIN32)
13# include <windows.h>
14// Windows version of my_sleep() function
15static void my_sleep(double sleeptime) {
16 DWORD ms = (DWORD) (sleeptime * 1000.0);
17 Sleep(ms);
18}
19
20
21#else // _WIN32
22
23// Unices version of my_sleep() function
24static void my_sleep(double sleeptime) {
25 struct timespec ts;
26 ts.tv_sec = (time_t)sleeptime;
27 ts.tv_nsec = (long)((sleeptime - (double)ts.tv_sec) * 1E9);
28 nanosleep(&ts, NULL);
29}
30
31#endif // _WIN32
32
33#endif // MY_SLEEP_H
static void my_sleep(double sleeptime)
Utility function to have a sleep function with better resolution and which only stops one thread.
Definition: omp_my_sleep.h:24