diff options
| author | armink <[email protected]> | 2019-12-17 20:11:46 +0800 |
|---|---|---|
| committer | armink <[email protected]> | 2019-12-17 20:11:46 +0800 |
| commit | 4875ee8a3ab95c4fbf1e09941d3f44d99a9a632b (patch) | |
| tree | 15c596c04a842bac747bbcf05a703b8da76f8eac /components/libc/pthreads | |
| parent | fa46d6ac861f26b472d62abdf1278c445431ce4c (diff) | |
Sync from master (75a3f3dd3a930eab1dc58fa0258a9d1605a0ac11)
Diffstat (limited to 'components/libc/pthreads')
| -rw-r--r-- | components/libc/pthreads/pthread.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c index 7ecf304038..5d3bc0796a 100644 --- a/components/libc/pthreads/pthread.c +++ b/components/libc/pthreads/pthread.c @@ -102,7 +102,7 @@ void _pthread_data_destroy(pthread_t pth) rt_sem_delete(ptd->joinable_sem); /* release thread resource */ - if (ptd->attr.stackaddr == RT_NULL) + if (ptd->attr.stackaddr == RT_NULL && ptd->tid->stack_addr != RT_NULL) { /* release thread allocated stack */ rt_free(ptd->tid->stack_addr); @@ -219,20 +219,6 @@ int pthread_create(pthread_t *pid, } rt_snprintf(name, sizeof(name), "pth%02d", pthread_number ++); - if (ptd->attr.stackaddr == 0) - { - stack = (void *)rt_malloc(ptd->attr.stacksize); - } - else - { - stack = (void *)(ptd->attr.stackaddr); - } - - if (stack == RT_NULL) - { - ret = ENOMEM; - goto __exit; - } /* pthread is a static thread object */ ptd->tid = (rt_thread_t) rt_malloc(sizeof(struct rt_thread)); @@ -241,6 +227,7 @@ int pthread_create(pthread_t *pid, ret = ENOMEM; goto __exit; } + memset(ptd->tid, 0, sizeof(struct rt_thread)); if (ptd->attr.detachstate == PTHREAD_CREATE_JOINABLE) { @@ -260,6 +247,22 @@ int pthread_create(pthread_t *pid, ptd->thread_entry = start; ptd->thread_parameter = parameter; + /* stack */ + if (ptd->attr.stackaddr == 0) + { + stack = (void *)rt_malloc(ptd->attr.stacksize); + } + else + { + stack = (void *)(ptd->attr.stackaddr); + } + + if (stack == RT_NULL) + { + ret = ENOMEM; + goto __exit; + } + /* initial this pthread to system */ if (rt_thread_init(ptd->tid, name, pthread_entry_stub, ptd, stack, ptd->attr.stacksize, |
