From 6bc00fda8a2eb2dd94ebf53f7b45467e104bba2a Mon Sep 17 00:00:00 2001 From: Jeremy Brodt Date: Fri, 27 Feb 2015 10:01:30 -0600 Subject: [PATCH] Improved handling of NULL condition. --- libraries/mbed/common/us_ticker_api.c | 17 ++++++++--------- libraries/mbed/hal/us_ticker_api.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libraries/mbed/common/us_ticker_api.c b/libraries/mbed/common/us_ticker_api.c index f464da1095..716e78103a 100644 --- a/libraries/mbed/common/us_ticker_api.c +++ b/libraries/mbed/common/us_ticker_api.c @@ -117,17 +117,16 @@ void us_ticker_remove_event(ticker_event_t *obj) { __enable_irq(); } -timestamp_t us_ticker_get_next_timestamp(void) { +int us_ticker_get_next_timestamp(timestamp_t *timestamp) { + int ret = 0; + + /* if head is NULL, there are no pending events */ __disable_irq(); - - if (head == NULL) { - __enable_irq(); - return 0; + if (head != NULL) { + *timestamp = head->timestamp; + ret = 1; } - - timestamp_t next_timestamp = head->timestamp; - __enable_irq(); - return next_timestamp; + return ret; } diff --git a/libraries/mbed/hal/us_ticker_api.h b/libraries/mbed/hal/us_ticker_api.h index 543c4da934..1fa93170ec 100644 --- a/libraries/mbed/hal/us_ticker_api.h +++ b/libraries/mbed/hal/us_ticker_api.h @@ -43,7 +43,7 @@ void us_ticker_irq_handler(void); void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id); void us_ticker_remove_event(ticker_event_t *obj); -timestamp_t us_ticker_get_next_timestamp(void); +int us_ticker_get_next_timestamp(timestamp_t *timestamp); #ifdef __cplusplus }