(*mbox)->alive = true;
- LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("new *mbox ok\n"));
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("new *mbox ok mbox=%p os_mbox=%p mbox_lock=%p\n", *mbox, (*mbox)->os_mbox, (*mbox)->lock));
return ERR_OK;
}
{
err_t xReturn;
- if (msg == NULL){
- LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("&msg=%p\n", &msg));
- }
-
if (xQueueSend((*mbox)->os_mbox, &msg, (portTickType)0) == pdPASS) {
xReturn = ERR_OK;
} else {
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("trypost mbox=%p fail\n", (*mbox)->os_mbox));
xReturn = ERR_MEM;
}
ulReturn = SYS_ARCH_TIMEOUT;
}
} else { // block forever for a message.
+
while (1){
LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sys_arch_mbox_fetch: fetch mbox=%p os_mbox=%p lock=%p\n", mbox, (*mbox)->os_mbox, (*mbox)->lock));
- //if (pdTRUE == xQueueReceive((*mbox)->os_mbox, &(*msg), portMAX_DELAY)){
- if (pdTRUE == xQueueReceive((*mbox)->os_mbox, &(*msg), 3000/portTICK_RATE_MS)){ //ESP32_WORKAROUND
+ if (pdTRUE == xQueueReceive((*mbox)->os_mbox, &(*msg), portMAX_DELAY)){
+ //if (pdTRUE == xQueueReceive((*mbox)->os_mbox, &(*msg), 3000/portTICK_RATE_MS)){ //ESP32_WORKAROUND
LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sys_arch_mbox_fetch:mbox rx msg=%p\n", (*msg)));
break;
}
LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sys_mbox_free:free mbox\n"));
-#if 1 //ESP32_WORKAROUND
if (uxQueueMessagesWaiting((*mbox)->os_mbox)) {
xQueueReset((*mbox)->os_mbox);
/* Line for breakpoint. Should never break here! */
sys_mutex_free(&(*mbox)->lock);
free(*mbox);
*mbox = NULL;
-#endif
}
/*-----------------------------------------------------------------------------------*/
while(1);
}
+#define SYS_TLS_INDEX CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX
/*
* get per thread semphore
*/
sys_sem_t* sys_thread_sem_get(void)
{
- sys_sem_t *sem = (sys_sem_t*)pvTaskGetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), 0);
+ sys_sem_t *sem = (sys_sem_t*)pvTaskGetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), SYS_TLS_INDEX);
if (!sem){
sem = sys_thread_sem_init();
}
return sem;
}
+static void sys_thread_tls_free(int index, void* data)
+{
+ sys_sem_t *sem = (sys_sem_t*)(data);
+
+ if (sem && *sem){
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem del, i=%d sem=%p\n", index, *sem));
+ ets_printf("sem del:%p\n", *sem);
+ vSemaphoreDelete(*sem);
+ }
+
+ if (sem){
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem pointer del, i=%d sem_p=%p\n", index, sem));
+ ets_printf("sem pointer del:%p\n", sem);
+ free(sem);
+ }
+}
+
sys_sem_t* sys_thread_sem_init(void)
{
sys_sem_t *sem = (sys_sem_t*)malloc(sizeof(sys_sem_t*));
return 0;
}
- LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem init %p %p\n", sem, *sem));
- vTaskSetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), 0, sem);
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem init sem_p=%p sem=%p cb=%p\n", sem, *sem, sys_thread_tls_free));
+ vTaskSetThreadLocalStoragePointerAndDelCallback(xTaskGetCurrentTaskHandle(), SYS_TLS_INDEX, sem, (TlsDeleteCallbackFunction_t)sys_thread_tls_free);
return sem;
}
void sys_thread_sem_deinit(void)
{
- sys_sem_t *sem = sys_thread_sem_get();
- if (sem && *sem){
- LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem del:%p %p\n", sem, *sem));
- vSemaphoreDelete(*sem);
- }
+ sys_sem_t *sem = (sys_sem_t*)pvTaskGetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), SYS_TLS_INDEX);
- if (sem){
- free(sem);
- }
+ sys_thread_tls_free(SYS_TLS_INDEX, (void*)sem);
+ vTaskSetThreadLocalStoragePointerAndDelCallback(xTaskGetCurrentTaskHandle(), SYS_TLS_INDEX, 0, 0);
- vTaskSetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), 0, 0);
return;
}