volatile eNotifyValue eNotifyState;
#endif
-#if (configESP32_PER_TASK_DATA == 1)
- void *data;
-#endif
-
} tskTCB;
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name
if( pxNewTCB != NULL )
{
-#if (configESP32_PER_TASK_DATA == 1)
- pxNewTCB->data = NULL;
-#endif
#if( portUSING_MPU_WRAPPERS == 1 )
/* Should the task be created in privileged mode? */
BaseType_t xRunPrivileged;
being deleted. */
pxTCB = prvGetTCBFromHandle( xTaskToDelete );
-#if (configESP32_PER_TASK_DATA == 1)
- if (pxTCB->data){
- vSemaphoreDelete( pxTCB->data );
- }
-#endif
/* Remove task from the ready list and place in the termination list.
This will stop the task from be scheduled. The idle task will check
the termination list and free up any memory allocated by the
#endif /* configUSE_TASK_NOTIFICATIONS */
-/*-----------------------------------------------------------*/
-#if (configESP32_PER_TASK_DATA == 1)
-void* xTaskGetPerTaskData(void)
-{
- TCB_t *pxTCB = (TCB_t*)(xTaskGetCurrentTaskHandle());
- if (pxTCB){
- if (!pxTCB->data){
- vSemaphoreCreateBinary(pxTCB->data);
- }
- return (void*)(&pxTCB->data);
- }
-
- return NULL;
-}
-#endif /* configESP32_PER_TASK_DATA */
-/*-----------------------------------------------------------*/
-
#ifdef FREERTOS_MODULE_TEST
#include "tasks_test_access_functions.h"
#endif
#if LWIP_NETCONN_SEM_PER_THREAD
#ifdef LWIP_ESP8266
-#define LWIP_NETCONN_THREAD_SEM_GET() sys_thread_sem()
-#define LWIP_NETCONN_THREAD_SEM_ALLOC()
-#define LWIP_NETCONN_THREAD_SEM_FREE()
+#define LWIP_NETCONN_THREAD_SEM_GET() sys_thread_sem_get()
+#define LWIP_NETCONN_THREAD_SEM_ALLOC() sys_thread_sem_init()
+#define LWIP_NETCONN_THREAD_SEM_FREE() sys_thread_sem_deinit()
#endif
#endif
\r
void sys_arch_assert(const char *file, int line);\r
uint32_t system_get_time(void);
-sys_sem_t* sys_thread_sem(void);
void sys_delay_ms(uint32_t ms);
-void* xTaskGetPerTaskData(void);
-
+sys_sem_t* sys_thread_sem_init(void);
+void sys_thread_sem_deinit(void);
+sys_sem_t* sys_thread_sem_get(void);
\r
#endif /* __SYS_ARCH_H__ */\r
while(1);
}
-/* This is a super hacky thread-local-storage repository
- FreeRTOS 8.2.3 & up have thread local storage in the
- OS, which is how we should do this. Once we upgrade FreeRTOS,
- we can drop this hacky store and use the FreeRTOS TLS API.
-*/
-sys_sem_t* sys_thread_sem(void)
+/*
+ * get per thread semphore
+ */
+sys_sem_t* sys_thread_sem_get(void)
+{
+ sys_sem_t *sem = (sys_sem_t*)pvTaskGetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), 0);
+ if (!sem){
+ sem = sys_thread_sem_init();
+ }
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem_get s=%p\n", sem));
+ return sem;
+}
+
+sys_sem_t* sys_thread_sem_init(void)
{
- sys_sem_t *sem = (sys_sem_t*)xTaskGetPerTaskData();
+ sys_sem_t *sem = (sys_sem_t*)malloc(sizeof(sys_sem_t*));
+
+ if (!sem){
+ printf("sem f1\n");
+ return 0;
+ }
+
+ *sem = xSemaphoreCreateBinary();
+ if (!(*sem)){
+ free(sem);
+ printf("sem f2\n");
+ return 0;
+ }
+
+ LWIP_DEBUGF(THREAD_SAFE_DEBUG, ("sem init %p %p\n", sem, *sem));
+ vTaskSetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), 0, sem);
+
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);
+ }
+
+ if (sem){
+ free(sem);
+ }
+
+ vTaskSetThreadLocalStoragePointer(xTaskGetCurrentTaskHandle(), 0, 0);
+ return;
+}
+
void sys_delay_ms(uint32_t ms)
{
vTaskDelay(ms/portTICK_RATE_MS);