Skip to content

Commit

Permalink
export hloop_process_events for (ithewei#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ithewei committed Apr 13, 2023
1 parent 2641e14 commit 1190383
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions event/hloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ static int hloop_process_pendings(hloop_t* loop) {
}

// hloop_process_ios -> hloop_process_timers -> hloop_process_idles -> hloop_process_pendings
static int hloop_process_events(hloop_t* loop) {
int hloop_process_events(hloop_t* loop, int timeout_ms) {
// ios -> timers -> idles
int nios, ntimers, nidles;
nios = ntimers = nidles = 0;

// calc blocktime
int32_t blocktime_ms = HLOOP_MAX_BLOCK_TIME;
int32_t blocktime_ms = timeout_ms;
if (loop->ntimers) {
hloop_update_time(loop);
int64_t blocktime_us = blocktime_ms * 1000;
Expand All @@ -157,7 +157,7 @@ static int hloop_process_events(hloop_t* loop) {
}
if (blocktime_us <= 0) goto process_timers;
blocktime_ms = blocktime_us / 1000 + 1;
blocktime_ms = MIN(blocktime_ms, HLOOP_MAX_BLOCK_TIME);
blocktime_ms = MIN(blocktime_ms, timeout_ms);
}

if (loop->nios) {
Expand Down Expand Up @@ -455,7 +455,7 @@ int hloop_run(hloop_t* loop) {
loop->nactives <= loop->intern_nevents) {
break;
}
hloop_process_events(loop);
hloop_process_events(loop, HLOOP_MAX_BLOCK_TIME);
if (loop->flags & HLOOP_FLAG_RUN_ONCE) {
break;
}
Expand Down
2 changes: 2 additions & 0 deletions event/hloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ HV_EXPORT hloop_t* hloop_new(int flags DEFAULT(HLOOP_FLAG_AUTO_FREE));
// WARN: Forbid to call hloop_free if HLOOP_FLAG_AUTO_FREE set.
HV_EXPORT void hloop_free(hloop_t** pp);

HV_EXPORT int hloop_process_events(hloop_t* loop, int timeout_ms DEFAULT(1));

// NOTE: when no active events, loop will quit if HLOOP_FLAG_QUIT_WHEN_NO_ACTIVE_EVENTS set.
HV_EXPORT int hloop_run(hloop_t* loop);
// NOTE: hloop_stop called in loop-thread just set flag to quit in next loop,
Expand Down

0 comments on commit 1190383

Please sign in to comment.