43 lines · c
1/*2 * ompt-signal.h -- Header providing low-level synchronization for tests3 */4 5//===----------------------------------------------------------------------===//6//7// The LLVM Compiler Infrastructure8//9// This file is a copy from runtime/test/ompt/10//11//===----------------------------------------------------------------------===//12 13#if defined(WIN32) || defined(_WIN32)14#include <windows.h>15#define delay() Sleep(1);16#else17#include <unistd.h>18#define delay(t) usleep(t);19#endif20 21// These functions are used to provide a signal-wait mechanism to enforce22// expected scheduling for the test cases.23// Conditional variable (s) needs to be shared! Initialize to 024 25#define OMPT_SIGNAL(s) ompt_signal(&s)26// inline27void ompt_signal(int *s) {28#pragma omp atomic29 (*s)++;30}31 32#define OMPT_WAIT(s, v) ompt_wait(&s, v)33// wait for s >= v34// inline35void ompt_wait(int *s, int v) {36 int wait = 0;37 do {38 delay(10);39#pragma omp atomic read40 wait = (*s);41 } while (wait < v);42}43