diff options
Diffstat (limited to 'openmp/testsuite/omp_my_sleep.h')
-rw-r--r-- | openmp/testsuite/omp_my_sleep.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/openmp/testsuite/omp_my_sleep.h b/openmp/testsuite/omp_my_sleep.h new file mode 100644 index 00000000000..8390a5b899f --- /dev/null +++ b/openmp/testsuite/omp_my_sleep.h @@ -0,0 +1,35 @@ +#ifndef MY_SLEEP_H +#define MY_SLEEP_H + +#include <stdio.h> +#include<stdlib.h> +#include<unistd.h> + +#include <sys/times.h> +#include <sys/time.h> +#include <time.h> +#include <errno.h> + +/*! Utility function to have a sleep function with better resolution and which only stops one thread. */ + +static void my_sleep(double sleeptime){ + struct timeval tv; + struct timezone tzp; + double start; + double real; + if(gettimeofday(&tv,&tzp)!=0) { + perror("get_time: "); + exit(-1); + } + start = (double)tv.tv_sec + ((double)tv.tv_usec/1000000.0); + real=start; + while( (real-start)<sleeptime){ + if(gettimeofday(&tv,&tzp)!=0) { + perror("get_time: "); + exit(-1); + } + real = (double)tv.tv_sec + ((double)tv.tv_usec/1000000.0); + } +} + +#endif |