From 18c297c5f88681236aec2537f7e7f2d9b50fcd7e Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Tue, 25 Apr 2017 22:14:49 -0400 Subject: adapt to the new experimental tasking system --- core.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'core.c') diff --git a/core.c b/core.c index cbc3bc2..1c247f0 100644 --- a/core.c +++ b/core.c @@ -213,31 +213,39 @@ hal_error_t hal_core_alloc(const char *name, hal_core_t **pcore) if (name == NULL) name = core->info.name; - hal_critical_section_start(); if (core != NULL) { /* if we can reallocate the same core, do it now */ if (!core->busy) { + hal_critical_section_start(); core->busy = 1; hal_critical_section_end(); return HAL_OK; } /* else fall through to search */ } - for (core = hal_core_iterate(NULL); core != NULL; core = core->next) { - if (name_matches(core, name)) { - if (core->busy) { - err = HAL_ERROR_CORE_BUSY; - continue; - } - else { - err = HAL_OK; - *pcore = core; - core->busy = 1; - break; + + while (1) { + hal_critical_section_start(); + for (core = hal_core_iterate(NULL); core != NULL; core = core->next) { + if (name_matches(core, name)) { + if (core->busy) { + err = HAL_ERROR_CORE_BUSY; + continue; + } + else { + err = HAL_OK; + *pcore = core; + core->busy = 1; + break; + } } } - } - hal_critical_section_end(); + hal_critical_section_end(); + if (err == HAL_ERROR_CORE_BUSY) + hal_task_yield(); + else + break; + } return err; } @@ -248,6 +256,7 @@ void hal_core_free(hal_core_t *core) hal_critical_section_start(); core->busy = 0; hal_critical_section_end(); + hal_task_yield(); } } -- cgit v1.2.3