summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-09-18 17:55:32 +0800
committerGitHub <[email protected]>2021-09-18 17:55:32 +0800
commit1cb19e594c2e17daaa975a8c8e7c9a9aae46b3db (patch)
tree0d12a8627975f6e1220a1589668dbd4f019cfb4e /components/libc
parent00221bd43f8aad4a91e44fe1a7c6fe85571df456 (diff)
parentb51602b1db901e46fd1fec4d76c669b31a538079 (diff)
Merge pull request #5071 from liukangcc/master
[update] support armclang and c++11.
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/compilers/common/nogcc/sys/types.h1
-rw-r--r--components/libc/compilers/common/sys/time.h7
-rw-r--r--components/libc/pthreads/pthread.c53
-rw-r--r--components/libc/pthreads/pthread.h5
4 files changed, 56 insertions, 10 deletions
diff --git a/components/libc/compilers/common/nogcc/sys/types.h b/components/libc/compilers/common/nogcc/sys/types.h
index 2c4c12055f..5672f54a4d 100644
--- a/components/libc/compilers/common/nogcc/sys/types.h
+++ b/components/libc/compilers/common/nogcc/sys/types.h
@@ -27,6 +27,7 @@ typedef signed int ssize_t; /* Used for a count of bytes or an error
#else
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
#endif
+typedef long suseconds_t; /* microseconds. */
typedef unsigned long useconds_t; /* microseconds (unsigned) */
typedef unsigned long dev_t;
diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h
index 9d4422e17a..ecf6e85ac6 100644
--- a/components/libc/compilers/common/sys/time.h
+++ b/components/libc/compilers/common/sys/time.h
@@ -48,9 +48,10 @@ rt_int8_t rt_tz_is_dst(void);
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
#if !(defined(_WIN32))
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
+struct timeval
+{
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
};
#endif
#endif /* _TIMEVAL_DEFINED */
diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c
index 79104d1fd5..b0bf39dff6 100644
--- a/components/libc/pthreads/pthread.c
+++ b/components/libc/pthreads/pthread.c
@@ -90,9 +90,30 @@ void _pthread_data_destroy(pthread_t pth)
{
RT_DECLARE_SPINLOCK(pth_lock);
+ extern _pthread_key_data_t _thread_keys[PTHREAD_KEY_MAX];
_pthread_data_t *ptd = _pthread_get_data(pth);
if (ptd)
{
+ /* destruct thread local key */
+ if (ptd->tls != RT_NULL)
+ {
+ void *data;
+ rt_uint32_t index;
+ for (index = 0; index < PTHREAD_KEY_MAX; index ++)
+ {
+ if (_thread_keys[index].is_used)
+ {
+ data = ptd->tls[index];
+ if (data && _thread_keys[index].destructor)
+ _thread_keys[index].destructor(data);
+ }
+ }
+
+ /* release tls area */
+ rt_free(ptd->tls);
+ ptd->tls = RT_NULL;
+ }
+
/* remove from pthread table */
rt_hw_spin_lock(&pth_lock);
pth_table[pth] = NULL;
@@ -103,13 +124,17 @@ void _pthread_data_destroy(pthread_t pth)
rt_sem_delete(ptd->joinable_sem);
/* release thread resource */
- if (ptd->attr.stackaddr == RT_NULL && ptd->tid->stack_addr != RT_NULL)
+ if (ptd->attr.stackaddr == RT_NULL)
{
/* release thread allocated stack */
- rt_free(ptd->tid->stack_addr);
+ if (ptd->tid)
+ {
+ rt_free(ptd->tid->stack_addr);
+ }
}
/* clean stack addr pointer */
- ptd->tid->stack_addr = RT_NULL;
+ if (ptd->tid)
+ ptd->tid->stack_addr = RT_NULL;
/*
* if this thread create the local thread data,
@@ -221,6 +246,12 @@ int pthread_create(pthread_t *pid,
pthread_attr_init(&ptd->attr);
}
+ if (ptd->attr.stacksize == 0)
+ {
+ ret = EINVAL;
+ goto __exit;
+ }
+
rt_snprintf(name, sizeof(name), "pth%02d", pthread_number ++);
/* pthread is a static thread object */
@@ -269,7 +300,7 @@ int pthread_create(pthread_t *pid,
/* initial this pthread to system */
if (rt_thread_init(ptd->tid, name, pthread_entry_stub, ptd,
stack, ptd->attr.stacksize,
- ptd->attr.schedparam.sched_priority, 5) != RT_EOK)
+ ptd->attr.schedparam.sched_priority, 20) != RT_EOK)
{
ret = EINVAL;
goto __exit;
@@ -460,7 +491,7 @@ void pthread_exit(void *value)
if (_thread_keys[index].is_used)
{
data = ptd->tls[index];
- if (data)
+ if (data && _thread_keys[index].destructor)
_thread_keys[index].destructor(data);
}
}
@@ -507,14 +538,21 @@ int pthread_kill(pthread_t thread, int sig)
{
#ifdef RT_USING_SIGNALS
_pthread_data_t *ptd;
+ int ret;
ptd = _pthread_get_data(thread);
if (ptd)
{
- return rt_thread_kill(ptd->tid, sig);
+ ret = rt_thread_kill(ptd->tid, sig);
+ if (ret == -RT_EINVAL)
+ {
+ return EINVAL;
+ }
+
+ return ret;
}
- return EINVAL;
+ return ESRCH;
#else
return ENOSYS;
#endif
@@ -707,3 +745,4 @@ int pthread_cancel(pthread_t thread)
return 0;
}
RTM_EXPORT(pthread_cancel);
+
diff --git a/components/libc/pthreads/pthread.h b/components/libc/pthreads/pthread.h
index 8639c1604b..177b2539c5 100644
--- a/components/libc/pthreads/pthread.h
+++ b/components/libc/pthreads/pthread.h
@@ -265,6 +265,11 @@ int pthread_barrier_init(pthread_barrier_t *barrier,
int pthread_barrier_wait(pthread_barrier_t *barrier);
+int pthread_setspecific(pthread_key_t key, const void *value);
+void *pthread_getspecific(pthread_key_t key);
+int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
+int pthread_key_delete(pthread_key_t key);
+
#ifdef __cplusplus
}
#endif