diff options
author | Rob Austein <sra@hactrn.net> | 2017-02-02 14:03:18 -0500 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2017-02-02 14:03:18 -0500 |
commit | 6a6cc04dda8f613134ae5b30b702de3f1a4dff95 (patch) | |
tree | 19a470e43f453392d3f48a7439437698bbcd084b /rpc_misc.c | |
parent | 9ec81408c25207149d8b3bfcfc80faf1c8ff0811 (diff) |
Add locking around keystore operations.
Diffstat (limited to 'rpc_misc.c')
-rw-r--r-- | rpc_misc.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -103,24 +103,32 @@ static client_slot_t client_handle[HAL_STATIC_CLIENT_STATE_BLOCKS]; static inline client_slot_t *alloc_slot(void) { + client_slot_t *slot = NULL; + hal_critical_section_start(); + #if HAL_STATIC_CLIENT_STATE_BLOCKS > 0 - for (int i = 0; i < sizeof(client_handle)/sizeof(*client_handle); i++) + for (int i = 0; slot == NULL && i < sizeof(client_handle)/sizeof(*client_handle); i++) if (client_handle[i].logged_in == HAL_USER_NONE) - return &client_handle[i]; + slot = &client_handle[i]; #endif - return NULL; + hal_critical_section_end(); + return slot; } static inline client_slot_t *find_handle(const hal_client_handle_t handle) { + client_slot_t *slot = NULL; + hal_critical_section_start(); + #if HAL_STATIC_CLIENT_STATE_BLOCKS > 0 - for (int i = 0; i < sizeof(client_handle)/sizeof(*client_handle); i++) + for (int i = 0; slot == NULL && i < sizeof(client_handle)/sizeof(*client_handle); i++) if (client_handle[i].logged_in != HAL_USER_NONE && client_handle[i].handle.handle == handle.handle) - return &client_handle[i]; + slot = &client_handle[i]; #endif - return NULL; + hal_critical_section_end(); + return slot; } static hal_error_t login(const hal_client_handle_t client, |