diff options
| author | guozhanxin <[email protected]> | 2021-12-09 20:31:12 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2021-12-22 13:04:35 +0800 |
| commit | acc62c1e3da639ec22ab0d6b44e4f777b6225603 (patch) | |
| tree | 01a1541394a6700edf08805fb6b666bef763cd6a /components/cplusplus/cpp11/armclang/thread.cpp | |
| parent | 67a39f62e55f4a3ca1ebf07cbe45dd9d98a668a8 (diff) | |
【修复】armclang cpp11 内存泄漏及编译警告问题
Diffstat (limited to 'components/cplusplus/cpp11/armclang/thread.cpp')
| -rw-r--r-- | components/cplusplus/cpp11/armclang/thread.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/components/cplusplus/cpp11/armclang/thread.cpp b/components/cplusplus/cpp11/armclang/thread.cpp index 46306eceb8..6b38d9b3a7 100644 --- a/components/cplusplus/cpp11/armclang/thread.cpp +++ b/components/cplusplus/cpp11/armclang/thread.cpp @@ -13,19 +13,18 @@ #include <cstdio> #include <pthread.h> +#define CPP11_DEFAULT_ID_OFFSET 1 + extern "C" int __ARM_TPL_thread_create(__ARM_TPL_thread_t *__t, void *(*__func)(void *), void *__arg) { int ret = 0; - /* TODO memory leek */ - pthread_t *pid = (pthread_t *)rt_malloc(sizeof(pthread_t)); - if (pid == nullptr) - return -1; - ret = pthread_create(pid, RT_NULL, __func, __arg); + pthread_t pid; + ret = pthread_create(&pid, RT_NULL, __func, __arg); if (ret == 0) { - __t->data = (std::uintptr_t)pid; + __t->data = (std::uintptr_t)pid + CPP11_DEFAULT_ID_OFFSET; return 0; } return -1; @@ -50,18 +49,18 @@ extern "C" __ARM_TPL_thread_id __ARM_TPL_thread_get_current_id() extern "C" __ARM_TPL_thread_id __ARM_TPL_thread_get_id( const __ARM_TPL_thread_t *__t) { - return (__ARM_TPL_thread_id)((*(pthread_t *)__t->data)); + return (__ARM_TPL_thread_id)(((pthread_t)__t->data - CPP11_DEFAULT_ID_OFFSET)); } extern "C" int __ARM_TPL_thread_join(__ARM_TPL_thread_t *__t) { - pthread_join((*(pthread_t *)__t->data), RT_NULL); + pthread_join(((pthread_t)__t->data - CPP11_DEFAULT_ID_OFFSET), RT_NULL); return 0; } extern "C" int __ARM_TPL_thread_detach(__ARM_TPL_thread_t *__t) { - pthread_detach((*(pthread_t *)__t->data)); + pthread_detach(((pthread_t)__t->data - CPP11_DEFAULT_ID_OFFSET)); return 0; } |
