Skip to content

Commit

Permalink
Merge pull request #52 from PDXostc/undo-dstc_get_timeout_msec-api-break
Browse files Browse the repository at this point in the history
Undid API breaking  dstc_get_timeout_msec_rel() change
  • Loading branch information
magnusfeuer authored Jul 12, 2019
2 parents f6670d4 + d3af7ee commit a95fa54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
33 changes: 19 additions & 14 deletions dstc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dstc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit a95fa54

Please sign in to comment.