aboutsummaryrefslogtreecommitdiff
path: root/core.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2017-04-25 22:14:49 -0400
committerPaul Selkirk <paul@psgd.org>2017-04-25 22:14:49 -0400
commit18c297c5f88681236aec2537f7e7f2d9b50fcd7e (patch)
tree7dbbfa8c1f144e8c30cff8084f69f9efe47df217 /core.c
parent22a58216681df01d20cfa0a5cfc5c49d15e6c606 (diff)
adapt to the new experimental tasking system
Diffstat (limited to 'core.c')
-rw-r--r--core.c37
1 files changed, 23 insertions, 14 deletions
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();
}
}