summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2019-05-13 09:19:44 +0800
committerBernard Xiong <[email protected]>2019-05-13 09:19:44 +0800
commitab595cc8640ba998f7f3172d573742c56f577e33 (patch)
tree772b88ce8ced407dd4f38f4783e49ab89e364999 /components/libc
parent7038465d13531ba26f16d1b402974bfef3f93115 (diff)
[pthreads] fix the free ptd issue when there is no pthread slot.
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/pthreads/pthread.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c
index 64ef81d680..7ecf304038 100644
--- a/components/libc/pthreads/pthread.c
+++ b/components/libc/pthreads/pthread.c
@@ -10,11 +10,11 @@
* 2019-02-07 Bernard Add _pthread_destroy to release pthread resource.
*/
+#include <rthw.h>
#include <pthread.h>
#include <sched.h>
#include "pthread_internal.h"
-#include <rthw.h>
RT_DEFINE_SPINLOCK(pth_lock);
_pthread_data_t *pth_table[PTHREAD_NUM_MAX] = {NULL};
@@ -75,6 +75,13 @@ pthread_t _pthread_data_create(void)
}
rt_hw_spin_unlock(&pth_lock);
+ /* full of pthreads, clean magic and release ptd */
+ if (index == PTHREAD_NUM_MAX)
+ {
+ ptd->magic = 0x0;
+ rt_free(ptd);
+ }
+
return index;
}
@@ -102,7 +109,7 @@ void _pthread_data_destroy(pthread_t pth)
}
/* clean stack addr pointer */
ptd->tid->stack_addr = RT_NULL;
-
+
/*
* if this thread create the local thread data,
* delete it
@@ -188,7 +195,7 @@ int pthread_create(pthread_t *pid,
pthread_t pth_id;
_pthread_data_t *ptd;
- /* tid shall be provided */
+ /* pid shall be provided */
RT_ASSERT(pid != RT_NULL);
/* allocate posix thread data */
@@ -198,7 +205,6 @@ int pthread_create(pthread_t *pid,
ret = ENOMEM;
goto __exit;
}
-
/* get pthread data */
ptd = _pthread_get_data(pth_id);