This source file includes following definitions.
- halide_start_clock
- halide_current_time_ns
- halide_sleep_ms
#include "HalideRuntime.h"
#ifndef __clockid_t_defined
#define __clockid_t_defined 1
typedef int32_t clockid_t;
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID 3
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_REALTIME_COARSE 5
#define CLOCK_MONOTONIC_COARSE 6
#define CLOCK_BOOTTIME 7
#define CLOCK_REALTIME_ALARM 8
#define CLOCK_BOOTTIME_ALARM 9
#endif
#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC
struct timespec {
long tv_sec;
long tv_nsec;
};
#endif
extern "C" {
WEAK bool halide_reference_clock_inited = false;
WEAK timespec halide_reference_clock;
#ifndef SYS_CLOCK_GETTIME
#ifdef BITS_64
#define SYS_CLOCK_GETTIME 228
#endif
#ifdef BITS_32
#define SYS_CLOCK_GETTIME 265
#endif
#endif
extern int syscall(int num, ...);
WEAK int halide_start_clock(void *user_context) {
if (!halide_reference_clock_inited) {
syscall(SYS_CLOCK_GETTIME, CLOCK_REALTIME, &halide_reference_clock);
halide_reference_clock_inited = true;
}
return 0;
}
WEAK int64_t halide_current_time_ns(void *user_context) {
timespec now;
syscall(SYS_CLOCK_GETTIME, CLOCK_REALTIME, &now);
int64_t d = int64_t(now.tv_sec - halide_reference_clock.tv_sec)*1000000000;
int64_t nd = (now.tv_nsec - halide_reference_clock.tv_nsec);
return d + nd;
}
extern int usleep(int);
WEAK void halide_sleep_ms(void *user_context, int ms) {
usleep(ms * 1000);
}
}