From 2ada7e5b4df4eacc8d6b046b4024d6662dd7d1cb Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 3 Sep 2017 15:57:52 +0200 Subject: Add headers wanted by glibc 2.26 * sysdeps/i386/bits/pthreadtypes-arch.h: New file. * sysdeps/pthread/bits/thread-shared-types.h: New file. * sysdeps/pthread/bits/pthreadtypes.h: Include --- sysdeps/i386/bits/pthreadtypes-arch.h | 21 +++++++++++++++++++++ sysdeps/pthread/bits/pthreadtypes.h | 3 ++- sysdeps/pthread/bits/thread-shared-types.h | 24 ++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 sysdeps/i386/bits/pthreadtypes-arch.h create mode 100644 sysdeps/pthread/bits/thread-shared-types.h diff --git a/sysdeps/i386/bits/pthreadtypes-arch.h b/sysdeps/i386/bits/pthreadtypes-arch.h new file mode 100644 index 0000000..7e7a311 --- /dev/null +++ b/sysdeps/i386/bits/pthreadtypes-arch.h @@ -0,0 +1,21 @@ +/* Copyright (C) 2002-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_PTHREADTYPES_ARCH_H +#define _BITS_PTHREADTYPES_ARCH_H 1 + +#endif /* bits/pthreadtypes.h */ diff --git a/sysdeps/pthread/bits/pthreadtypes.h b/sysdeps/pthread/bits/pthreadtypes.h index 70368ff..3e44d6b 100644 --- a/sysdeps/pthread/bits/pthreadtypes.h +++ b/sysdeps/pthread/bits/pthreadtypes.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2000 Free Software Foundation, Inc. + Copyright (C) 2000-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -25,5 +25,6 @@ #define _BITS_PTHREADTYPES_H 1 #include +#include #endif /* bits/pthreadtypes.h */ diff --git a/sysdeps/pthread/bits/thread-shared-types.h b/sysdeps/pthread/bits/thread-shared-types.h new file mode 100644 index 0000000..369fead --- /dev/null +++ b/sysdeps/pthread/bits/thread-shared-types.h @@ -0,0 +1,24 @@ +/* Common threading primitives definitions for both POSIX and C11. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _THREAD_SHARED_TYPES_H +#define _THREAD_SHARED_TYPES_H 1 + +#include + +#endif /* _THREAD_SHARED_TYPES_H */ -- cgit v1.2.3 From 4c9332bfdc9ccd793b6ded3168602195913cedb3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 17 Sep 2017 21:44:09 +0200 Subject: Fix build with hidden symbols * forward.c (__register_atfork): Add missing def for hidden symbol. --- forward.c | 1 + 1 file changed, 1 insertion(+) diff --git a/forward.c b/forward.c index c819357..0ee84a0 100644 --- a/forward.c +++ b/forward.c @@ -246,6 +246,7 @@ __register_atfork ( return 0; } +libc_hidden_def (__register_atfork) void __unregister_atfork (void *dso_handle) -- cgit v1.2.3 From f881f17267506f3ced17259a066a4d95bffb57f0 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 24 Sep 2017 23:09:59 +0200 Subject: Fix symbols exposed in linkspace Libc uses some thread functions, but should not expose the corresponding symbols, so use aliases. * Versions (__cthread_detach, __cthread_fork, __cthread_keycreate, __cthread_getspecific, __cthread_setspecific, __pthread_getattr_np, __pthread_attr_getstack): Add symbols * pthread/cthreads-compat.c (cthread_t, cthread_fn_t, cthread_key_t): Do not define. (cthread_detach): Rename to __cthread_detach. (cthread_detach): Define as weak alias to __cthread_detach. (cthread_fork, cthread_keycreate, cthread_getspecific, cthread_setspecific): Likewise. * pthread/pt-getattr.c (pthread_getattr_np): Likewise. * sysdeps/generic/pt-attr-getstack.c (pthread_attr_getstack): Likewise. * sysdeps/pthread/pthread.h (__cthread_t, __cthread_key_t, __cthread_fn_t, __cthread_fork, __cthread_detach, __cthread_keycreate, __cthread_getspecific, __cthread_setspecific, __pthread_getattr_np, __pthread_attr_getstack): Declare. --- Versions | 8 ++++++++ pthread/cthreads-compat.c | 25 +++++++++++++------------ pthread/pt-getattr.c | 3 ++- sysdeps/generic/pt-attr-getstack.c | 3 ++- sysdeps/pthread/pthread.h | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Versions b/Versions index 4ad3c3e..67c6032 100644 --- a/Versions +++ b/Versions @@ -143,5 +143,13 @@ libpthread { GLIBC_PRIVATE { __shm_directory; __pthread_threads; + + __cthread_detach; + __cthread_fork; + __cthread_keycreate; + __cthread_getspecific; + __cthread_setspecific; + __pthread_getattr_np; + __pthread_attr_getstack; } } diff --git a/pthread/cthreads-compat.c b/pthread/cthreads-compat.c index 1a0971b..cd845ed 100644 --- a/pthread/cthreads-compat.c +++ b/pthread/cthreads-compat.c @@ -20,23 +20,20 @@ #include #include -typedef void *cthread_t; -typedef void *(*cthread_fn_t) (void *arg); -typedef int cthread_key_t; - -#define CTHREAD_KEY_INVALID (cthread_key_t) -1 +#define CTHREAD_KEY_INVALID (__cthread_key_t) -1 void -cthread_detach (cthread_t thread) +__cthread_detach (__cthread_t thread) { int err; err = pthread_detach ((pthread_t) thread); assert_perror (err); } +weak_alias (__cthread_detach, cthread_detach) -cthread_t -cthread_fork (cthread_fn_t func, void *arg) +__cthread_t +__cthread_fork (__cthread_fn_t func, void *arg) { pthread_t thread; int err; @@ -44,11 +41,12 @@ cthread_fork (cthread_fn_t func, void *arg) err = pthread_create (&thread, NULL, func, arg); assert_perror (err); - return (cthread_t) thread; + return (__cthread_t) thread; } +weak_alias (__cthread_fork, cthread_fork) int -cthread_keycreate (cthread_key_t *key) +__cthread_keycreate (__cthread_key_t *key) { error_t err; @@ -62,16 +60,18 @@ cthread_keycreate (cthread_key_t *key) return err; } +weak_alias (__cthread_keycreate, cthread_keycreate) int -cthread_getspecific (cthread_key_t key, void **val) +__cthread_getspecific (__cthread_key_t key, void **val) { *val = pthread_getspecific (key); return 0; } +weak_alias (__cthread_getspecific, cthread_getspecific) int -cthread_setspecific (cthread_key_t key, void *val) +__cthread_setspecific (__cthread_key_t key, void *val) { error_t err; @@ -84,6 +84,7 @@ cthread_setspecific (cthread_key_t key, void *val) return err; } +weak_alias (__cthread_setspecific, cthread_setspecific) void __mutex_lock_solid (void *lock) diff --git a/pthread/pt-getattr.c b/pthread/pt-getattr.c index 574420a..0b86c66 100644 --- a/pthread/pt-getattr.c +++ b/pthread/pt-getattr.c @@ -27,7 +27,7 @@ already running thread THREAD. It shall be called on an uninitialized ATTR and destroyed with pthread_attr_destroy when no longer needed. */ int -pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) +__pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) { struct __pthread *pthread; @@ -49,3 +49,4 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr) return 0; } +weak_alias (__pthread_getattr_np, pthread_getattr_np) diff --git a/sysdeps/generic/pt-attr-getstack.c b/sysdeps/generic/pt-attr-getstack.c index 7beb79f..5ab821e 100644 --- a/sysdeps/generic/pt-attr-getstack.c +++ b/sysdeps/generic/pt-attr-getstack.c @@ -21,7 +21,7 @@ #include int -pthread_attr_getstack (const pthread_attr_t *attr, +__pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr, size_t *stacksize) { @@ -29,3 +29,4 @@ pthread_attr_getstack (const pthread_attr_t *attr, pthread_attr_getstacksize (attr, stacksize); return 0; } +weak_alias (__pthread_attr_getstack, pthread_attr_getstack) diff --git a/sysdeps/pthread/pthread.h b/sysdeps/pthread/pthread.h index 1d4d3c7..8e65b05 100644 --- a/sysdeps/pthread/pthread.h +++ b/sysdeps/pthread/pthread.h @@ -1,7 +1,22 @@ #ifndef _PTHREAD_H #include +/* These represent the interface used by glibc itself. */ + extern int __pthread_mutex_lock (pthread_mutex_t *__mutex); extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex); +typedef struct __cthread *__cthread_t; +typedef int __cthread_key_t; +typedef void * (*__cthread_fn_t)(void *__arg); + +__cthread_t __cthread_fork (__cthread_fn_t, void *); +void __cthread_detach (__cthread_t); +int __cthread_keycreate (__cthread_key_t *); +int __cthread_getspecific (__cthread_key_t, void **); +int __cthread_setspecific (__cthread_key_t, void *); + +int __pthread_getattr_np (pthread_t, pthread_attr_t *); +int __pthread_attr_getstack (const pthread_attr_t *, void **, size_t *); + #endif -- cgit v1.2.3 From 2b7d0800f314e0abf370b2b6f6272a2ddb875464 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 25 Sep 2017 21:18:29 +0200 Subject: Fix exposing symbols * sysdeps/hurd/pt-key.h (__pthread_key_lock_ready): Use __pthread_mutexattr_init, __pthread_mutexattr_settype, _pthread_mutex_init, __pthread_mutexattr_destroy, __pthread_once instead of pthread_mutexattr_init, pthread_mutexattr_settype,pthread_mutex_init, pthread_mutexattr_destroy, pthread_once. --- sysdeps/hurd/pt-key.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sysdeps/hurd/pt-key.h b/sysdeps/hurd/pt-key.h index 494e01d..7b6a2c2 100644 --- a/sysdeps/hurd/pt-key.h +++ b/sysdeps/hurd/pt-key.h @@ -19,6 +19,7 @@ #include #include +#include #define PTHREAD_KEY_MEMBERS \ hurd_ihash_t thread_specifics; @@ -59,18 +60,18 @@ __pthread_key_lock_ready (void) int err; pthread_mutexattr_t attr; - err = pthread_mutexattr_init (&attr); + err = __pthread_mutexattr_init (&attr); assert_perror (err); - err = pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); + err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); assert_perror (err); - err = pthread_mutex_init (&__pthread_key_lock, &attr); + err = _pthread_mutex_init (&__pthread_key_lock, &attr); assert_perror (err); - err = pthread_mutexattr_destroy (&attr); + err = __pthread_mutexattr_destroy (&attr); assert_perror (err); } - pthread_once (&o, do_init); + __pthread_once (&o, do_init); } -- cgit v1.2.3 From 596061769ee34741a42eb375b1a2e06fffb4c5a3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 25 Sep 2017 21:47:12 +0200 Subject: Fix symbol exposition * sysdeps/generic/pt-rwlock-rdlock.c (pthread_rwlock_rdlock): Make alias weak. * sysdeps/generic/pt-rwlock-unlock.c (pthread_rwlock_unlock): Likewise. * sysdeps/generic/pt-rwlock-wrlock.c (pthread_rwlock_wrlock): Likewise. * sysdeps/generic/sem-timedwait.c (sem_timedwait): Likewise. * sysdeps/generic/pt-rwlock-timedrdlock.c (pthread_rwlock_timedrdlock): Make it a weak alias. * sysdeps/generic/pt-rwlock-timedwrlock.c (pthread_rwlock_timedwrlock): Likewise. --- sysdeps/generic/pt-rwlock-rdlock.c | 2 +- sysdeps/generic/pt-rwlock-timedrdlock.c | 3 ++- sysdeps/generic/pt-rwlock-timedwrlock.c | 3 ++- sysdeps/generic/pt-rwlock-unlock.c | 2 +- sysdeps/generic/pt-rwlock-wrlock.c | 2 +- sysdeps/generic/sem-timedwait.c | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sysdeps/generic/pt-rwlock-rdlock.c b/sysdeps/generic/pt-rwlock-rdlock.c index 6eca601..708e3e1 100644 --- a/sysdeps/generic/pt-rwlock-rdlock.c +++ b/sysdeps/generic/pt-rwlock-rdlock.c @@ -30,4 +30,4 @@ __pthread_rwlock_rdlock (struct __pthread_rwlock *rwlock) { return __pthread_rwlock_timedrdlock_internal (rwlock, 0); } -strong_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock); +weak_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock); diff --git a/sysdeps/generic/pt-rwlock-timedrdlock.c b/sysdeps/generic/pt-rwlock-timedrdlock.c index 69bc757..4cfba43 100644 --- a/sysdeps/generic/pt-rwlock-timedrdlock.c +++ b/sysdeps/generic/pt-rwlock-timedrdlock.c @@ -113,8 +113,9 @@ __pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock, } int -pthread_rwlock_timedrdlock (struct __pthread_rwlock *rwlock, +__pthread_rwlock_timedrdlock (struct __pthread_rwlock *rwlock, const struct timespec *abstime) { return __pthread_rwlock_timedrdlock_internal (rwlock, abstime); } +weak_alias (__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock) diff --git a/sysdeps/generic/pt-rwlock-timedwrlock.c b/sysdeps/generic/pt-rwlock-timedwrlock.c index be25629..2adaf03 100644 --- a/sysdeps/generic/pt-rwlock-timedwrlock.c +++ b/sysdeps/generic/pt-rwlock-timedwrlock.c @@ -96,8 +96,9 @@ __pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock, } int -pthread_rwlock_timedwrlock (struct __pthread_rwlock *rwlock, +__pthread_rwlock_timedwrlock (struct __pthread_rwlock *rwlock, const struct timespec *abstime) { return __pthread_rwlock_timedwrlock_internal (rwlock, abstime); } +weak_alias (__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock) diff --git a/sysdeps/generic/pt-rwlock-unlock.c b/sysdeps/generic/pt-rwlock-unlock.c index d538544..0506ae6 100644 --- a/sysdeps/generic/pt-rwlock-unlock.c +++ b/sysdeps/generic/pt-rwlock-unlock.c @@ -96,4 +96,4 @@ __pthread_rwlock_unlock (pthread_rwlock_t *rwlock) __pthread_spin_unlock (&rwlock->__lock); return 0; } -strong_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock); +weak_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock); diff --git a/sysdeps/generic/pt-rwlock-wrlock.c b/sysdeps/generic/pt-rwlock-wrlock.c index 68254d1..c769bc6 100644 --- a/sysdeps/generic/pt-rwlock-wrlock.c +++ b/sysdeps/generic/pt-rwlock-wrlock.c @@ -32,4 +32,4 @@ __pthread_rwlock_wrlock (struct __pthread_rwlock *rwlock) { return __pthread_rwlock_timedwrlock_internal (rwlock, 0); } -strong_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock); +weak_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock); diff --git a/sysdeps/generic/sem-timedwait.c b/sysdeps/generic/sem-timedwait.c index 7ab1583..11c1391 100644 --- a/sysdeps/generic/sem-timedwait.c +++ b/sysdeps/generic/sem-timedwait.c @@ -97,4 +97,4 @@ __sem_timedwait (sem_t *restrict sem, return __sem_timedwait_internal (sem, timeout); } -strong_alias (__sem_timedwait, sem_timedwait); +weak_alias (__sem_timedwait, sem_timedwait); -- cgit v1.2.3 From 6bb20b2e064e1e4473683fa6e598e80f4ea8aa00 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 26 Sep 2017 21:16:41 +0200 Subject: Remove libihash use It poses compilation bootstrapping inconvenience, non-standard symbol exposition, and this is overkill, considering the usual use of TSD, and the availability of TLS. * sysdeps/hurd/pt-key.h: Do not include . (PTHREAD_KEY_MEMBERS): Turn thread_specifics to a void**, add unsigned thread_specifics_size. * sysdeps/hurd/pt-init-specific.c (__pthread_init_specific): Initialize thread_specifics_size to 0. * sysdeps/hurd/pt-setspecific.c: Do not include . (__pthread_setspecific): Expand and access thread_specifics array instead of hash table. * sysdeps/hurd/pt-getspecific.c: Do not include . (__pthread_getspecific): Access thread_specifics array instead of hash table. * sysdeps/hurd/pt-key-delete.c (pthread_key_delete): Clean thread_specifics array instead of hash table. * sysdeps/hurd/pt-destroy-specific.c: Do not include . (__pthread_destroy_specific): Clean and free thread_specifics array instead of hash table. * Makeconfig (LDLIBS-tst-interpose-static-thread): Remove -lihash. (LDLIBS-tst-linkall-static): Remove -lihash. * Makefile (HURDLIBS): Remove ihash. (LDLIBS-pthread.so): Remove -lihash. * libpthread.a: Remove -lihash. * libpthread_pic.a: Remove -lihash_pic. --- Makeconfig | 7 ------- Makefile | 6 ------ libpthread.a | 2 +- libpthread_pic.a | 2 +- sysdeps/hurd/pt-destroy-specific.c | 12 +++++------- sysdeps/hurd/pt-getspecific.c | 5 ++--- sysdeps/hurd/pt-init-specific.c | 1 + sysdeps/hurd/pt-key-delete.c | 4 ++-- sysdeps/hurd/pt-key.h | 4 ++-- sysdeps/hurd/pt-setspecific.c | 21 ++++++++++++--------- 10 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Makeconfig b/Makeconfig index a8ef68e..e90f5f7 100644 --- a/Makeconfig +++ b/Makeconfig @@ -8,13 +8,6 @@ shared-thread-library = $(common-objpfx)libpthread/libpthread_nonshared.a \ static-thread-library = $(common-objpfx)libpthread/libpthread.a bounded-thread-library = $(static-thread-library) -ifeq ($(subdir),malloc) -LDLIBS-tst-interpose-static-thread += -lihash -endif -ifeq ($(subdir),elf) -LDLIBS-tst-linkall-static += -lihash -endif - rpath-dirs += libpthread +includes += -I$(..)libpthread/include diff --git a/Makefile b/Makefile index 9707f57..3f59924 100644 --- a/Makefile +++ b/Makefile @@ -219,12 +219,6 @@ SYSDEP_PATH = $(srcdir)/sysdeps/$(MICROKERNEL)/hurd/i386 \ VPATH += $(SYSDEP_PATH) -ifeq ($(IN_GLIBC),no) -HURDLIBS = ihash -else -LDLIBS-pthread.so = -lihash -endif - ifeq ($(IN_GLIBC),no) installhdrs := installhdrsubdir := . diff --git a/libpthread.a b/libpthread.a index 7d3f8d3..e5bd2cc 100644 --- a/libpthread.a +++ b/libpthread.a @@ -19,4 +19,4 @@ EXTERN(_cthreads_ftrylockfile) EXTERN(pthread_getattr_np) EXTERN(pthread_attr_getstack) -GROUP(-lpthread2 -lihash -lrt) +GROUP(-lpthread2 -lrt) diff --git a/libpthread_pic.a b/libpthread_pic.a index cf0bd90..33346b4 100644 --- a/libpthread_pic.a +++ b/libpthread_pic.a @@ -19,4 +19,4 @@ EXTERN(_cthreads_ftrylockfile) EXTERN(pthread_getattr_np) EXTERN(pthread_attr_getstack) -GROUP(-lpthread2_pic -lihash_pic) +GROUP(-lpthread2_pic) diff --git a/sysdeps/hurd/pt-destroy-specific.c b/sysdeps/hurd/pt-destroy-specific.c index f7896e5..642c61c 100644 --- a/sysdeps/hurd/pt-destroy-specific.c +++ b/sysdeps/hurd/pt-destroy-specific.c @@ -19,14 +19,12 @@ #include #include -#include #include void __pthread_destroy_specific (struct __pthread *thread) { - error_t err; int i; int seen_one; @@ -43,18 +41,17 @@ __pthread_destroy_specific (struct __pthread *thread) __pthread_mutex_lock (&__pthread_key_lock); - for (i = 0; i < __pthread_key_count; i ++) + for (i = 0; i < __pthread_key_count && i < thread->thread_specifics_size; i ++) { void *value; if (__pthread_key_destructors[i] == PTHREAD_KEY_INVALID) continue; - value = hurd_ihash_find (thread->thread_specifics, i); + value = thread->thread_specifics[i]; if (value) { - err = hurd_ihash_remove (thread->thread_specifics, i); - assert (err == 1); + thread->thread_specifics[i] = 0; if (__pthread_key_destructors[i]) { @@ -74,6 +71,7 @@ __pthread_destroy_specific (struct __pthread *thread) sched_yield (); } - hurd_ihash_free (thread->thread_specifics); + free (thread->thread_specifics); thread->thread_specifics = 0; + thread->thread_specifics_size = 0; } diff --git a/sysdeps/hurd/pt-getspecific.c b/sysdeps/hurd/pt-getspecific.c index 8a01470..1f49c03 100644 --- a/sysdeps/hurd/pt-getspecific.c +++ b/sysdeps/hurd/pt-getspecific.c @@ -18,7 +18,6 @@ Boston, MA 02111-1307, USA. */ #include -#include #include @@ -32,9 +31,9 @@ __pthread_getspecific (pthread_key_t key) return NULL; self = _pthread_self (); - if (! self->thread_specifics) + if (key >= self->thread_specifics_size) return 0; - return hurd_ihash_find (self->thread_specifics, key); + return self->thread_specifics[key]; } strong_alias (__pthread_getspecific, pthread_getspecific); diff --git a/sysdeps/hurd/pt-init-specific.c b/sysdeps/hurd/pt-init-specific.c index c1bacbc..78958cb 100644 --- a/sysdeps/hurd/pt-init-specific.c +++ b/sysdeps/hurd/pt-init-specific.c @@ -26,5 +26,6 @@ error_t __pthread_init_specific (struct __pthread *thread) { thread->thread_specifics = 0; + thread->thread_specifics_size = 0; return 0; } diff --git a/sysdeps/hurd/pt-key-delete.c b/sysdeps/hurd/pt-key-delete.c index 8b2c8bb..499e9f3 100644 --- a/sysdeps/hurd/pt-key-delete.c +++ b/sysdeps/hurd/pt-key-delete.c @@ -52,8 +52,8 @@ pthread_key_delete (pthread_key_t key) /* Just remove the key, no need to care whether it was already there. */ - if (t->thread_specifics) - hurd_ihash_remove (t->thread_specifics, key); + if (key < t->thread_specifics_size) + t->thread_specifics[key] = 0; } __pthread_rwlock_unlock (&__pthread_threads_lock); } diff --git a/sysdeps/hurd/pt-key.h b/sysdeps/hurd/pt-key.h index 7b6a2c2..46830d7 100644 --- a/sysdeps/hurd/pt-key.h +++ b/sysdeps/hurd/pt-key.h @@ -18,11 +18,11 @@ Boston, MA 02111-1307, USA. */ #include -#include #include #define PTHREAD_KEY_MEMBERS \ - hurd_ihash_t thread_specifics; + void **thread_specifics; /* This is only resized by the thread, and always growing */ \ + unsigned thread_specifics_size; /* Number of entries in thread_specifics */ #define PTHREAD_KEY_INVALID (void *) (-1) diff --git a/sysdeps/hurd/pt-setspecific.c b/sysdeps/hurd/pt-setspecific.c index b3976cc..871560c 100644 --- a/sysdeps/hurd/pt-setspecific.c +++ b/sysdeps/hurd/pt-setspecific.c @@ -18,31 +18,34 @@ Boston, MA 02111-1307, USA. */ #include -#include #include int __pthread_setspecific (pthread_key_t key, const void *value) { - error_t err; struct __pthread *self = _pthread_self (); if (key < 0 || key >= __pthread_key_count || __pthread_key_destructors[key] == PTHREAD_KEY_INVALID) return EINVAL; - if (! self->thread_specifics) + if (key >= self->thread_specifics_size) { - err = hurd_ihash_create (&self->thread_specifics, HURD_IHASH_NO_LOCP); - if (err) + /* Amortize reallocation cost. */ + int newsize = 2 * key + 1; + void **new = realloc (self->thread_specifics, + newsize * sizeof (new[0])); + if (! new ) return ENOMEM; + + memset (&new[self->thread_specifics_size], 0, + (newsize - self->thread_specifics_size) * sizeof (new[0])); + self->thread_specifics = new; + self->thread_specifics_size = newsize; } - err = hurd_ihash_add (self->thread_specifics, key, (void *) value); - if (err) - return ENOMEM; - + self->thread_specifics[key] = (void*) value; return 0; } strong_alias (__pthread_setspecific, pthread_setspecific); -- cgit v1.2.3 From 64727f50e23a744e1607cb6aff72f0813d56c6c9 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 26 Sep 2017 21:29:14 +0200 Subject: Avoid exposing mach_port_set_qlimit * sysdeps/mach/pt-thread-alloc.c (create_wakeupmsg): Call __mach_port_set_qlimit instead of mach_port_set_qlimit. --- sysdeps/mach/pt-thread-alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/pt-thread-alloc.c b/sysdeps/mach/pt-thread-alloc.c index 77aa933..76e5660 100644 --- a/sysdeps/mach/pt-thread-alloc.c +++ b/sysdeps/mach/pt-thread-alloc.c @@ -56,8 +56,8 @@ create_wakeupmsg (struct __pthread *thread) } /* No need to queue more than one wakeup message on this port. */ - mach_port_set_qlimit (__mach_task_self (), - thread->wakeupmsg.msgh_remote_port, 1); + __mach_port_set_qlimit (__mach_task_self (), + thread->wakeupmsg.msgh_remote_port, 1); return 0; } -- cgit v1.2.3 From c5446ccd59e5b3adb89071167bcf0ff26303c57e Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Nov 2017 12:14:16 +0100 Subject: Add missing internal names Follow-up 2b7d0800f314e0abf370b2b6f6272a2ddb875464 ('Fix exposing symbols') * sysdeps/generic/pt-mutexattr-destroy.c (__pthread_mutexattr_destroy): Define. (pthread_mutexattr_destroy): Redefine as alias. * sysdeps/generic/pt-mutexattr-init.c (__pthread_mutexattr_init): Define. (pthread_mutexattr_init): Redefine as alias. * sysdeps/generic/pt-mutexattr-settype.c (__pthread_mutexattr_settype): Define. (pthread_mutexattr_settype): Redefine as alias. --- sysdeps/generic/pt-mutexattr-destroy.c | 3 ++- sysdeps/generic/pt-mutexattr-init.c | 3 ++- sysdeps/generic/pt-mutexattr-settype.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sysdeps/generic/pt-mutexattr-destroy.c b/sysdeps/generic/pt-mutexattr-destroy.c index fe7e95d..fc0479b 100644 --- a/sysdeps/generic/pt-mutexattr-destroy.c +++ b/sysdeps/generic/pt-mutexattr-destroy.c @@ -21,7 +21,8 @@ #include int -pthread_mutexattr_destroy (pthread_mutexattr_t *attr) +__pthread_mutexattr_destroy (pthread_mutexattr_t *attr) { return 0; } +weak_alias (__pthread_mutexattr_destroy, pthread_mutexattr_destroy) diff --git a/sysdeps/generic/pt-mutexattr-init.c b/sysdeps/generic/pt-mutexattr-init.c index 2f23673..82f5da2 100644 --- a/sysdeps/generic/pt-mutexattr-init.c +++ b/sysdeps/generic/pt-mutexattr-init.c @@ -21,8 +21,9 @@ #include int -pthread_mutexattr_init (pthread_mutexattr_t *attr) +__pthread_mutexattr_init (pthread_mutexattr_t *attr) { *attr = __pthread_default_mutexattr; return 0; } +weak_alias (__pthread_mutexattr_init, pthread_mutexattr_init) diff --git a/sysdeps/generic/pt-mutexattr-settype.c b/sysdeps/generic/pt-mutexattr-settype.c index 5c46010..7a7ce35 100644 --- a/sysdeps/generic/pt-mutexattr-settype.c +++ b/sysdeps/generic/pt-mutexattr-settype.c @@ -21,7 +21,7 @@ #include int -pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) +__pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) { switch (type) { @@ -35,3 +35,4 @@ pthread_mutexattr_settype (pthread_mutexattr_t *attr, int type) return EINVAL; } } +weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype) -- cgit v1.2.3 From b279c3618db5740e155c110e8dca395132b53ecd Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Nov 2017 13:00:31 +0100 Subject: Install missing headers * Makefile (headers): Add bits/pthreadtypes-arch.h and bits/thread-shared-types.h. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 3f59924..94f8576 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,8 @@ headers := \ bits/pthread.h \ bits/pthread-np.h \ bits/pthreadtypes.h \ + bits/pthreadtypes-arch.h \ + bits/thread-shared-types.h \ bits/mutex.h \ bits/condition.h \ bits/condition-attr.h \ -- cgit v1.2.3 From 8f03a364f803ad878ea3ab226fd2955ed4565495 Mon Sep 17 00:00:00 2001 From: Agustina Arzille Date: Tue, 18 Oct 2016 00:20:45 +0200 Subject: Make pthread_spinlock use gsync * pthread/pt-spin-inlines.c (pthread_spin_lock): Define weak alias for __pthread_spin_lock. * sysdeps/mach/bits/spin-lock-inline.h: Include instead of . (__pthread_spin_trylock, __pthread_spin_unlock): Use __spin_lock_t type instead of __lock. (__pthread_spin_lock): Define as inline only, use __spin_lock and __spin_lock_t type. * sysdeps/mach/bits/spin-lock.h: Do not include (__pthread_spinlock_t): Use volatile int instead of __spin_lock_t. (__PTHREAD_SPIN_LOCK_INITIALIZER): Define to 0. * sysdeps/mach/i386/bits/spin-lock-inline.h: Remove file. * sysdeps/mach/i386/bits/spin-lock.h: Remove file. * sysdeps/posix/pt-spin.c (pthread_spin_lock, __pthread_spin_lock): Remove weak aliases, provided by pt-spin-inlines.c --- pthread/pt-spin-inlines.c | 5 +- sysdeps/mach/bits/spin-lock-inline.h | 14 ++--- sysdeps/mach/bits/spin-lock.h | 7 +-- sysdeps/mach/i386/bits/spin-lock-inline.h | 98 ------------------------------- sysdeps/mach/i386/bits/spin-lock.h | 39 ------------ sysdeps/mach/pt-spin.c | 8 +-- sysdeps/posix/pt-spin.c | 3 - 7 files changed, 12 insertions(+), 162 deletions(-) delete mode 100644 sysdeps/mach/i386/bits/spin-lock-inline.h delete mode 100644 sysdeps/mach/i386/bits/spin-lock.h diff --git a/pthread/pt-spin-inlines.c b/pthread/pt-spin-inlines.c index cfb21dd..97afb4d 100644 --- a/pthread/pt-spin-inlines.c +++ b/pthread/pt-spin-inlines.c @@ -25,10 +25,9 @@ #include -/* Weak aliases for the spin lock functions. Note that - pthread_spin_lock is left out deliberately. We already provide an - implementation for it in pt-spin.c. */ +/* Weak aliases for the spin lock functions. */ weak_alias (__pthread_spin_destroy, pthread_spin_destroy); weak_alias (__pthread_spin_init, pthread_spin_init); weak_alias (__pthread_spin_trylock, pthread_spin_trylock); +weak_alias (__pthread_spin_lock, pthread_spin_lock); weak_alias (__pthread_spin_unlock, pthread_spin_unlock); diff --git a/sysdeps/mach/bits/spin-lock-inline.h b/sysdeps/mach/bits/spin-lock-inline.h index f9f7c29..98e4b3b 100644 --- a/sysdeps/mach/bits/spin-lock-inline.h +++ b/sysdeps/mach/bits/spin-lock-inline.h @@ -22,7 +22,7 @@ #include #include -#include /* This does all the work. */ +#include /* This does all the work. */ __BEGIN_DECLS @@ -60,17 +60,15 @@ __PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock); __PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock) { - return __spin_try_lock (__lock) ? 0 : __EBUSY; + return __spin_try_lock ((__spin_lock_t *) __lock) ? 0 : __EBUSY; } -__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock); -extern int _pthread_spin_lock (__pthread_spinlock_t *__lock); +__PT_SPIN_INLINE int __pthread_spin_lock (__pthread_spinlock_t *__lock); -__extern_inline int +__PT_SPIN_INLINE int __pthread_spin_lock (__pthread_spinlock_t *__lock) { - if (__pthread_spin_trylock (__lock)) - return _pthread_spin_lock (__lock); + __spin_lock ((__spin_lock_t *) __lock); return 0; } @@ -79,7 +77,7 @@ __PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock); __PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock) { - __spin_unlock (__lock); + __spin_unlock ((__spin_lock_t *) __lock); return 0; } diff --git a/sysdeps/mach/bits/spin-lock.h b/sysdeps/mach/bits/spin-lock.h index 537dac9..7574b37 100644 --- a/sysdeps/mach/bits/spin-lock.h +++ b/sysdeps/mach/bits/spin-lock.h @@ -21,17 +21,14 @@ #define _BITS_SPIN_LOCK_H 1 #include -#include /* This does all the work. */ __BEGIN_DECLS /* The type of a spin lock object. */ -typedef __spin_lock_t __pthread_spinlock_t; +typedef volatile int __pthread_spinlock_t; /* Initializer for a spin lock object. */ -#ifndef __PTHREAD_SPIN_LOCK_INITIALIZER -#error __PTHREAD_SPIN_LOCK_INITIALIZER undefined: should be defined by . -#endif +#define __PTHREAD_SPIN_LOCK_INITIALIZER 0 __END_DECLS diff --git a/sysdeps/mach/i386/bits/spin-lock-inline.h b/sysdeps/mach/i386/bits/spin-lock-inline.h deleted file mode 100644 index e5ed3de..0000000 --- a/sysdeps/mach/i386/bits/spin-lock-inline.h +++ /dev/null @@ -1,98 +0,0 @@ -/* Machine-specific definitions for spin locks. i386 version. - Copyright (C) 2000, 2005, 2008, 2009 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* - * Never include this file directly; use or instead. - */ - -#ifndef _BITS_SPIN_LOCK_INLINE_H -#define _BITS_SPIN_LOCK_INLINE_H 1 - -#include -#include - -__BEGIN_DECLS - -#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES - -# ifndef __EBUSY -# include -# define __EBUSY EBUSY -# endif - -# ifndef __PT_SPIN_INLINE -# define __PT_SPIN_INLINE __extern_inline -# endif - -__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock); - -__PT_SPIN_INLINE int -__pthread_spin_destroy (__pthread_spinlock_t *__lock) -{ - return 0; -} - -__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock, - int __pshared); - -__PT_SPIN_INLINE int -__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared) -{ - *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER; - return 0; -} - -__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock); - -__PT_SPIN_INLINE int -__pthread_spin_trylock (__pthread_spinlock_t *__lock) -{ - int __locked; - __asm__ __volatile ("xchgl %0, %1" - : "=&r" (__locked), "=m" (*__lock) : "0" (1) : "memory"); - return __locked ? __EBUSY : 0; -} - -__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock); -extern int _pthread_spin_lock (__pthread_spinlock_t *__lock); - -__extern_inline int -__pthread_spin_lock (__pthread_spinlock_t *__lock) -{ - if (__pthread_spin_trylock (__lock)) - return _pthread_spin_lock (__lock); - return 0; -} - -__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock); - -__PT_SPIN_INLINE int -__pthread_spin_unlock (__pthread_spinlock_t *__lock) -{ - int __unlocked; - __asm__ __volatile ("xchgl %0, %1" - : "=&r" (__unlocked), "=m" (*__lock) : "0" (0) : "memory"); - return 0; -} - -#endif /* Use extern inlines or force inlines. */ - -__END_DECLS - -#endif /* bits/spin-lock.h */ diff --git a/sysdeps/mach/i386/bits/spin-lock.h b/sysdeps/mach/i386/bits/spin-lock.h deleted file mode 100644 index 5ae81e1..0000000 --- a/sysdeps/mach/i386/bits/spin-lock.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Machine-specific definitions for spin locks. i386 version. - Copyright (C) 2000, 2005, 2008, 2009 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* - * Never include this file directly; use or instead. - */ - -#ifndef _BITS_SPIN_LOCK_H -#define _BITS_SPIN_LOCK_H 1 - -#include - -__BEGIN_DECLS - -/* The type of a spin lock object. */ -typedef __volatile int __pthread_spinlock_t; - -/* Initializer for a spin lock object. */ -# define __PTHREAD_SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0) - -__END_DECLS - -#endif /* bits/spin-lock.h */ diff --git a/sysdeps/mach/pt-spin.c b/sysdeps/mach/pt-spin.c index d9a2a32..0cf1c49 100644 --- a/sysdeps/mach/pt-spin.c +++ b/sysdeps/mach/pt-spin.c @@ -17,20 +17,16 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include #include /* In glibc. */ -extern void __spin_lock_solid (__pthread_spinlock_t *lock); +extern void __spin_lock_solid (__spin_lock_t *lock); /* Lock the spin lock object LOCK. If the lock is held by another thread spin until it becomes available. */ int -_pthread_spin_lock (__pthread_spinlock_t *lock) +_pthread_spin_lock (__spin_lock_t *lock) { __spin_lock_solid (lock); return 0; } - -weak_alias (_pthread_spin_lock, pthread_spin_lock); -weak_alias (_pthread_spin_lock, __pthread_spin_lock); diff --git a/sysdeps/posix/pt-spin.c b/sysdeps/posix/pt-spin.c index cb809c6..07f8936 100644 --- a/sysdeps/posix/pt-spin.c +++ b/sysdeps/posix/pt-spin.c @@ -49,6 +49,3 @@ _pthread_spin_lock (__pthread_spinlock_t *lock) __sched_yield (); } } - -weak_alias (_pthread_spin_lock, pthread_spin_lock); -weak_alias (_pthread_spin_lock, __pthread_spin_lock); -- cgit v1.2.3 From 7d4a84731cd80a1ef711c83535c6340f0e2b143f Mon Sep 17 00:00:00 2001 From: Agustina Arzille Date: Mon, 17 Oct 2016 00:56:58 +0200 Subject: Make pthread_mutex use gsync * Makefile (libpthread-routines): Add pt-mutexattr-getrobust pt-mutexattr-setrobust pt-mutex-consistent. * include/pthread/pthreadtypes.h (__pthread_mutex_robustness): New enum, containing __PTHREAD_MUTEX_STALLED, __PTHREAD_MUTEX_ROBUST. * include/pthread/pthread.h [__USE_XOPEN2K] (PTHREAD_MUTEX_STALLED, PTHREAD_MUTEX_ROBUST): New macros. [__USE_XOPEN2K8] (pthread_mutex_consistent, pthread_mutex_consistent_np): New declarations. * sysdeps/mach/hurd/bits/mutex.h sysdeps/mach/hurd/pt-mutex-consistent.c sysdeps/mach/hurd/pt-mutex-destroy.c sysdeps/mach/hurd/pt-mutex-getprioceiling.c sysdeps/mach/hurd/pt-mutex-init.c sysdeps/mach/hurd/pt-mutex-lock.c sysdeps/mach/hurd/pt-mutex-setprioceiling.c sysdeps/mach/hurd/pt-mutex-timedlock.c sysdeps/mach/hurd/pt-mutex-transfer-np.c sysdeps/mach/hurd/pt-mutex-trylock.c sysdeps/mach/hurd/pt-mutex-unlock.c sysdeps/mach/hurd/pt-mutex.h sysdeps/mach/hurd/pt-mutexattr-destroy.c sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c sysdeps/mach/hurd/pt-mutexattr-getprotocol.c sysdeps/mach/hurd/pt-mutexattr-getpshared.c sysdeps/mach/hurd/pt-mutexattr-getrobust.c sysdeps/mach/hurd/pt-mutexattr-gettype.c sysdeps/mach/hurd/pt-mutexattr-init.c sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c sysdeps/mach/hurd/pt-mutexattr-setprotocol.c sysdeps/mach/hurd/pt-mutexattr-setpshared.c sysdeps/mach/hurd/pt-mutexattr-setrobust.c sysdeps/mach/hurd/pt-mutexattr-settype.c sysdeps/mach/hurd/pt-mutexattr.c: New files --- Makefile | 2 + include/pthread/pthread.h | 17 +++++ include/pthread/pthreadtypes.h | 6 ++ sysdeps/mach/hurd/bits/mutex.h | 64 +++++++++++++++++ sysdeps/mach/hurd/pt-mutex-consistent.c | 45 ++++++++++++ sysdeps/mach/hurd/pt-mutex-destroy.c | 36 ++++++++++ sysdeps/mach/hurd/pt-mutex-getprioceiling.c | 32 +++++++++ sysdeps/mach/hurd/pt-mutex-init.c | 55 +++++++++++++++ sysdeps/mach/hurd/pt-mutex-lock.c | 79 +++++++++++++++++++++ sysdeps/mach/hurd/pt-mutex-setprioceiling.c | 32 +++++++++ sysdeps/mach/hurd/pt-mutex-timedlock.c | 80 +++++++++++++++++++++ sysdeps/mach/hurd/pt-mutex-transfer-np.c | 74 ++++++++++++++++++++ sysdeps/mach/hurd/pt-mutex-trylock.c | 77 +++++++++++++++++++++ sysdeps/mach/hurd/pt-mutex-unlock.c | 90 ++++++++++++++++++++++++ sysdeps/mach/hurd/pt-mutex.h | 92 +++++++++++++++++++++++++ sysdeps/mach/hurd/pt-mutexattr-destroy.c | 31 +++++++++ sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c | 32 +++++++++ sysdeps/mach/hurd/pt-mutexattr-getprotocol.c | 30 ++++++++ sysdeps/mach/hurd/pt-mutexattr-getpshared.c | 30 ++++++++ sysdeps/mach/hurd/pt-mutexattr-getrobust.c | 33 +++++++++ sysdeps/mach/hurd/pt-mutexattr-gettype.c | 31 +++++++++ sysdeps/mach/hurd/pt-mutexattr-init.c | 39 +++++++++++ sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c | 32 +++++++++ sysdeps/mach/hurd/pt-mutexattr-setprotocol.c | 32 +++++++++ sysdeps/mach/hurd/pt-mutexattr-setpshared.c | 34 +++++++++ sysdeps/mach/hurd/pt-mutexattr-setrobust.c | 36 ++++++++++ sysdeps/mach/hurd/pt-mutexattr-settype.c | 34 +++++++++ sysdeps/mach/hurd/pt-mutexattr.c | 1 + 28 files changed, 1176 insertions(+) create mode 100644 sysdeps/mach/hurd/bits/mutex.h create mode 100644 sysdeps/mach/hurd/pt-mutex-consistent.c create mode 100644 sysdeps/mach/hurd/pt-mutex-destroy.c create mode 100644 sysdeps/mach/hurd/pt-mutex-getprioceiling.c create mode 100644 sysdeps/mach/hurd/pt-mutex-init.c create mode 100644 sysdeps/mach/hurd/pt-mutex-lock.c create mode 100644 sysdeps/mach/hurd/pt-mutex-setprioceiling.c create mode 100644 sysdeps/mach/hurd/pt-mutex-timedlock.c create mode 100644 sysdeps/mach/hurd/pt-mutex-transfer-np.c create mode 100644 sysdeps/mach/hurd/pt-mutex-trylock.c create mode 100644 sysdeps/mach/hurd/pt-mutex-unlock.c create mode 100644 sysdeps/mach/hurd/pt-mutex.h create mode 100644 sysdeps/mach/hurd/pt-mutexattr-destroy.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-getprotocol.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-getpshared.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-getrobust.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-gettype.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-init.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-setprotocol.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-setpshared.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-setrobust.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr-settype.c create mode 100644 sysdeps/mach/hurd/pt-mutexattr.c diff --git a/Makefile b/Makefile index 94f8576..39e7f4c 100644 --- a/Makefile +++ b/Makefile @@ -87,12 +87,14 @@ libpthread-routines := pt-attr pt-attr-destroy pt-attr-getdetachstate \ pt-mutexattr-getpshared pt-mutexattr-gettype \ pt-mutexattr-setprioceiling pt-mutexattr-setprotocol \ pt-mutexattr-setpshared pt-mutexattr-settype \ + pt-mutexattr-getrobust pt-mutexattr-setrobust \ \ pt-mutex-init pt-mutex-destroy \ pt-mutex-lock pt-mutex-trylock pt-mutex-timedlock \ pt-mutex-unlock \ pt-mutex-transfer-np \ pt-mutex-getprioceiling pt-mutex-setprioceiling \ + pt-mutex-consistent \ \ pt-rwlock-attr \ pt-rwlockattr-init pt-rwlockattr-destroy \ diff --git a/include/pthread/pthread.h b/include/pthread/pthread.h index 350a673..ad34e5d 100644 --- a/include/pthread/pthread.h +++ b/include/pthread/pthread.h @@ -271,6 +271,11 @@ extern pthread_t pthread_self (void) __THROW; #define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_TIMED_NP #endif +#ifdef __USE_XOPEN2K +#define PTHREAD_MUTEX_STALLED __PTHREAD_MUTEX_STALLED +#define PTHREAD_MUTEX_ROBUST __PTHREAD_MUTEX_ROBUST +#endif + #include /* Initialize the mutex attribute object in *ATTR to the default @@ -399,6 +404,18 @@ extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, __THROW __nonnull ((1, 3)); #endif +#ifdef __USE_XOPEN2K8 + +/* Declare the state protected by robust mutex MTXP as consistent. */ +extern int pthread_mutex_consistent (pthread_mutex_t *__mtxp) + __THROW __nonnull ((1)); + +# ifdef __USE_GNU +extern int pthread_mutex_consistent_np (pthread_mutex_t *__mtxp) + __THROW __nonnull ((1)); +# endif +#endif + /* Condition attributes. */ diff --git a/include/pthread/pthreadtypes.h b/include/pthread/pthreadtypes.h index 33bd009..d8aed4d 100644 --- a/include/pthread/pthreadtypes.h +++ b/include/pthread/pthreadtypes.h @@ -77,6 +77,12 @@ enum __pthread_mutex_type __PTHREAD_MUTEX_RECURSIVE }; +enum __pthread_mutex_robustness + { + __PTHREAD_MUTEX_STALLED, + __PTHREAD_MUTEX_ROBUST = 0x100 + }; + #include typedef struct __pthread_mutexattr pthread_mutexattr_t; diff --git a/sysdeps/mach/hurd/bits/mutex.h b/sysdeps/mach/hurd/bits/mutex.h new file mode 100644 index 0000000..a52a2ad --- /dev/null +++ b/sysdeps/mach/hurd/bits/mutex.h @@ -0,0 +1,64 @@ +/* Mutex type. Generic version. + + Copyright (C) 2000-2016 + Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _BITS_MUTEX_H + +#ifndef __need_pthread_mutex +# define _BITS_MUTEX_H 1 +#endif + +#ifndef __pthread_mutex_defined +# if defined __need_pthread_mutex || defined _BITS_MUTEX_H +# undef __need_pthread_mutex +# define __pthread_mutex_defined + +# include + +/* User visible part of a mutex. */ +struct __pthread_mutex +{ + unsigned int __lock; + unsigned int __owner_id; + unsigned int __cnt; + int __shpid; + int __type; + int __flags; + unsigned int __reserved1; + unsigned int __reserved2; +}; + +/* Static mutex initializers. */ +#define __PTHREAD_MUTEX_INITIALIZER \ + { 0, 0, 0, 0, __PTHREAD_MUTEX_TIMED, 0, 0, 0 } + +/* The +1 is to mantain binary compatibility with the old + * libpthread implementation. */ +#define __PTHREAD_ERRORCHECK_MUTEX_INITIALIZER \ + { 0, 0, 0, 0, __PTHREAD_MUTEX_ERRORCHECK + 1, 0, 0, 0 } + +#define __PTHREAD_RECURSIVE_MUTEX_INITIALIZER \ + { 0, 0, 0, 0, __PTHREAD_MUTEX_RECURSIVE + 1, 0, 0, 0 } + +# endif +#endif /* Not __pthread_mutex_defined. */ + +#endif /* bits/mutex.h */ diff --git a/sysdeps/mach/hurd/pt-mutex-consistent.c b/sysdeps/mach/hurd/pt-mutex-consistent.c new file mode 100644 index 0000000..28e9e4a --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-consistent.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutex_consistent (pthread_mutex_t *mtxp) +{ + int ret = EINVAL; + unsigned int val = mtxp->__lock; + + if ((mtxp->__flags & PTHREAD_MUTEX_ROBUST) != 0 && + (val & LLL_DEAD_OWNER) != 0 && + atomic_compare_and_exchange_bool_acq (&mtxp->__lock, + __getpid () | LLL_WAITERS, val) == 0) + { + /* The mutex is now ours, and it's consistent. */ + mtxp->__owner_id = _pthread_self()->thread; + mtxp->__cnt = 1; + ret = 0; + } + + return (ret); +} + +weak_alias (pthread_mutex_consistent, pthread_mutex_consistent_np) diff --git a/sysdeps/mach/hurd/pt-mutex-destroy.c b/sysdeps/mach/hurd/pt-mutex-destroy.c new file mode 100644 index 0000000..2c6acd1 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-destroy.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int _pthread_mutex_destroy (pthread_mutex_t *mtxp) +{ + atomic_read_barrier (); + if (*(volatile unsigned int *)&mtxp->__lock != 0) + return (EBUSY); + + mtxp->__type = -1; + return (0); +} + +strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy) diff --git a/sysdeps/mach/hurd/pt-mutex-getprioceiling.c b/sysdeps/mach/hurd/pt-mutex-getprioceiling.c new file mode 100644 index 0000000..8a8a080 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-getprioceiling.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutex_getprioceiling (const pthread_mutex_t *mtxp, int *clp) +{ + (void)mtxp; (void)clp; + return (ENOSYS); +} + +stub_warning (pthread_mutex_getprioceiling) diff --git a/sysdeps/mach/hurd/pt-mutex-init.c b/sysdeps/mach/hurd/pt-mutex-init.c new file mode 100644 index 0000000..af9ed7e --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-init.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +static const pthread_mutexattr_t dfl_attr = +{ + .__prioceiling = 0, + .__protocol = PTHREAD_PRIO_NONE, + .__pshared = PTHREAD_PROCESS_PRIVATE, + .__mutex_type = __PTHREAD_MUTEX_TIMED +}; + +int _pthread_mutex_init (pthread_mutex_t *mtxp, + const pthread_mutexattr_t *attrp) +{ + if (attrp == NULL) + attrp = &dfl_attr; + + mtxp->__flags = (attrp->__pshared == PTHREAD_PROCESS_SHARED ? + GSYNC_SHARED : 0) | ((attrp->__prioceiling & PTHREAD_MUTEX_ROBUST) ? + PTHREAD_MUTEX_ROBUST : 0); + + mtxp->__type = attrp->__mutex_type + + (attrp->__mutex_type != __PTHREAD_MUTEX_TIMED); + + mtxp->__owner_id = 0; + mtxp->__shpid = 0; + mtxp->__cnt = 0; + mtxp->__lock = 0; + + return (0); +} + +strong_alias (_pthread_mutex_init, pthread_mutex_init) diff --git a/sysdeps/mach/hurd/pt-mutex-lock.c b/sysdeps/mach/hurd/pt-mutex-lock.c new file mode 100644 index 0000000..5d3c958 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-lock.c @@ -0,0 +1,79 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int __pthread_mutex_lock (pthread_mutex_t *mtxp) +{ + struct __pthread *self; + int flags = mtxp->__flags & GSYNC_SHARED; + int ret = 0; + + switch (MTX_TYPE (mtxp)) + { + case PT_MTX_NORMAL: + lll_lock (&mtxp->__lock, flags); + break; + + case PT_MTX_RECURSIVE: + self = _pthread_self (); + if (mtx_owned_p (mtxp, self, flags)) + { + if (__glibc_unlikely (mtxp->__cnt + 1 == 0)) + return (EAGAIN); + + ++mtxp->__cnt; + return (ret); + } + + lll_lock (&mtxp->__lock, flags); + mtx_set_owner (mtxp, self, flags); + mtxp->__cnt = 1; + break; + + case PT_MTX_ERRORCHECK: + self = _pthread_self (); + if (mtx_owned_p (mtxp, self, flags)) + return (EDEADLK); + + lll_lock (&mtxp->__lock, flags); + mtx_set_owner (mtxp, self, flags); + break; + + case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST: + case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST: + case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST: + self = _pthread_self (); + ROBUST_LOCK (self, mtxp, __lll_robust_lock, flags); + break; + + default: + ret = EINVAL; + break; + } + + return (ret); +} + +strong_alias (__pthread_mutex_lock, _pthread_mutex_lock) +strong_alias (__pthread_mutex_lock, pthread_mutex_lock) diff --git a/sysdeps/mach/hurd/pt-mutex-setprioceiling.c b/sysdeps/mach/hurd/pt-mutex-setprioceiling.c new file mode 100644 index 0000000..b88917d --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-setprioceiling.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutex_setprioceiling (pthread_mutex_t *mtxp, int cl, int *prp) +{ + (void)mtxp; (void)cl; (void)prp; + return (ENOSYS); +} + +stub_warning (pthread_mutex_setprioceiling) diff --git a/sysdeps/mach/hurd/pt-mutex-timedlock.c b/sysdeps/mach/hurd/pt-mutex-timedlock.c new file mode 100644 index 0000000..3fdd5da --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-timedlock.c @@ -0,0 +1,80 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutex_timedlock (pthread_mutex_t *mtxp, + const struct timespec *tsp) +{ + struct __pthread *self; + int ret, flags = mtxp->__flags & GSYNC_SHARED; + + switch (MTX_TYPE (mtxp)) + { + case PT_MTX_NORMAL: + ret = lll_abstimed_lock (&mtxp->__lock, tsp, flags); + break; + + case PT_MTX_RECURSIVE: + self = _pthread_self (); + if (mtx_owned_p (mtxp, self, flags)) + { + if (__glibc_unlikely (mtxp->__cnt + 1 == 0)) + return (EAGAIN); + + ++mtxp->__cnt; + ret = 0; + } + else if ((ret = lll_abstimed_lock (&mtxp->__lock, + tsp, flags)) == 0) + { + mtx_set_owner (mtxp, self, flags); + mtxp->__cnt = 1; + } + + break; + + case PT_MTX_ERRORCHECK: + self = _pthread_self (); + if (mtx_owned_p (mtxp, self, flags)) + ret = EDEADLK; + else if ((ret = lll_abstimed_lock (&mtxp->__lock, + tsp, flags)) == 0) + mtx_set_owner (mtxp, self, flags); + + break; + + case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST: + case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST: + case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST: + self = _pthread_self (); + ROBUST_LOCK (self, mtxp, lll_robust_abstimed_lock, tsp, flags); + break; + + default: + ret = EINVAL; + break; + } + + return (ret); +} diff --git a/sysdeps/mach/hurd/pt-mutex-transfer-np.c b/sysdeps/mach/hurd/pt-mutex-transfer-np.c new file mode 100644 index 0000000..410474f --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-transfer-np.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int __pthread_mutex_transfer_np (pthread_mutex_t *mtxp, pthread_t th) +{ + struct __pthread *self = _pthread_self (); + struct __pthread *pt = __pthread_getid (th); + + if (!pt) + return (ESRCH); + else if (pt == self) + return (0); + + int ret = 0; + int flags = mtxp->__flags & GSYNC_SHARED; + + switch (MTX_TYPE (mtxp)) + { + case PT_MTX_NORMAL: + break; + + case PT_MTX_RECURSIVE: + case PT_MTX_ERRORCHECK: + if (!mtx_owned_p (mtxp, self, flags)) + ret = EPERM; + else + mtx_set_owner (mtxp, pt, flags); + + break; + + case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST: + case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST: + case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST: + /* Note that this can be used to transfer an inconsistent + * mutex as well. The new owner will still have the same + * flags as the original. */ + if (mtxp->__owner_id != self->thread || + (int)(mtxp->__lock & LLL_OWNER_MASK) != __getpid ()) + ret = EPERM; + else + mtxp->__owner_id = pt->thread; + + break; + + default: + ret = EINVAL; + } + + return (ret); +} + +weak_alias (__pthread_mutex_transfer_np, pthread_mutex_transfer_np) diff --git a/sysdeps/mach/hurd/pt-mutex-trylock.c b/sysdeps/mach/hurd/pt-mutex-trylock.c new file mode 100644 index 0000000..6680094 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-trylock.c @@ -0,0 +1,77 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int __pthread_mutex_trylock (pthread_mutex_t *mtxp) +{ + struct __pthread *self; + int ret; + + switch (MTX_TYPE (mtxp)) + { + case PT_MTX_NORMAL: + ret = lll_trylock (&mtxp->__lock); + break; + + case PT_MTX_RECURSIVE: + self = _pthread_self (); + if (mtx_owned_p (mtxp, self, mtxp->__flags)) + { + if (__glibc_unlikely (mtxp->__cnt + 1 == 0)) + return (EAGAIN); + + ++mtxp->__cnt; + ret = 0; + } + else if ((ret = lll_trylock (&mtxp->__lock)) == 0) + { + mtx_set_owner (mtxp, self, mtxp->__flags); + mtxp->__cnt = 1; + } + + break; + + case PT_MTX_ERRORCHECK: + self = _pthread_self (); + if ((ret = lll_trylock (&mtxp->__lock)) == 0) + mtx_set_owner (mtxp, self, mtxp->__flags); + break; + + case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST: + case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST: + case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST: + self = _pthread_self (); + ROBUST_LOCK (self, mtxp, __lll_robust_trylock); + break; + + default: + ret = EINVAL; + break; + } + + return (ret); +} + +strong_alias (__pthread_mutex_trylock, _pthread_mutex_trylock) +strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock) diff --git a/sysdeps/mach/hurd/pt-mutex-unlock.c b/sysdeps/mach/hurd/pt-mutex-unlock.c new file mode 100644 index 0000000..071f622 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex-unlock.c @@ -0,0 +1,90 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int __pthread_mutex_unlock (pthread_mutex_t *mtxp) +{ + struct __pthread *self; + int ret = 0, flags = mtxp->__flags & GSYNC_SHARED; + + switch (MTX_TYPE (mtxp)) + { + case PT_MTX_NORMAL: + lll_unlock (&mtxp->__lock, flags); + break; + + case PT_MTX_RECURSIVE: + self = _pthread_self (); + if (!mtx_owned_p (mtxp, self, flags)) + ret = EPERM; + else if (--mtxp->__cnt == 0) + { + mtxp->__owner_id = mtxp->__shpid = 0; + lll_unlock (&mtxp->__lock, flags); + } + + break; + + case PT_MTX_ERRORCHECK: + self = _pthread_self (); + if (!mtx_owned_p (mtxp, self, flags)) + ret = EPERM; + else + { + mtxp->__owner_id = mtxp->__shpid = 0; + lll_unlock (&mtxp->__lock, flags); + } + + break; + + case PT_MTX_NORMAL | PTHREAD_MUTEX_ROBUST: + case PT_MTX_RECURSIVE | PTHREAD_MUTEX_ROBUST: + case PT_MTX_ERRORCHECK | PTHREAD_MUTEX_ROBUST: + self = _pthread_self (); + if (mtxp->__owner_id == NOTRECOVERABLE_ID) + ; /* Nothing to do. */ + else if (mtxp->__owner_id != self->thread || + (int)(mtxp->__lock & LLL_OWNER_MASK) != __getpid ()) + ret = EPERM; + else if (--mtxp->__cnt == 0) + { + /* Release the lock. If it's in an inconsistent + * state, mark it as irrecoverable. */ + mtxp->__owner_id = (mtxp->__lock & LLL_DEAD_OWNER) ? + NOTRECOVERABLE_ID : 0; + __lll_robust_unlock (&mtxp->__lock, flags); + } + + break; + + default: + ret = EINVAL; + break; + } + + return (ret); +} + +strong_alias (__pthread_mutex_unlock, _pthread_mutex_unlock) +strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock) diff --git a/sysdeps/mach/hurd/pt-mutex.h b/sysdeps/mach/hurd/pt-mutex.h new file mode 100644 index 0000000..c67453e --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutex.h @@ -0,0 +1,92 @@ +/* Internal definitions for pthreads library. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Agustina Arzille , 2016. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _PT_MUTEX_H +#define _PT_MUTEX_H 1 + +/* Special ID used to signal an unrecoverable robust mutex. */ +#define NOTRECOVERABLE_ID (1U << 31) + +/* Common path for robust mutexes. Assumes the variable 'ret' + * is bound in the function this is called from. */ +#define ROBUST_LOCK(self, mtxp, cb, ...) \ + if (mtxp->__owner_id == NOTRECOVERABLE_ID) \ + return (ENOTRECOVERABLE); \ + else if (mtxp->__owner_id == self->thread && \ + __getpid () == (int)(mtxp->__lock & LLL_OWNER_MASK)) \ + { \ + if (mtxp->__type == PT_MTX_RECURSIVE) \ + { \ + if (__glibc_unlikely (mtxp->__cnt + 1 == 0)) \ + return (EAGAIN); \ + \ + ++mtxp->__cnt; \ + return (0); \ + } \ + else if (mtxp->__type == PT_MTX_ERRORCHECK) \ + return (EDEADLK); \ + } \ + \ + ret = cb (&mtxp->__lock, ##__VA_ARGS__); \ + if (ret == 0 || ret == EOWNERDEAD) \ + { \ + if (mtxp->__owner_id == ENOTRECOVERABLE) \ + ret = ENOTRECOVERABLE; \ + else \ + { \ + mtxp->__owner_id = self->thread; \ + mtxp->__cnt = 1; \ + if (ret == EOWNERDEAD) \ + { \ + mtxp->__lock = mtxp->__lock | LLL_DEAD_OWNER; \ + atomic_write_barrier (); \ + } \ + } \ + } \ + (void)0 + +/* Check that a thread owns the mutex. For non-robust, task-shared + * objects, we have to check the thread *and* process-id. */ +#define mtx_owned_p(mtx, pt, flags) \ + ((mtx)->__owner_id == (pt)->thread && \ + (((flags) & GSYNC_SHARED) == 0 || \ + (mtx)->__shpid == __getpid ())) + +/* Record a thread as the owner of the mutex. */ +#define mtx_set_owner(mtx, pt, flags) \ + (void) \ + ({ \ + (mtx)->__owner_id = (pt)->thread; \ + if ((flags) & GSYNC_SHARED) \ + (mtx)->__shpid = __getpid (); \ + }) + +/* Redefined mutex types. The +1 is for binary compatibility. */ +#define PT_MTX_NORMAL __PTHREAD_MUTEX_TIMED +#define PT_MTX_RECURSIVE (__PTHREAD_MUTEX_RECURSIVE + 1) +#define PT_MTX_ERRORCHECK (__PTHREAD_MUTEX_ERRORCHECK + 1) + +/* Mutex type, including robustness. */ +#define MTX_TYPE(mtxp) \ + ((mtxp)->__type | ((mtxp)->__flags & PTHREAD_MUTEX_ROBUST)) + +extern int __getpid (void) __attribute__ ((const)); + +#endif /* pt-mutex.h */ diff --git a/sysdeps/mach/hurd/pt-mutexattr-destroy.c b/sysdeps/mach/hurd/pt-mutexattr-destroy.c new file mode 100644 index 0000000..ad711ac --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-destroy.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int __pthread_mutexattr_destroy (pthread_mutexattr_t *attrp) +{ + (void)attrp; + return (0); +} +weak_alias (__pthread_mutexattr_destroy, pthread_mutexattr_destroy) diff --git a/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c b/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c new file mode 100644 index 0000000..bcfc8c8 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-getprioceiling.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *ap, int *clp) +{ + (void)ap; (void)clp; + return (ENOSYS); +} + +stub_warning (pthread_mutexattr_getprioceiling) diff --git a/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c b/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c new file mode 100644 index 0000000..cb94424 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-getprotocol.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attrp, int *ptp) +{ + *ptp = attrp->__protocol; + return (0); +} diff --git a/sysdeps/mach/hurd/pt-mutexattr-getpshared.c b/sysdeps/mach/hurd/pt-mutexattr-getpshared.c new file mode 100644 index 0000000..7639528 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-getpshared.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_getpshared (const pthread_mutexattr_t *attrp, int *outp) +{ + *outp = attrp->__pshared; + return (0); +} diff --git a/sysdeps/mach/hurd/pt-mutexattr-getrobust.c b/sysdeps/mach/hurd/pt-mutexattr-getrobust.c new file mode 100644 index 0000000..86a0909 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-getrobust.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_getrobust (const pthread_mutexattr_t *attrp, int *outp) +{ + *outp = (attrp->__prioceiling & PTHREAD_MUTEX_ROBUST) ? + PTHREAD_MUTEX_ROBUST : PTHREAD_MUTEX_STALLED; + return (0); +} + +weak_alias (pthread_mutexattr_getrobust, pthread_mutexattr_getrobust_np) diff --git a/sysdeps/mach/hurd/pt-mutexattr-gettype.c b/sysdeps/mach/hurd/pt-mutexattr-gettype.c new file mode 100644 index 0000000..746f628 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-gettype.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_gettype (const pthread_mutexattr_t *attrp, int *outp) +{ + *outp = attrp->__mutex_type; + return (0); +} + diff --git a/sysdeps/mach/hurd/pt-mutexattr-init.c b/sysdeps/mach/hurd/pt-mutexattr-init.c new file mode 100644 index 0000000..4cac661 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-init.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +static const pthread_mutexattr_t dfl_attr = +{ + .__prioceiling = 0, + .__protocol = PTHREAD_PRIO_NONE, + .__pshared = PTHREAD_PROCESS_PRIVATE, + .__mutex_type = __PTHREAD_MUTEX_TIMED +}; + +int __pthread_mutexattr_init (pthread_mutexattr_t *attrp) +{ + *attrp = dfl_attr; + return (0); +} +weak_alias (__pthread_mutexattr_init, pthread_mutexattr_init) diff --git a/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c b/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c new file mode 100644 index 0000000..d399050 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-setprioceiling.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *attrp, int cl) +{ + (void)attrp; (void)cl; + return (ENOSYS); +} + +stub_warning (pthread_mutexattr_setprioceiling) diff --git a/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c b/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c new file mode 100644 index 0000000..9f7f152 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-setprotocol.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attrp, int proto) +{ + (void)attrp; + return (proto == PTHREAD_PRIO_NONE ? 0 : + proto != PTHREAD_PRIO_INHERIT && + proto != PTHREAD_PRIO_PROTECT ? EINVAL : ENOTSUP); +} diff --git a/sysdeps/mach/hurd/pt-mutexattr-setpshared.c b/sysdeps/mach/hurd/pt-mutexattr-setpshared.c new file mode 100644 index 0000000..c10dfa0 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-setpshared.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_setpshared (pthread_mutexattr_t *attrp, int pshared) +{ + if (pshared != PTHREAD_PROCESS_PRIVATE && + pshared != PTHREAD_PROCESS_SHARED) + return (EINVAL); + + attrp->__pshared = pshared; + return (0); +} diff --git a/sysdeps/mach/hurd/pt-mutexattr-setrobust.c b/sysdeps/mach/hurd/pt-mutexattr-setrobust.c new file mode 100644 index 0000000..a90e747 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-setrobust.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int pthread_mutexattr_setrobust (pthread_mutexattr_t *attrp, int robust) +{ + if (robust != PTHREAD_MUTEX_ROBUST && + robust != PTHREAD_MUTEX_STALLED) + return (EINVAL); + + attrp->__prioceiling |= robust; + return (0); +} + +weak_alias (pthread_mutexattr_setrobust, pthread_mutexattr_setrobust_np) diff --git a/sysdeps/mach/hurd/pt-mutexattr-settype.c b/sysdeps/mach/hurd/pt-mutexattr-settype.c new file mode 100644 index 0000000..67ed4f5 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr-settype.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2016 Free Software Foundation, Inc. + Contributed by Agustina Arzille , 2016. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either + version 2 of the license, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, see + . +*/ + +#include +#include +#include +#include +#include "pt-mutex.h" +#include + +int __pthread_mutexattr_settype (pthread_mutexattr_t *attrp, int type) +{ + if (type < 0 || type > __PTHREAD_MUTEX_RECURSIVE) + return (EINVAL); + + attrp->__mutex_type = type; + return (0); +} +weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype) diff --git a/sysdeps/mach/hurd/pt-mutexattr.c b/sysdeps/mach/hurd/pt-mutexattr.c new file mode 100644 index 0000000..40a8c17 --- /dev/null +++ b/sysdeps/mach/hurd/pt-mutexattr.c @@ -0,0 +1 @@ +/* empty */ -- cgit v1.2.3