[Cryptech-Commits] [sw/stm32] branch no-rtos updated: Add minimal mutexes to the minimal tasking system

git at cryptech.is git at cryptech.is
Sun Apr 30 03:25:16 UTC 2017


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch no-rtos
in repository sw/stm32.

The following commit(s) were added to refs/heads/no-rtos by this push:
     new 73b784e  Add minimal mutexes to the minimal tasking system
73b784e is described below

commit 73b784eac101085b8734d2188ae59b5295a80839
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Sat Apr 29 23:24:37 2017 -0400

    Add minimal mutexes to the minimal tasking system
---
 projects/hsm/hsm.c |  6 ++++++
 task.c             | 13 +++++++++++++
 task.h             |  5 +++++
 3 files changed, 24 insertions(+)

diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c
index a683b7f..60fa2bd 100644
--- a/projects/hsm/hsm.c
+++ b/projects/hsm/hsm.c
@@ -380,6 +380,12 @@ void hal_task_yield(void)
     task_yield();
 }
 
+/* A mutex to arbitrate concurrent access to the keystore.
+ */
+task_mutex_t ks_mutex = { 0 };
+void hal_ks_lock(void)   { task_mutex_lock(&ks_mutex); }
+void hal_ks_unlock(void) { task_mutex_unlock(&ks_mutex); }
+
 /* The main task. This does all the setup, and the worker tasks handle
  * the rest.
  */
diff --git a/task.c b/task.c
index 600b679..bc6eded 100644
--- a/task.c
+++ b/task.c
@@ -326,3 +326,16 @@ void task_delay(uint32_t delay)
     while ((HAL_GetTick() - tickstart) < delay)
 	task_yield();
 }
+
+void task_mutex_lock(task_mutex_t *mutex)
+{
+    while (mutex->locked)
+	task_yield();
+    mutex->locked = 1;
+}
+
+void task_mutex_unlock(task_mutex_t *mutex)
+{
+    if (mutex != NULL)
+	mutex->locked = 0;
+}
diff --git a/task.h b/task.h
index 9178c2d..f4d4260 100644
--- a/task.h
+++ b/task.h
@@ -45,6 +45,8 @@ typedef enum task_state {
 
 typedef struct task_cb tcb_t;
 
+typedef struct { unsigned locked; } task_mutex_t;
+
 typedef void (*funcp_t)(void);
 
 extern tcb_t *task_add(char *name, funcp_t func, void *cookie, void *stack, size_t stack_len);
@@ -67,4 +69,7 @@ extern tcb_t *task_iterate(tcb_t *t);
 
 extern void task_delay(uint32_t delay);
 
+extern void task_mutex_lock(task_mutex_t *mutex);
+extern void task_mutex_unlock(task_mutex_t *mutex);
+
 #endif /* _TASK_H_ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Commits mailing list