@@ -74,8 +74,9 @@ static inline int _mk_event_add(struct mk_event_ctx *ctx, int fd,
7474 int ret ;
7575 int set = MK_FALSE ;
7676 struct mk_event * event ;
77- struct kevent ke = { 0 , 0 , 0 , 0 , 0 , 0 } ;
77+ struct kevent ke ;
7878
79+ EV_SET (& ke , 0 , 0 , 0 , 0 , 0 , 0 );
7980 mk_bug (ctx == NULL );
8081 mk_bug (data == NULL );
8182
@@ -142,8 +143,9 @@ static inline int _mk_event_add(struct mk_event_ctx *ctx, int fd,
142143static inline int _mk_event_del (struct mk_event_ctx * ctx , struct mk_event * event )
143144{
144145 int ret ;
145- struct kevent ke = { 0 , 0 , 0 , 0 , 0 , 0 } ;
146+ struct kevent ke ;
146147
148+ EV_SET (& ke , 0 , 0 , 0 , 0 , 0 , 0 );
147149 mk_bug (ctx == NULL );
148150 mk_bug (event == NULL );
149151
@@ -208,12 +210,16 @@ static inline int _mk_event_timeout_create(struct mk_event_ctx *ctx,
208210 event -> priority = MK_EVENT_PRIORITY_DEFAULT ;
209211 mk_list_entry_init (& event -> _priority_head );
210212
211- #if defined(NOTE_SECONDS ) && !defined(__APPLE__ )
212- /* FreeBSD or LINUX_KQUEUE defined */
213- /* TODO : high resolution interval support. */
213+ #if defined(NOTE_NSECONDS )
214+ /* The modern FreeBSD & NetBSD & OpenBSD & macOS have a high-resolution
215+ event timer. */
216+ EV_SET (& ke , fd , EVFILT_TIMER , EV_ADD , NOTE_NSECONDS ,
217+ (sec * 1000000000 ) + nsec , event );
218+ #elif defined(NOTE_SECONDS ) && !defined(__APPLE__ )
219+ /* LINUX_KQUEUE defined */
214220 EV_SET (& ke , fd , EVFILT_TIMER , EV_ADD , NOTE_SECONDS , sec , event );
215221#else
216- /* Other BSD have no NOTE_SECONDS & specify milliseconds */
222+ /* Keep backward compatibility; use the millisecond-resolution event timer. */
217223 /* Also, on macOS, NOTE_SECONDS has severe side effect that cause
218224 * performance degradation. */
219225 EV_SET (& ke , fd , EVFILT_TIMER , EV_ADD , 0 , (sec * 1000 ) + (nsec / 1000000 ) , event );
@@ -239,8 +245,9 @@ static inline int _mk_event_timeout_destroy(struct mk_event_ctx *ctx, void *data
239245{
240246 int ret ;
241247 struct mk_event * event ;
242- struct kevent ke = { 0 , 0 , 0 , 0 , 0 , 0 } ;
248+ struct kevent ke ;
243249
250+ EV_SET (& ke , 0 , 0 , 0 , 0 , 0 , 0 );
244251 if (data == NULL ) {
245252 return 0 ;
246253 }
@@ -316,14 +323,11 @@ static inline int _mk_event_channel_destroy(struct mk_event_ctx *ctx,
316323 }
317324
318325 ret = _mk_event_del (ctx , event );
319- if (ret != 0 ) {
320- return ret ;
321- }
322326
323327 close (r_fd );
324328 close (w_fd );
325329
326- return 0 ;
330+ return ret ;
327331}
328332
329333static inline int _mk_event_inject (struct mk_event_loop * loop ,
0 commit comments