aboutsummaryrefslogtreecommitdiff
path: root/projects
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2017-02-02 14:04:21 -0500
committerRob Austein <sra@hactrn.net>2017-02-02 14:04:21 -0500
commit0345b661c6de52013788972b817320ad30b279ba (patch)
treefcad10029c2c4ff11a36e8e11d50b0f2184cbb08 /projects
parentb6e02ef2971ebc1dbe67c7417376e3657c47aa13 (diff)
Add locking around keystore operations.
Diffstat (limited to 'projects')
-rw-r--r--projects/hsm/hsm.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c
index 971d460..c2f6e0e 100644
--- a/projects/hsm/hsm.c
+++ b/projects/hsm/hsm.c
@@ -103,6 +103,15 @@ osMutexId uart_mutex;
osMutexDef(uart_mutex);
#endif
+#if NUM_RPC_TASK > 1
+/* A mutex to arbitrate concurrent access to the keystore.
+ */
+osMutexId ks_mutex;
+osMutexDef(ks_mutex);
+void hal_ks_lock(void) { osMutexWait(ks_mutex, osWaitForever); }
+void hal_ks_unlock(void) { osMutexRelease(ks_mutex); }
+#endif
+
static uint8_t uart_rx[2]; /* current character received from UART */
/* Callback for HAL_UART_Receive_DMA().
@@ -261,6 +270,8 @@ int main()
#if NUM_RPC_TASK > 1
if ((uart_mutex = osMutexCreate(osMutex(uart_mutex))) == NULL)
Error_Handler();
+ if ((ks_mutex = osMutexCreate(osMutex(ks_mutex))) == NULL)
+ Error_Handler();
#endif
if (hal_rpc_server_init() != LIBHAL_OK)