21 #ifndef XAPIAN_INCLUDED_MATCHTIMEOUT_H
22 #define XAPIAN_INCLUDED_MATCHTIMEOUT_H
25 # error config.h must be included first in each C++ source file
28 #ifdef HAVE_TIMER_CREATE
38 set_timeout_flag(
union sigval sv)
40 *(
reinterpret_cast<volatile bool*
>(sv.sival_ptr)) =
true;
48 #ifndef _POSIX_MONOTONIC_CLOCK
49 const clockid_t TIMEOUT_CLOCK = CLOCK_REALTIME;
56 const clockid_t TIMEOUT_CLOCK = CLOCK_REALTIME;
57 #elif defined __CYGWIN__
65 const clockid_t TIMEOUT_CLOCK = CLOCK_REALTIME;
67 const clockid_t TIMEOUT_CLOCK = CLOCK_MONOTONIC;
73 volatile bool expired =
false;
80 explicit TimeOut(
double limit) {
82 sev.sigev_notify = SIGEV_THREAD;
83 sev.sigev_notify_function = set_timeout_flag;
84 sev.sigev_notify_attributes = NULL;
85 sev.sigev_value.sival_ptr =
86 static_cast<void*
>(
const_cast<bool*
>(&expired));
87 if (
usual(timer_create(TIMEOUT_CLOCK, &sev, &timerid) == 0)) {
88 struct itimerspec interval;
89 interval.it_interval.tv_sec = 0;
90 interval.it_interval.tv_nsec = 0;
91 RealTime::to_timespec(limit, &interval.it_value);
92 if (
usual(timer_settime(timerid, 0, &interval, NULL) == 0)) {
96 timer_delete(timerid);
99 sev.sigev_notify = SIGEV_NONE;
103 if (sev.sigev_notify != SIGEV_NONE) {
104 timer_delete(timerid);
105 sev.sigev_notify = SIGEV_NONE;
109 bool timed_out()
const {
return expired; }
Functions for handling a time or time interval in a double.
<unistd.h>, but with compat.