mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-20 16:46:14 +00:00
1. add lock function for every function
2. modify some function for crypto
This commit is contained in:
53
components/mbedtls/port/multi_thread.c
Normal file
53
components/mbedtls/port/multi_thread.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "multi_thread.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
static xSemaphoreHandle multi_thread_mutex[MUTEX_MAX_NUM];
|
||||
static int multi_thread_sig[MUTEX_MAX_NUM];
|
||||
|
||||
int multi_thread_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MUTEX_MAX_NUM; i++) {
|
||||
multi_thread_mutex[i] = xSemaphoreCreateMutex();
|
||||
if (!multi_thread_mutex[i]) {
|
||||
goto failed1;
|
||||
}
|
||||
multi_thread_sig[i] = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
failed1:
|
||||
for (i--; i >= 0; i--)
|
||||
vQueueDelete(multi_thread_mutex[i]);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void multi_thread_lock(unsigned int num)
|
||||
{
|
||||
xSemaphoreTake(multi_thread_mutex[num], portMAX_DELAY);
|
||||
}
|
||||
|
||||
void multi_thread_unlock(unsigned int num)
|
||||
{
|
||||
xSemaphoreGive(multi_thread_mutex[num]);
|
||||
}
|
||||
|
||||
void multi_thread_take(unsigned int num)
|
||||
{
|
||||
multi_thread_sig[num]++;
|
||||
}
|
||||
|
||||
void multi_thread_give(unsigned int num)
|
||||
{
|
||||
multi_thread_sig[num]--;
|
||||
}
|
||||
|
||||
bool multi_thread_is_used(num)
|
||||
{
|
||||
return (multi_thread_sig[num] != 0) ? true : false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user