mirror of
https://github.com/janet-lang/janet
synced 2025-01-27 23:54:45 +00:00
Fixing kqueue under the BSDs.
FreeBSD is the only BSD supporting ABSTIME timers, whereas the rest demand intervals. Janet operates on timestamps, which are absolute times, as per ABSTIME. The idea was to use that under FreeBSD but not the other BSDs. This commit changes that since ABSTIME breaks when the timeout supplied is for a time prior to whatever the time is now (invalid argument). We now utilize the same logic we use on the other BSDs with FreeBSD to effect interval timeouts since intervals are absolutely sometime beyond now, be it now and less than a millisecond, or more than a millisecond. This will hopefully unbreak BSD builds when running the test suite.
This commit is contained in:
parent
038ca1b9ca
commit
e1ec0d13ae
@ -1586,22 +1586,17 @@ void janet_ev_deinit(void) {
|
|||||||
#define JANET_KQUEUE_MIN_INTERVAL 0
|
#define JANET_KQUEUE_MIN_INTERVAL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
|
||||||
#define JANET_KQUEUE_TS(timestamp) (timestamp)
|
|
||||||
#else
|
|
||||||
/* NOTE:
|
/* NOTE:
|
||||||
* NetBSD and OpenBSD expect things are always intervals, so fake that we have
|
* NetBSD and OpenBSD expect things are always intervals, and FreeBSD doesn't
|
||||||
* abstime capability by changing how a timestamp is used in all kqueue calls
|
* like an ABSTIME in the past so just use intervals always. Introduces a
|
||||||
* and defining absent macros. Additionally NetBSD expects intervals be
|
* calculation to determine the minimum timeout per timeout requested of
|
||||||
* greater than 1 millisecond, so correct all intervals to be at least 1
|
* kqueue. Also note that NetBSD doesn't accept timeout intervals less than 1
|
||||||
* millisecond under NetBSD. */
|
* millisecond, so correct all intervals on that platform to be at least 1
|
||||||
|
* millisecond.*/
|
||||||
JanetTimestamp fix_interval(const JanetTimestamp ts) {
|
JanetTimestamp fix_interval(const JanetTimestamp ts) {
|
||||||
return ts >= JANET_KQUEUE_MIN_INTERVAL ? ts : JANET_KQUEUE_MIN_INTERVAL;
|
return ts >= JANET_KQUEUE_MIN_INTERVAL ? ts : JANET_KQUEUE_MIN_INTERVAL;
|
||||||
}
|
}
|
||||||
#define JANET_KQUEUE_TS(timestamp) (fix_interval((timestamp - ts_now())))
|
#define JANET_KQUEUE_TS(timestamp) (fix_interval((timestamp - ts_now())))
|
||||||
#define NOTE_MSECONDS 0
|
|
||||||
#define NOTE_ABSTIME 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* TODO: make this available be we using kqueue or epoll, instead of
|
/* TODO: make this available be we using kqueue or epoll, instead of
|
||||||
@ -1692,7 +1687,7 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
|
|||||||
JANET_KQUEUE_TIMER_IDENT,
|
JANET_KQUEUE_TIMER_IDENT,
|
||||||
EVFILT_TIMER,
|
EVFILT_TIMER,
|
||||||
JANET_KQUEUE_TF,
|
JANET_KQUEUE_TF,
|
||||||
NOTE_MSECONDS | NOTE_ABSTIME,
|
0,
|
||||||
JANET_KQUEUE_TS(timeout), &janet_vm.timer);
|
JANET_KQUEUE_TS(timeout), &janet_vm.timer);
|
||||||
add_kqueue_events(&timer, 1);
|
add_kqueue_events(&timer, 1);
|
||||||
}
|
}
|
||||||
@ -1757,7 +1752,7 @@ void janet_ev_init(void) {
|
|||||||
JANET_KQUEUE_TIMER_IDENT,
|
JANET_KQUEUE_TIMER_IDENT,
|
||||||
EVFILT_TIMER,
|
EVFILT_TIMER,
|
||||||
JANET_KQUEUE_TF,
|
JANET_KQUEUE_TF,
|
||||||
NOTE_MSECONDS, JANET_KQUEUE_MIN_INTERVAL, &janet_vm.timer);
|
0, JANET_KQUEUE_MIN_INTERVAL, &janet_vm.timer);
|
||||||
EV_SETx(&events[1], janet_vm.selfpipe[0], EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, janet_vm.selfpipe);
|
EV_SETx(&events[1], janet_vm.selfpipe[0], EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, janet_vm.selfpipe);
|
||||||
add_kqueue_events(events, 2);
|
add_kqueue_events(events, 2);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user