Skip to content

Commit

Permalink
scheduler: new wrapper for timers to consume notification byte
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Aug 19, 2024
1 parent b5eeda5 commit 8a1d830
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/flb_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ static inline int consume_byte(flb_pipefd_t fd)

/* We need to consume the byte */
ret = flb_pipe_r(fd, &val, sizeof(val));
#if defined(FLB_EVENT_LOOP_KQUEUE) || defined(MK_EVENT_LOOP_KQUEUE)
//#if defined(__APPLE__) || __FreeBSD__ >= 12

/* ref: https://github.com/fluent/fluent-bit/pull/2463 */
#if defined(__APPLE__) || __FreeBSD__ >= 12
if (ret < 0) {
#else
if (ret <= 0) {
Expand Down Expand Up @@ -384,6 +385,23 @@ int flb_sched_request_invalidate(struct flb_config *config, void *data)
return -1;
}

/*
* Depending on the backend that provides the timer, most of the time except
* on event loops based on 'kqueue', we need to read the notification byte, which
* usually comes from a file descriptor registered through the backend based on
* epoll(), select() or poll().
*
* If we are NOT using kequeue, just read(2) the byte.
*/
static inline int timer_consume_byte(int fd)
{
#ifndef FLB_EVENT_LOOP_KQUEUE
return consume_byte(fd);
#endif

return 0;
}

/* Handle a timeout event set by a previous flb_sched_request_create(...) */
int flb_sched_event_handler(struct flb_config *config, struct mk_event *event)
{
Expand Down Expand Up @@ -412,21 +430,17 @@ int flb_sched_event_handler(struct flb_config *config, struct mk_event *event)
}
else if (timer->type == FLB_SCHED_TIMER_FRAME) {
sched = timer->data;

#if defined(FLB_EVENT_LOOP_KQUEUE) || defined(MK_EVENT_LOOP_KQUEUE)
//#ifndef __APPLE__
consume_byte(sched->frame_fd);
#endif
timer_consume_byte(sched->frame_fd);
schedule_request_promote(sched);
}
else if (timer->type == FLB_SCHED_TIMER_CB_ONESHOT) {
consume_byte(timer->timer_fd);
timer_consume_byte(timer->timer_fd);
flb_sched_timer_cb_disable(timer);
timer->cb(config, timer->data);
flb_sched_timer_cb_destroy(timer);
}
else if (timer->type == FLB_SCHED_TIMER_CB_PERM) {
consume_byte(timer->timer_fd);
timer_consume_byte(timer->timer_fd);
timer->cb(config, timer->data);
}

Expand Down

0 comments on commit 8a1d830

Please sign in to comment.