From d3af7ee48e1e660aa1aeb0cb82a36d21bb46a276 Mon Sep 17 00:00:00 2001 From: Magnus Feuer Date: Fri, 12 Jul 2019 10:30:54 -0700 Subject: [PATCH] Undid API breaking dstc_get_timeout_msec_rel() change --- dstc.c | 33 +++++++++++++++++++-------------- dstc.h | 2 +- examples/chat/chat.c | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dstc.c b/dstc.c index 16f1431..2e2e6e6 100644 --- a/dstc.c +++ b/dstc.c @@ -776,6 +776,21 @@ static msec_timestamp_t _dstc_msec_monotonic_timestamp(struct timespec* abs_time return (msec_timestamp_t) abs_time_res->tv_sec * 1000 + abs_time_res->tv_nsec / 1000000; } +static int _dstc_get_timeout_msec_rel(msec_timestamp_t current_time) +{ + msec_timestamp_t tout = _dstc_get_next_timeout_abs(); + + if (tout == -1) + return -1; + + // Convert to relative timestamp. + tout -= current_time; + + if (tout < 0) + return 0; + + return tout + 1; +} // ctx must be set and locked static int dstc_setup_internal(dstc_context_t* ctx, @@ -1233,20 +1248,10 @@ msec_timestamp_t dstc_msec_monotonic_timestamp(void) } -int dstc_get_timeout_msec_rel(msec_timestamp_t current_time) -{ - msec_timestamp_t tout = _dstc_get_next_timeout_abs(); - - if (tout == -1) - return -1; - - // Convert to relative timestamp. - tout -= (current_time?current_time:dstc_msec_monotonic_timestamp()); - - if (tout < 0) - return 0; - return tout + 1; +int dstc_get_timeout_msec_rel(void) +{ + return _dstc_get_timeout_msec_rel(dstc_msec_monotonic_timestamp()); } static int _dstc_process_timeout(dstc_context_t* ctx) @@ -1330,7 +1335,7 @@ int dstc_process_events(int timeout_rel) } start_time = _dstc_msec_monotonic_timestamp(&abs_time); - next_dstc_timeout_rel = dstc_get_timeout_msec_rel(start_time); + next_dstc_timeout_rel = _dstc_get_timeout_msec_rel(start_time); next_dstc_timeout_abs = start_time + next_dstc_timeout_rel; // printf("Timeout_rel[%d]\n", timeout_rel); diff --git a/dstc.h b/dstc.h index 7080886..8e6e396 100644 --- a/dstc.h +++ b/dstc.h @@ -84,7 +84,7 @@ extern void dstc_process_epoll_result(struct epoll_event* event); typedef usec_timestamp_t msec_timestamp_t; extern msec_timestamp_t dstc_msec_monotonic_timestamp(void); // Return the number of milliseconds until the next timeout. -extern int dstc_get_timeout_msec_rel(msec_timestamp_t current_time); +extern int dstc_get_timeout_msec_rel(void); extern rmc_node_id_t dstc_get_node_id(void); extern uint8_t dstc_remote_function_available(void* func_ptr); diff --git a/examples/chat/chat.c b/examples/chat/chat.c index ccbf1da..03bede1 100644 --- a/examples/chat/chat.c +++ b/examples/chat/chat.c @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) // Find out when our next timeout is. // If timeout is zero, then we need to process a timeout immediately. - while (!(timeout = dstc_get_timeout_msec_rel(0))) { + while (!(timeout = dstc_get_timeout_msec_rel())) { RMC_LOG_DEBUG("Got timeout in dstc_get_timeout_msec_rel()"); dstc_process_timeout(); }