A272R版本优化
This commit is contained in:
@ -37,6 +37,8 @@
|
||||
#include "FreeRTOS_POSIX/errno.h"
|
||||
#include "FreeRTOS_POSIX/pthread.h"
|
||||
|
||||
#define ENABLE_TLS 1
|
||||
|
||||
/**
|
||||
* @brief Thread attribute object.
|
||||
*/
|
||||
@ -73,8 +75,9 @@ typedef struct pthread_internal
|
||||
StaticSemaphore_t xJoinBarrier; /**< Synchronizes the two callers of pthread_join. */
|
||||
StaticSemaphore_t xJoinMutex; /**< Ensures that only one other thread may join this thread. */
|
||||
void * xReturn; /**< Return value of pvStartRoutine. */
|
||||
|
||||
void** tls;
|
||||
#if ENABLE_TLS
|
||||
void** tls;//亿联内部又单独重新实现了pthread_create,会造成pthread_join里面释放tls分配的内存时奔溃,需要把这部分合并到亿联那边重新打包亿联的库
|
||||
#endif
|
||||
} pthread_internal_t;
|
||||
|
||||
/**
|
||||
@ -123,6 +126,12 @@ static void prvExitThread( void )
|
||||
}
|
||||
else
|
||||
{
|
||||
#if ENABLE_TLS
|
||||
if (pxThread->tls) {
|
||||
vPortFree(pxThread->tls);
|
||||
pxThread->tls = NULL;
|
||||
}
|
||||
#endif
|
||||
/* For a detached thread, perform cleanup of thread object. */
|
||||
vPortFree( pxThread );
|
||||
vTaskDelete( NULL );
|
||||
@ -311,7 +320,6 @@ int pthread_create( pthread_t * thread,
|
||||
iStatus = EAGAIN;
|
||||
} else {
|
||||
memset((void*)pxThread, 0, sizeof(pthread_internal_t));
|
||||
pxThread->tls = NULL;
|
||||
}
|
||||
|
||||
if( iStatus == 0 )
|
||||
@ -467,7 +475,12 @@ int pthread_join( pthread_t pthread,
|
||||
/* Release xJoinMutex and delete it. */
|
||||
( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxThread->xJoinMutex );
|
||||
vSemaphoreDelete( ( SemaphoreHandle_t ) &pxThread->xJoinMutex );
|
||||
|
||||
#if ENABLE_TLS
|
||||
if (pxThread->tls) {
|
||||
vPortFree(pxThread->tls);
|
||||
pxThread->tls = NULL;
|
||||
}
|
||||
#endif
|
||||
/* Delete the FreeRTOS task that ran the thread. */
|
||||
vTaskDelete( pxThread->xTaskHandle );
|
||||
|
||||
@ -522,7 +535,12 @@ int pthread_detach(pthread_t pthread)
|
||||
/* Release xJoinMutex and delete it. */
|
||||
( void ) xSemaphoreGive( ( SemaphoreHandle_t ) &pxThread->xJoinMutex );
|
||||
vSemaphoreDelete( ( SemaphoreHandle_t ) &pxThread->xJoinMutex );
|
||||
|
||||
#if ENABLE_TLS
|
||||
if (pxThread->tls) {
|
||||
vPortFree(pxThread->tls);
|
||||
pxThread->tls = NULL;
|
||||
}
|
||||
#endif
|
||||
/* Thread has been finished */
|
||||
if ( pThreadState == eSuspended )
|
||||
{
|
||||
@ -627,6 +645,7 @@ int pthread_setspecific(pthread_key_t key, const void *value)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
||||
int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
|
||||
{
|
||||
uint32_t index;
|
||||
@ -643,7 +662,7 @@ int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
return EAGAIN;
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
int pthread_key_delete(pthread_key_t key)
|
||||
@ -695,5 +714,63 @@ int pthread_once_ext(pthread_once_t *once_control, void (*init_routine)(void* ar
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pthread_getname_np (pthread_t __target_thread, char *__buf, size_t __buflen)
|
||||
{
|
||||
pthread_internal_t * pxThread = ( pthread_internal_t * ) __target_thread;
|
||||
char *name = NULL;
|
||||
int copy_len = 0;
|
||||
|
||||
if (pxThread == NULL || pxThread->xTaskHandle == NULL || __buf == NULL || __buflen <= 0) {
|
||||
//printf("pthread no handle\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = pcTaskGetName(pxThread->xTaskHandle);
|
||||
copy_len = strlen(name);
|
||||
|
||||
if (copy_len > __buflen - 1) {
|
||||
copy_len = __buflen - 1;
|
||||
}
|
||||
|
||||
memcpy(__buf, name, copy_len);
|
||||
__buf[copy_len] = '\0';
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int pthread_setname_np (pthread_t __target_thread, const char *__name)
|
||||
{
|
||||
pthread_internal_t * pxThread = ( pthread_internal_t * ) __target_thread;
|
||||
char *name = NULL;
|
||||
int copy_len = 0;
|
||||
|
||||
if (pxThread == NULL || pxThread->xTaskHandle == NULL || __name == NULL) {
|
||||
//printf("pthread no handle\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
copy_len = strlen(__name);
|
||||
|
||||
if (copy_len <= 0) {
|
||||
//printf("pthread name is null \r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (copy_len > (configMAX_TASK_NAME_LEN - 1)) {
|
||||
copy_len = (configMAX_TASK_NAME_LEN - 1);
|
||||
}
|
||||
|
||||
name = pcTaskGetName(pxThread->xTaskHandle);
|
||||
|
||||
memcpy(name, __name, copy_len);
|
||||
|
||||
name[copy_len] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
Reference in New Issue
Block a user