mbedtls threading c & pthread
Posted: Fri May 12, 2017 12:48 pm
I was trying to enable MBEDTLS_THREADING_C and MBEDTLS_THREADING_PTHREAD in:
mbedtls/port/include/mbedtls/esp_config.h
mbedtls/include/mbedtls/config.h
Resulting in a compiler error:
I saw a pthread_mutex_t defined in bt_defs.h and sys/types.h
I made a fix based on how bt_defs.h uses pthread_mutex_t that seems to fix that issue but is there another way?
I also have no clue if this fix is correct.
Threading.h:44
Threading.h:85
Threading.c:33
mbedtls/port/include/mbedtls/esp_config.h
mbedtls/include/mbedtls/config.h
Resulting in a compiler error:
Code: Select all
esp-idf/components/mbedtls/include/mbedtls/threading.h:46:2: error: 'pthread_mutex_t' does not name a type
pthread_mutex_t mutex;
I made a fix based on how bt_defs.h uses pthread_mutex_t that seems to fix that issue but is there another way?
I also have no clue if this fix is correct.
Threading.h:44
Code: Select all
// typedef struct
// {
// pthread_mutex_t mutex;
// char is_valid;
// } mbedtls_threading_mutex_t;
Code: Select all
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
typedef unsigned int mbedtls_pthread_mutex_t; /* identify a mutex */
typedef struct
{
mbedtls_pthread_mutex_t mutex;
char is_valid;
} mbedtls_threading_mutex_t;
typedef struct
{
int type;
} pthread_mutexattr_t;
#define PTHREAD_MUTEX_INITIALIZER ((mbedtls_pthread_mutex_t)0xFFFFFFFF)
Code: Select all
int pthread_mutex_unlock(mbedtls_pthread_mutex_t *pxMutex)
{
xSemaphoreGive(*pxMutex);
return 0;
}
void pthread_mutex_destroy(mbedtls_pthread_mutex_t *pxMutex)
{
vQueueDelete((QueueHandle_t)*pxMutex);
}
int pthread_mutex_lock(mbedtls_pthread_mutex_t *pxMutex)
{
while (xSemaphoreTake(*pxMutex, portMAX_DELAY) != pdPASS)
;
return 0;
}
int pthread_mutex_init(mbedtls_pthread_mutex_t *pxMutex, void *a)
{
int xReturn = -1;
*pxMutex = (mbedtls_pthread_mutex_t)xSemaphoreCreateMutex();
if (pxMutex != NULL)
{
xReturn = 0;
}
return xReturn;
}