From 608a12659f15d57abf42a972c1e56c6a24cfe244 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 21 Apr 2012 22:14:22 +0000 Subject: Rename bits/atomic.h to bits/pt-atomic.h This avoids a conflict with glibc-provided bits/atomic.h * sysdeps/ia32/bits/atomic.h: Rename to... * sysdeps/ia32/bits/pt-atomic.h: ... this. * pthread/pt-create.c: Include instead of * pthread/pt-exit.c: Likewise. * pthread/pt-internal.h: Likewise. --- pthread/pt-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pthread/pt-internal.h') diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index 3f69d2d..94bc9a7 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include -- cgit v1.2.3 From d21d530170abcaec33ba272b11cb6615eb2804de Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 21 Apr 2012 22:54:16 +0000 Subject: Do not redefine tcbhead_t in glibc * pthread/pt-internal.h (tcbhead_t): Define struct only if IS_IN_libpthread is not defined. --- pthread/pt-internal.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pthread/pt-internal.h') diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index 94bc9a7..6186c86 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -54,6 +54,7 @@ enum pthread_state # define PTHREAD_SYSDEP_MEMBERS #endif +#ifndef IS_IN_libpthread #ifdef ENABLE_TLS /* Type of the TCB. */ typedef struct @@ -63,6 +64,7 @@ typedef struct thread_t self; /* This thread's control port. */ } tcbhead_t; #endif /* ENABLE_TLS */ +#endif /* IS_IN_libpthread */ /* This structure describes a POSIX thread. */ struct __pthread -- cgit v1.2.3 From dbaf5693972d2cbfad0ad48b966e5693b770127e Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 22 Apr 2012 00:22:47 +0200 Subject: __pthread_timedblock: add an argument for the clock id To make `__pthread_timedblock' properly measure time using the right clock, add a new argument representing the clock to use. * pthread/pt-internal.h (__pthread_timedblock): New argument CLOCK_ID. * sysdeps/l4/pt-timedblock.c (__pthread_timedblock): Likewise. * sysdeps/mach/pt-timedblock.c (__pthread_timedblock): Likewise. * sysdeps/generic/pt-cond-timedwait.c (__pthread_cond_timedwait_internal): Pass the clock of the `pthread_cond' to `__pthread_timedblock'. * sysdeps/generic/pt-mutex-timedlock.c (__pthread_mutex_timedlock_internal): Pass CLOCK_REALTIME to `__pthread_timedblock'. * sysdeps/generic/pt-rwlock-timedrdlock.c (__pthread_rwlock_timedrdlock_internal): Likewise. * sysdeps/generic/pt-rwlock-timedwrlock.c (__pthread_rwlock_timedwrlock_internal): Likewise. * sysdeps/generic/sem-timedwait.c (__sem_timedwait_internal): Likewise. --- pthread/pt-internal.h | 3 ++- sysdeps/generic/pt-cond-timedwait.c | 5 ++++- sysdeps/generic/pt-mutex-timedlock.c | 2 +- sysdeps/generic/pt-rwlock-timedrdlock.c | 2 +- sysdeps/generic/pt-rwlock-timedwrlock.c | 2 +- sysdeps/generic/sem-timedwait.c | 2 +- sysdeps/l4/pt-timedblock.c | 3 ++- sysdeps/mach/pt-timedblock.c | 3 ++- 8 files changed, 14 insertions(+), 8 deletions(-) (limited to 'pthread/pt-internal.h') diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index 6186c86..a1e90aa 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -254,7 +254,8 @@ extern void __pthread_block (struct __pthread *thread); /* Block THREAD until *ABSTIME is reached. */ extern error_t __pthread_timedblock (struct __pthread *__restrict thread, - const struct timespec *__restrict abstime); + const struct timespec *__restrict abstime, + clockid_t clock_id); /* Wakeup THREAD. */ extern void __pthread_wakeup (struct __pthread *thread); diff --git a/sysdeps/generic/pt-cond-timedwait.c b/sysdeps/generic/pt-cond-timedwait.c index 483f277..56eb1ec 100644 --- a/sysdeps/generic/pt-cond-timedwait.c +++ b/sysdeps/generic/pt-cond-timedwait.c @@ -46,6 +46,7 @@ __pthread_cond_timedwait_internal (pthread_cond_t *cond, { error_t err; int canceltype; + clockid_t clock_id = __pthread_default_condattr.clock; void cleanup (void *arg) { @@ -68,6 +69,8 @@ __pthread_cond_timedwait_internal (pthread_cond_t *cond, /* Add ourselves to the list of waiters. */ __pthread_spin_lock (&cond->__lock); __pthread_enqueue (&cond->__queue, self); + if (cond->__attr) + clock_id = cond->__attr->clock; __pthread_spin_unlock (&cond->__lock); __pthread_mutex_unlock (mutex); @@ -79,7 +82,7 @@ __pthread_cond_timedwait_internal (pthread_cond_t *cond, if (abstime) { - err = __pthread_timedblock (self, abstime); + err = __pthread_timedblock (self, abstime, clock_id); if (err) /* We timed out. We may need to disconnect ourself from the waiter queue. diff --git a/sysdeps/generic/pt-mutex-timedlock.c b/sysdeps/generic/pt-mutex-timedlock.c index 883e50a..48bffaf 100644 --- a/sysdeps/generic/pt-mutex-timedlock.c +++ b/sysdeps/generic/pt-mutex-timedlock.c @@ -130,7 +130,7 @@ __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex, { error_t err; - err = __pthread_timedblock (self, abstime); + err = __pthread_timedblock (self, abstime, CLOCK_REALTIME); if (err) /* We timed out. We may need to disconnect ourself from the waiter queue. diff --git a/sysdeps/generic/pt-rwlock-timedrdlock.c b/sysdeps/generic/pt-rwlock-timedrdlock.c index ba610fa..a110213 100644 --- a/sysdeps/generic/pt-rwlock-timedrdlock.c +++ b/sysdeps/generic/pt-rwlock-timedrdlock.c @@ -73,7 +73,7 @@ __pthread_rwlock_timedrdlock_internal (struct __pthread_rwlock *rwlock, { error_t err; - err = __pthread_timedblock (self, abstime); + err = __pthread_timedblock (self, abstime, CLOCK_REALTIME); if (err) /* We timed out. We may need to disconnect ourself from the waiter queue. diff --git a/sysdeps/generic/pt-rwlock-timedwrlock.c b/sysdeps/generic/pt-rwlock-timedwrlock.c index 04eab51..a5cc579 100644 --- a/sysdeps/generic/pt-rwlock-timedwrlock.c +++ b/sysdeps/generic/pt-rwlock-timedwrlock.c @@ -59,7 +59,7 @@ __pthread_rwlock_timedwrlock_internal (struct __pthread_rwlock *rwlock, { error_t err; - err = __pthread_timedblock (self, abstime); + err = __pthread_timedblock (self, abstime, CLOCK_REALTIME); if (err) /* We timed out. We may need to disconnect ourself from the waiter queue. diff --git a/sysdeps/generic/sem-timedwait.c b/sysdeps/generic/sem-timedwait.c index e34539a..94e6dee 100644 --- a/sysdeps/generic/sem-timedwait.c +++ b/sysdeps/generic/sem-timedwait.c @@ -55,7 +55,7 @@ __sem_timedwait_internal (sem_t *restrict sem, { error_t err; - err = __pthread_timedblock (self, timeout); + err = __pthread_timedblock (self, timeout, CLOCK_REALTIME); if (err) /* We timed out. We may need to disconnect ourself from the waiter queue. diff --git a/sysdeps/l4/pt-timedblock.c b/sysdeps/l4/pt-timedblock.c index ce7972b..951644f 100644 --- a/sysdeps/l4/pt-timedblock.c +++ b/sysdeps/l4/pt-timedblock.c @@ -27,7 +27,8 @@ /* Block THREAD. */ error_t __pthread_timedblock (struct __pthread *thread, - const struct timespec *abstime) + const struct timespec *abstime, + clockid_t clock_id) { #warning Need gettimeofday to implement properly. __pthread_block (thread); diff --git a/sysdeps/mach/pt-timedblock.c b/sysdeps/mach/pt-timedblock.c index 6f54726..88beaa2 100644 --- a/sysdeps/mach/pt-timedblock.c +++ b/sysdeps/mach/pt-timedblock.c @@ -30,7 +30,8 @@ /* Block THREAD. */ error_t __pthread_timedblock (struct __pthread *thread, - const struct timespec *abstime) + const struct timespec *abstime, + clockid_t clock_id) { error_t err; mach_msg_header_t msg; -- cgit v1.2.3 From 71dcdb6d0189761ecc27691932502eacdf7e6b2c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 23 Apr 2012 18:00:21 +0000 Subject: Rename __pthread_initialize into __pthread_init The former conflicts with usage in glibc. * pthread/pt-initialize.c (__pthread_initialize): Rename into __pthread_init. * pthread/pt-internal.h (__pthread_initialize): Likewise. * sysdeps/l4/hurd/pt-sysdep.c (init_routine): Likewise. * sysdeps/mach/hurd/pt-sysdep.c (init_routine): Likewise. --- pthread/pt-initialize.c | 2 +- pthread/pt-internal.h | 2 +- sysdeps/l4/hurd/pt-sysdep.c | 2 +- sysdeps/mach/hurd/pt-sysdep.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'pthread/pt-internal.h') diff --git a/pthread/pt-initialize.c b/pthread/pt-initialize.c index f0ef8f8..39f1aed 100644 --- a/pthread/pt-initialize.c +++ b/pthread/pt-initialize.c @@ -74,7 +74,7 @@ static const struct pthread_functions pthread_functions = /* Initialize the pthreads library. */ void -__pthread_initialize (void) +__pthread_init (void) { #ifdef IS_IN_libpthread __libc_pthread_init(ptr_pthread_functions); diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index a1e90aa..a1da377 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -188,7 +188,7 @@ extern struct __pthread *_pthread_self (void); /* Initialize the pthreads library. */ -extern void __pthread_initialize (void); +extern void __pthread_init (void); /* Internal version of pthread_create. Rather than return the new tid, we return the whole __pthread structure in *PTHREAD. */ diff --git a/sysdeps/l4/hurd/pt-sysdep.c b/sysdeps/l4/hurd/pt-sysdep.c index c23364c..1df6c2e 100644 --- a/sysdeps/l4/hurd/pt-sysdep.c +++ b/sysdeps/l4/hurd/pt-sysdep.c @@ -45,7 +45,7 @@ static void init_routine (void (*entry) (void *), void *arg) { /* Initialize the library. */ - __pthread_initialize (); + __pthread_init(); struct __pthread *thread; int err; diff --git a/sysdeps/mach/hurd/pt-sysdep.c b/sysdeps/mach/hurd/pt-sysdep.c index 5e07006..95a4d36 100644 --- a/sysdeps/mach/hurd/pt-sysdep.c +++ b/sysdeps/mach/hurd/pt-sysdep.c @@ -45,7 +45,7 @@ init_routine (void) int err; /* Initialize the library. */ - __pthread_initialize (); + __pthread_init (); /* Create the pthread structure for the main thread (i.e. us). */ err = __pthread_create_internal (&thread, 0, 0, 0); -- cgit v1.2.3 From 25260994c812050a5d7addf125cdc90c911ca5c1 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 27 Apr 2012 01:32:54 +0000 Subject: Store self in __thread variable instead of threadvar * sysdeps/mach/hurd/pt-sysdep.h (_HURD_THREADVAR_THREAD): Remove macro. (___pthread_self): Declare new __thread variable. (_pthread_self): Take self pointer from ___pthread_self instead of threadvar. * sysdeps/mach/hurd/pt-sysdep.c (___pthread_self): Define new __thread variable. (init_routine): Set ___pthread_self to initial thread structure. * pthread/pt-internal.h (__pthread_setup): Add `self' parameter to `entry_point' parameter. * pthread/pt-create.c (entry_point): Add `self' parameter. Store it in ___pthread_self. * sysdeps/l4/hurd/ia32/pt-setup.c (stack_setup): Add `self parameter to `entry_point' parameter. Pass it the `thread' parameter. (__pthread_setup): Likewise. * sysdeps/l4/hurd/powerpc/pt-setup.c (struct start_info): Add `self' field. (first_entry_1): Pass `self' parameter. (stack_setup): Add `self' parameter to `entry_point' parameter, pass it the `thread' parameter. (__pthread_setup): Likewise. * sysdeps/mach/hurd/ia32/pt-setup.c (stack_setup): Pass `thread' parameter to the start routine. (stack_setup): Add `self' parameter to `entry_point' paramter. --- pthread/pt-create.c | 6 +++++- pthread/pt-internal.h | 3 ++- sysdeps/l4/hurd/ia32/pt-setup.c | 5 +++-- sysdeps/l4/hurd/powerpc/pt-setup.c | 7 +++++-- sysdeps/mach/hurd/ia32/pt-setup.c | 12 +++++------- sysdeps/mach/hurd/pt-sysdep.c | 5 +++-- sysdeps/mach/hurd/pt-sysdep.h | 6 ++---- 7 files changed, 25 insertions(+), 19 deletions(-) (limited to 'pthread/pt-internal.h') diff --git a/pthread/pt-create.c b/pthread/pt-create.c index ca6b66c..4d81a95 100644 --- a/pthread/pt-create.c +++ b/pthread/pt-create.c @@ -38,8 +38,12 @@ __atomic_t __pthread_total; /* The entry-point for new threads. */ static void -entry_point (void *(*start_routine)(void *), void *arg) +entry_point (struct __pthread *self, void *(*start_routine)(void *), void *arg) { +#ifdef ENABLE_TLS + ___pthread_self = self; +#endif + #ifdef HAVE_USELOCALE /* A fresh thread needs to be bound to the global locale. */ uselocale (LC_GLOBAL_LOCALE); diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index a1da377..f5766e9 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -217,7 +217,8 @@ extern void __pthread_stack_dealloc (void *stackaddr, size_t stacksize); /* Setup thread THREAD's context. */ extern int __pthread_setup (struct __pthread *__restrict thread, - void (*entry_point)(void *(*)(void *), + void (*entry_point)(struct __pthread *, + void *(*)(void *), void *), void *(*start_routine)(void *), void *__restrict arg); diff --git a/sysdeps/l4/hurd/ia32/pt-setup.c b/sysdeps/l4/hurd/ia32/pt-setup.c index 579905c..de7359c 100644 --- a/sysdeps/l4/hurd/ia32/pt-setup.c +++ b/sysdeps/l4/hurd/ia32/pt-setup.c @@ -65,7 +65,7 @@ __pthread_entry_point:\n\ static void * stack_setup (struct __pthread *thread, void *(*start_routine)(void *), void *arg, - void (*entry_point)(void *(*)(void *), void *)) + void (*entry_point)(struct __pthread *, void *(*)(void *), void *)) { uintptr_t *top; @@ -80,6 +80,7 @@ stack_setup (struct __pthread *thread, /* Set up call frame. */ *--top = (uintptr_t) arg; /* Argument to START_ROUTINE. */ *--top = (uintptr_t) start_routine; + *--top = (uintptr_t) thread; *--top = 0; /* Fake return address. */ *--top = (uintptr_t) entry_point; } @@ -89,7 +90,7 @@ stack_setup (struct __pthread *thread, int __pthread_setup (struct __pthread *thread, - void (*entry_point)(void *(*)(void *), void *), + void (*entry_point)(struct __pthread *, void *(*)(void *), void *), void *(*start_routine)(void *), void *arg) { thread->mcontext.pc = (void *) &_pthread_entry_point; diff --git a/sysdeps/l4/hurd/powerpc/pt-setup.c b/sysdeps/l4/hurd/powerpc/pt-setup.c index d3cf4ec..d309216 100644 --- a/sysdeps/l4/hurd/powerpc/pt-setup.c +++ b/sysdeps/l4/hurd/powerpc/pt-setup.c @@ -28,6 +28,7 @@ struct start_info { void (*entry_point) (void *(*)(void *), void *); + struct __pthread *self; void *(*start_routine) (void *); void *arg; }; @@ -41,6 +42,7 @@ first_entry_1: ;\ lwz 0, 0(1) ;\ lwz 3, 4(1) ;\ lwz 4, 8(1) ;\ + lwz 5, 12(1) ;\ mtctr 0 ;\ bctrl ;\ "); @@ -51,7 +53,7 @@ first_entry_1: ;\ opportunity to install THREAD in our utcb. */ static void * stack_setup (struct __pthread *thread, - void (*entry_point)(void *(*)(void *), void *), + void (*entry_point)(struct __pthread *, void *(*)(void *), void *), void *(*start_routine)(void *), void *arg) { l4_word_t *top; @@ -68,6 +70,7 @@ stack_setup (struct __pthread *thread, struct start_info *info = ((struct start_info *) top) - 1; info->entry_point = entry_point; + info->self = thread; info->start_routine = start_routine; info->arg = arg; return (void *) info; @@ -77,7 +80,7 @@ stack_setup (struct __pthread *thread, int __pthread_setup (struct __pthread *thread, - void (*entry_point)(void *(*)(void *), void *), + void (*entry_point)(struct __pthread *, void *(*)(void *), void *), void *(*start_routine)(void *), void *arg) { thread->mcontext.pc = first_entry_1; diff --git a/sysdeps/mach/hurd/ia32/pt-setup.c b/sysdeps/mach/hurd/ia32/pt-setup.c index 5420dc8..73fd43d 100644 --- a/sysdeps/mach/hurd/ia32/pt-setup.c +++ b/sysdeps/mach/hurd/ia32/pt-setup.c @@ -57,16 +57,14 @@ stack_setup (struct __pthread *thread, /* Next, make room for the TSDs. */ top -= __hurd_threadvar_max; - /* Save the self pointer. */ - top[_HURD_THREADVAR_THREAD] = (uintptr_t) thread; - if (start_routine) { /* And then the call frame. */ - top -= 2; + top -= 3; top = (uintptr_t *) ((uintptr_t) top & ~0xf); - top[1] = (uintptr_t) arg; /* Argument to START_ROUTINE. */ - top[0] = (uintptr_t) start_routine; + top[2] = (uintptr_t) arg; /* Argument to START_ROUTINE. */ + top[1] = (uintptr_t) start_routine; + top[0] = (uintptr_t) thread; *--top = 0; /* Fake return address. */ } @@ -82,7 +80,7 @@ stack_setup (struct __pthread *thread, int __pthread_setup (struct __pthread *thread, - void (*entry_point)(void *(*)(void *), void *), + void (*entry_point)(struct __pthread *, void *(*)(void *), void *), void *(*start_routine)(void *), void *arg) { error_t err; diff --git a/sysdeps/mach/hurd/pt-sysdep.c b/sysdeps/mach/hurd/pt-sysdep.c index 95a4d36..f40fee5 100644 --- a/sysdeps/mach/hurd/pt-sysdep.c +++ b/sysdeps/mach/hurd/pt-sysdep.c @@ -28,6 +28,8 @@ #include +__thread struct __pthread *___pthread_self; + /* Forward. */ static void *init_routine (void); @@ -51,8 +53,7 @@ init_routine (void) err = __pthread_create_internal (&thread, 0, 0, 0); assert_perror (err); - ((void **) (__hurd_threadvar_stack_offset))[_HURD_THREADVAR_THREAD] - = thread; + ___pthread_self = thread; /* Decrease the number of threads, to take into account that the signal thread (which will be created by the glibc startup code diff --git a/sysdeps/mach/hurd/pt-sysdep.h b/sysdeps/mach/hurd/pt-sysdep.h index 13e235d..bec1b40 100644 --- a/sysdeps/mach/hurd/pt-sysdep.h +++ b/sysdeps/mach/hurd/pt-sysdep.h @@ -35,15 +35,13 @@ mach_msg_header_t wakeupmsg; \ int have_kernel_resources; -#define _HURD_THREADVAR_THREAD _HURD_THREADVAR_DYNAMIC_USER - +extern __thread struct __pthread *___pthread_self; #define _pthread_self() \ ({ \ struct __pthread *thread; \ \ assert (__pthread_threads); \ - thread = *(struct __pthread **) \ - __hurd_threadvar_location (_HURD_THREADVAR_THREAD); \ + thread = ___pthread_self; \ \ assert (thread); \ assert (({ mach_port_t ktid = __mach_thread_self (); \ -- cgit v1.2.3 From f42e3ba3cb16bd892957f3b018e2d8ae1e06d022 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 8 Jul 2012 20:45:56 +0200 Subject: Comment on deviation from standard * pthread/pt-internal.h (guardsize): Mention that we depart from the standard which says guardsize is in addition to stacksize. --- pthread/pt-internal.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pthread/pt-internal.h') diff --git a/pthread/pt-internal.h b/pthread/pt-internal.h index f5766e9..067fb73 100644 --- a/pthread/pt-internal.h +++ b/pthread/pt-internal.h @@ -84,6 +84,8 @@ struct __pthread size_t guardsize; /* Included in STACKSIZE (i.e. total stack memory is STACKSIZE, not STACKSIZE + GUARDSIZE). */ + /* FIXME: standard says that guardsize is in + addition to stacksize. */ int stack; /* Nonzero if the stack was allocated. */ /* Exit status. */ -- cgit v1.2.3