Skip to content

Commit 1cc58de

Browse files
committed
Set the FreeBSD clock types
Dispatch passes everything through in nanoseconds, but the default time on FreeBSD is in milliseconds, resulting in delays taking a million times longer than expected. This stands out most with `Task.sleep`, where a 2 second sleep would take hours. By setting the EVFILT_TIMER filter flag to use nanoseconds, we get the expected delay. Also sets up the absolute time flag. The spelling on FreeBSD is `NOTE_ABSTIME` instead of `NOTE_ABSOLUTE`.
1 parent 4029973 commit 1cc58de

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/event/event_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@
118118

119119
// FreeBSD's kevent does not support those
120120
# ifndef NOTE_ABSOLUTE
121-
# define NOTE_ABSOLUTE 0
121+
# ifdef NOTE_ABSTIME
122+
# define NOTE_ABSOLUTE NOTE_ABSTIME
123+
# else
124+
# define NOTE_ABSOLUTE 0
125+
# endif
122126
# endif
123127
# ifndef NOTE_EXITSTATUS
124128
# define NOTE_EXITSTATUS 0

src/event/event_kevent.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ DISPATCH_STATIC_GLOBAL(struct dispatch_muxnote_bucket_s _dispatch_sources[DSL_HA
5050
#define DISPATCH_NOTE_CLOCK_WALL NOTE_NSECONDS | NOTE_MACH_CONTINUOUS_TIME
5151
#define DISPATCH_NOTE_CLOCK_MONOTONIC NOTE_MACHTIME | NOTE_MACH_CONTINUOUS_TIME
5252
#define DISPATCH_NOTE_CLOCK_UPTIME NOTE_MACHTIME
53+
#elif __FreeBSD__
54+
#define DISPATCH_NOTE_CLOCK_WALL NOTE_NSECONDS
55+
#define DISPATCH_NOTE_CLOCK_MONOTONIC NOTE_NSECONDS
56+
#define DISPATCH_NOTE_CLOCK_UPTIME NOTE_NSECONDS
5357
#else
5458
#define DISPATCH_NOTE_CLOCK_WALL 0
5559
#define DISPATCH_NOTE_CLOCK_MONOTONIC 0

0 commit comments

Comments
 (0)