Skip to content

Commit

Permalink
[Minor] Add method ev_now_update_if_cheap
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Nov 1, 2019
1 parent ab2d0a0 commit 0194245
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contrib/libev/ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,7 @@ static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */
static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
static EV_ATOMIC_T monotinic_clock_id;
#endif
static EV_ATOMIC_T have_cheap_timer = 0;

#ifndef EV_FD_TO_WIN32_HANDLE
# define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd)
Expand Down Expand Up @@ -2898,6 +2899,7 @@ loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
!clock_getres ((id), &ts)) { \
if (ts.tv_sec == 0 && ts.tv_nsec < 10ULL * 1000000) { \
monotinic_clock_id = (id); \
have_cheap_timer = 1; \
} \
} \
} while(0)
Expand Down Expand Up @@ -3808,6 +3810,12 @@ ev_now_update (EV_P) EV_NOEXCEPT
time_update (EV_A_ 1e100);
}

void
ev_now_update_if_cheap (EV_P) EV_NOEXCEPT
{
if (have_cheap_timer) time_update (EV_A_ 1e100);
}

void
ev_suspend (EV_P) EV_NOEXCEPT
{
Expand Down
5 changes: 5 additions & 0 deletions contrib/libev/ev.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ EV_API_DECL void ev_loop_fork (EV_P) EV_NOEXCEPT;
EV_API_DECL unsigned int ev_backend (EV_P) EV_NOEXCEPT; /* backend in use by loop */

EV_API_DECL void ev_now_update (EV_P) EV_NOEXCEPT; /* update event loop time */
/*
* Same as ev_now_update, but will update time merely if cheap (coarse) timers
* are used in system.
*/
EV_API_DECL void ev_now_update_if_cheap (EV_P) EV_NOEXCEPT;

#if EV_WALK_ENABLE
/* walk (almost) all watchers in the loop of a given type, invoking the */
Expand Down

0 comments on commit 0194245

Please sign in to comment.