Skip to content

Commit

Permalink
use max/min from mathutils
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Aug 3, 2024
1 parent 4cac693 commit 3939bbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ww/eventloop/event/hevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void hio_set_write_timeout(hio_t* io, int timeout_ms) {

static void __keepalive_timeout_cb(htimer_t* timer) {
hio_t* io = (hio_t*)timer->privdata;
uint64_t last_rw_hrtime = MAX(io->last_read_hrtime, io->last_write_hrtime);
uint64_t last_rw_hrtime = max(io->last_read_hrtime, io->last_write_hrtime);
uint64_t inactive_ms = (io->loop->cur_hrtime - last_rw_hrtime) / 1000;
if (inactive_ms + 100 < (uint64_t)io->keepalive_timeout) {
htimer_reset(io->keepalive_timer, io->keepalive_timeout - inactive_ms);
Expand Down
8 changes: 4 additions & 4 deletions ww/eventloop/event/hloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ int hloop_process_events(hloop_t* loop, int timeout_ms) {
int64_t blocktime_us = blocktime_ms * 1000;
if (loop->timers.root) {
int64_t min_timeout = TIMER_ENTRY(loop->timers.root)->next_timeout - loop->cur_hrtime;
blocktime_us = MIN(blocktime_us, min_timeout);
blocktime_us = min(blocktime_us, min_timeout);
}
if (loop->realtimers.root) {
int64_t min_timeout = TIMER_ENTRY(loop->realtimers.root)->next_timeout - hloop_now_us(loop);
blocktime_us = MIN(blocktime_us, min_timeout);
blocktime_us = min(blocktime_us, min_timeout);
}
if (blocktime_us < 0) goto process_timers;
blocktime_ms = blocktime_us / 1000 + 1;
blocktime_ms = MIN(blocktime_ms, timeout_ms);
blocktime_ms = min(blocktime_ms, timeout_ms);
}

if (loop->nios) {
Expand Down Expand Up @@ -717,7 +717,7 @@ const char* hio_engine(void) {
static inline hio_t* __hio_get(hloop_t* loop, int fd) {
if (fd >= (int)loop->ios.maxsize) {
int newsize = ceil2e(fd);
newsize = MAX(newsize, IO_ARRAY_INIT_SIZE);
newsize = max(newsize, IO_ARRAY_INIT_SIZE);
io_array_resize(&loop->ios, newsize > fd ? newsize : 2 * fd);
}
return loop->ios.ptr[fd];
Expand Down
5 changes: 3 additions & 2 deletions ww/eventloop/event/hloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "hexport.h"
#include "hplatform.h"
#include "hdef.h"
#include "utils/mathutils.h"
#include "buffer_pool.h"

typedef struct hloop_s hloop_t;
Expand Down Expand Up @@ -471,8 +472,8 @@ HV_INLINE uint32_t reconn_setting_calc_delay(reconn_setting_t* reconn) {
// exponential
reconn->cur_delay *= reconn->delay_policy;
}
reconn->cur_delay = MAX(reconn->cur_delay, reconn->min_delay);
reconn->cur_delay = MIN(reconn->cur_delay, reconn->max_delay);
reconn->cur_delay = max(reconn->cur_delay, reconn->min_delay);
reconn->cur_delay = min(reconn->cur_delay, reconn->max_delay);
return reconn->cur_delay;
}

Expand Down

0 comments on commit 3939bbd

Please sign in to comment.