diff --git a/porting/liteos_a/user/src/thread/pthread_attr_get.c b/porting/liteos_a/user/src/thread/pthread_attr_get.c index 0e4db95e5828c6b3d208282b02593b3dbfee10ca..1a72c7155962967befbd0088b98b80a87797a1dc 100644 --- a/porting/liteos_a/user/src/thread/pthread_attr_get.c +++ b/porting/liteos_a/user/src/thread/pthread_attr_get.c @@ -83,7 +83,6 @@ int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *res int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) { - unsupported_api(__FUNCTION__); *robust = a->__attr / 4U % 2; return 0; } diff --git a/porting/liteos_a/user/src/thread/pthread_create.c b/porting/liteos_a/user/src/thread/pthread_create.c index 7cc0d5481350b5d25f445f49abf26e150e741944..38aa89868d5551e6540848cc825effbd6e94e085 100644 --- a/porting/liteos_a/user/src/thread/pthread_create.c +++ b/porting/liteos_a/user/src/thread/pthread_create.c @@ -101,7 +101,6 @@ _Noreturn void __pthread_exit(void *result) /* Process robust list in userspace to handle non-pshared mutexes * and the detached thread case where the robust list head will * be invalid when the kernel would process it. */ -#if 0 __vm_lock(); volatile void *volatile *rp; while ((rp=self->robust_list.head) && rp != &self->robust_list.head) { @@ -117,7 +116,6 @@ _Noreturn void __pthread_exit(void *result) __wake(&m->_m_lock, 1, priv); } __vm_unlock(); -#endif __do_orphaned_stdio_locks(); __dl_thread_cleanup(); diff --git a/porting/liteos_a/user/src/thread/pthread_getconcurrency.c b/porting/liteos_a/user/src/thread/pthread_getconcurrency.c deleted file mode 100644 index 4156988eed2032660679211b18b9f312d30ae87e..0000000000000000000000000000000000000000 --- a/porting/liteos_a/user/src/thread/pthread_getconcurrency.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int pthread_getconcurrency() -{ - unsupported_api(__FUNCTION__); - return 0; -} diff --git a/porting/liteos_a/user/src/thread/pthread_mutex_consistent.c b/porting/liteos_a/user/src/thread/pthread_mutex_consistent.c deleted file mode 100644 index 52cc962c5b7517ee812b4ffb9aa6d656705903f6..0000000000000000000000000000000000000000 --- a/porting/liteos_a/user/src/thread/pthread_mutex_consistent.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "pthread_impl.h" -#include "atomic.h" - -int pthread_mutex_consistent(pthread_mutex_t *m) -{ - unsupported_api(__FUNCTION__); - - int old = m->_m_lock; - int own = old & 0x3fffffff; - if (!(m->_m_type & 4) || !own || !(old & 0x40000000)) - return EINVAL; - if (own != __pthread_self()->tid) - return EPERM; - a_and(&m->_m_lock, ~0x40000000); - return 0; -} diff --git a/porting/liteos_a/user/src/thread/pthread_mutex_timedlock.c b/porting/liteos_a/user/src/thread/pthread_mutex_timedlock.c index ef3ffdbfc0e03476945f93e74cdc329320dd0e5a..20689669f6eeedba4a0bc6a10f759f3f80642947 100644 --- a/porting/liteos_a/user/src/thread/pthread_mutex_timedlock.c +++ b/porting/liteos_a/user/src/thread/pthread_mutex_timedlock.c @@ -71,7 +71,7 @@ int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec while ((r=__pthread_mutex_trylock(m)) == EBUSY) { r = m->_m_lock; int own = r & 0x3fffffff; - if (!r) + if (!own && (!r || (type&4))) continue; if ((type&3) == PTHREAD_MUTEX_ERRORCHECK && own == __pthread_self()->tid) diff --git a/porting/liteos_a/user/src/thread/pthread_mutex_trylock.c b/porting/liteos_a/user/src/thread/pthread_mutex_trylock.c index 9fb6c5128cfd99156042e142b33fe35f292b3f5d..8efd615f74f153047321cf6710013cf9a4d87f1f 100644 --- a/porting/liteos_a/user/src/thread/pthread_mutex_trylock.c +++ b/porting/liteos_a/user/src/thread/pthread_mutex_trylock.c @@ -17,14 +17,22 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m) } } if (own == 0x3fffffff) return ENOTRECOVERABLE; - tid |= 0x80000000; - if (own) return EBUSY; + if (own || (old && !(type & 4))) return EBUSY; + + if (type & 128) { + if (!self->robust_list.off) { + self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next; + } + if (m->_m_waiters) tid |= 0x80000000; + self->robust_list.pending = &m->_m_next; + } + tid |= old & 0x40000000; + if (a_cas(&m->_m_lock, old, tid) != old) { self->robust_list.pending = 0; return EBUSY; } -#if 0 volatile void *next = self->robust_list.head; m->_m_next = next; m->_m_prev = &self->robust_list.head; @@ -32,13 +40,18 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m) ((char *)next - sizeof(void *)) = &m->_m_next; self->robust_list.head = &m->_m_next; self->robust_list.pending = 0; -#endif + + if (old) { + m->_m_count = 0; + return EOWNERDEAD; + } + return 0; } int __pthread_mutex_trylock(pthread_mutex_t *m) { - if ((m->_m_type&PTHREAD_MUTEX_TYPE_MASK) == PTHREAD_MUTEX_NORMAL) + if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL) return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY; return __pthread_mutex_trylock_owner(m); } diff --git a/porting/liteos_a/user/src/thread/pthread_mutex_unlock.c b/porting/liteos_a/user/src/thread/pthread_mutex_unlock.c index 6922c8f04e053f1b63465d5853431504786d37c2..d65108faa9963160149f8fb8c537c9bdb200cb66 100644 --- a/porting/liteos_a/user/src/thread/pthread_mutex_unlock.c +++ b/porting/liteos_a/user/src/thread/pthread_mutex_unlock.c @@ -5,7 +5,7 @@ int __pthread_mutex_unlock(pthread_mutex_t *m) pthread_t self; int waiters = m->_m_waiters; int cont; - int type = m->_m_type & PTHREAD_MUTEX_TYPE_MASK; + int type = m->_m_type & 15; int priv = (m->_m_type & 128) ^ 128; int new = 0; int old; @@ -18,11 +18,25 @@ int __pthread_mutex_unlock(pthread_mutex_t *m) return EPERM; if ((type&PTHREAD_MUTEX_TYPE_MASK) == PTHREAD_MUTEX_RECURSIVE && m->_m_count) return m->_m_count--, 0; - + if ((type&4) && (old&0x40000000)) + new = 0x7fffffff; + if (!priv) { + self->robust_list.pending = &m->_m_next; + __vm_lock(); + } + volatile void *prev = m->_m_prev; + volatile void *next = m->_m_next; + *(volatile void *volatile *)prev = next; + if (next != &self->robust_list.head) *(volatile void *volatile *) + ((char *)next - sizeof(void *)) = prev; } cont = a_swap(&m->_m_lock, new); + if (type != PTHREAD_MUTEX_NORMAL && !priv) { + self->robust_list.pending = 0; + __vm_unlock(); + } if (waiters || cont<0) __wake(&m->_m_lock, 1, priv); return 0; diff --git a/porting/liteos_a/user/src/thread/pthread_mutexattr_setrobust.c b/porting/liteos_a/user/src/thread/pthread_mutexattr_setrobust.c index 859350db383f003d90aff37ccbb6592f22dd7405..9a9750d28f1dd01f89f1e3432d204d4192177216 100644 --- a/porting/liteos_a/user/src/thread/pthread_mutexattr_setrobust.c +++ b/porting/liteos_a/user/src/thread/pthread_mutexattr_setrobust.c @@ -1,24 +1,10 @@ #include "pthread_impl.h" -#include #include "syscall.h" -static pthread_once_t check_robust_once; -static int check_robust_result; - -static void check_robust() -{ - void *p; - size_t l; - check_robust_result = -__syscall(SYS_get_robust_list, 0, &p, &l); -} - int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust) { - unsupported_api(__FUNCTION__); if (robust > 1U) return EINVAL; if (robust) { - pthread_once(&check_robust_once, check_robust); - if (check_robust_result) return check_robust_result; a->__attr |= 4; return 0; } diff --git a/porting/liteos_a/user/src/thread/pthread_setconcurrency.c b/porting/liteos_a/user/src/thread/pthread_setconcurrency.c deleted file mode 100644 index a394233321ff4a6882edb3aee56e931b45f41f4a..0000000000000000000000000000000000000000 --- a/porting/liteos_a/user/src/thread/pthread_setconcurrency.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -int pthread_setconcurrency(int val) -{ - unsupported_api(__FUNCTION__); - if (val < 0) return EINVAL; - if (val > 0) return EAGAIN; - return 0; -}