diff options
author | Paul Selkirk <paul@psgd.org> | 2018-04-19 16:30:22 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2018-04-19 16:30:22 -0400 |
commit | 46fbe98ffe13484b2fc5e8cfe1e67a84f6be84da (patch) | |
tree | 47f3dea06110954512467234897c990a404e0706 /task.c | |
parent | 1ceb5752a309397799e9ef4a99ff1b327fc42a8d (diff) |
Reconstruct the hashsig hash tree(s) on device restart.
This can take long enough (several minutes for h=10) that we do it in a
background task, which is then converted to an RPC dispatch task.
Also add a very limited form of free(), to free the topmost allocation in
the sdram "heap". I don't want to deal with real heap management, but I do
want to be able to recover memory upon deleting a hashsig key, if it's
easy to do so.
Diffstat (limited to 'task.c')
-rw-r--r-- | task.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -119,6 +119,24 @@ tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size_t stac return t; } +/* Reinitalize the current task. + * NOTE: This will destroy any state in the running task. + * DO NOT CALL THIS UNLESS YOU ARE REALLY SURE THAT'S WHAT YOU WANT TO DO. + */ +void task_mod(char *name, funcp_t func, void *cookie) +{ + tcb_t *t = cur_task; + t->name = name; + t->func = func; + t->cookie = cookie; + t->state = TASK_INIT; + t->stack_ptr = t->stack_base + t->stack_len; + for (uint32_t *p = (uint32_t *)t->stack_base; p < (uint32_t *)t->stack_ptr; ++p) + *p = STACK_GUARD_WORD; + __set_MSP((uint32_t)cur_task->stack_ptr); + task_yield(); +} + /* Set the idle hook function pointer. * * This function is called repeatedly when the system is idle (there are @@ -200,11 +218,11 @@ void task_yield(void) /* If there are no other runnable tasks (and cur_task is runnable), * we don't need to context-switch. */ - if (next == cur_task) + if (next == cur_task && cur_task->state != TASK_INIT) return; /* Save current context, if there is one. */ - if (cur_task != NULL) { + if (cur_task != NULL && cur_task->state != TASK_INIT) { __asm("push {r0-r12, lr}"); cur_task->stack_ptr = (void *)__get_MSP(); |