Skip to content

Commit

Permalink
Revert explicit equeue_tick initialisation
Browse files Browse the repository at this point in the history
equeue_tick_init raises several questions around reentrancy. Can
equeue_tick_init be called multiple times in the case we create multiple
equeues? What about equeue_tick_deinit? Should equeue_tick_init be
allowed to fail and return an error?

Also equeue_tick_init makes less sense when supporting other OSs. Mbed
seems unique in requiring a equeue_tick_init.
  • Loading branch information
geky committed Aug 4, 2019
1 parent 58113eb commit 101f830
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 0 additions & 1 deletion equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ int equeue_create_inplace(equeue_t *q, size_t size, void *buffer) {
q->slab.data = q->buffer;

q->queue = 0;
equeue_tick_init();
q->tick = equeue_tick();
q->generation = 0;
q->break_requested = false;
Expand Down
19 changes: 17 additions & 2 deletions equeue_mbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ using namespace mbed;
#include "rtos/Kernel.h"
#include "platform/mbed_os_timer.h"

void equeue_tick_init() {
static bool equeue_tick_inited = false;

static void equeue_tick_init() {
#if defined MBED_TICKLESS || !MBED_CONF_RTOS_PRESENT
mbed::internal::init_os_timer();
#endif

equeue_tick_inited = true;
}

unsigned equeue_tick() {
if (!equeue_tick_inited) {
equeue_tick_init();
}

#if defined MBED_TICKLESS || !MBED_CONF_RTOS_PRESENT
// It is not safe to call get_ms_count from ISRs, both
// because documentation says so, and because it will give
Expand Down Expand Up @@ -72,6 +80,7 @@ unsigned equeue_tick() {
#define ALIAS_TIMEOUT Timeout
#endif

static bool equeue_tick_inited = false;
static volatile unsigned equeue_minutes = 0;
static unsigned equeue_timer[
(sizeof(ALIAS_TIMER)+sizeof(unsigned)-1)/sizeof(unsigned)];
Expand All @@ -83,7 +92,7 @@ static void equeue_tick_update() {
reinterpret_cast<ALIAS_TIMER*>(equeue_timer)->reset();
}

void equeue_tick_init() {
static void equeue_tick_init() {
MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(ALIAS_TIMER),
"The equeue_timer buffer must fit the class Timer");
MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(ALIAS_TICKER),
Expand All @@ -94,9 +103,15 @@ void equeue_tick_init() {
equeue_minutes = 0;
timer->start();
ticker->attach_us(equeue_tick_update, 1000 << 16);

equeue_tick_inited = true;
}

unsigned equeue_tick() {
if (!equeue_tick_inited) {
equeue_tick_init();
}

unsigned minutes;
unsigned ms;

Expand Down
1 change: 0 additions & 1 deletion equeue_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ extern "C" {
// limited by the accuracy of this tick.
//
// Must intentionally overflow to 0 after 2^32-1
void equeue_tick_init(void);
unsigned equeue_tick(void);


Expand Down
3 changes: 0 additions & 3 deletions equeue_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@


// Tick operations
void equeue_tick_init(void) {
}

unsigned equeue_tick(void) {
struct timeval tv;
gettimeofday(&tv, 0);
Expand Down

0 comments on commit 101f830

Please sign in to comment.