This moves the Hurd gsope implementation to be more like the Linux one. --- sysdeps/generic/ldsodefs.h | 2 -- sysdeps/htl/dl-thread_gscope_wait.c | 36 +++++++++++++++++++++++++++++ sysdeps/mach/hurd/i386/tls.h | 22 ++++++++++++++++++ sysdeps/mach/hurd/tls.h | 20 ---------------- 4 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 sysdeps/htl/dl-thread_gscope_wait.c
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 4604d00b..af16162f 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1324,10 +1324,8 @@ link_map_audit_state (struct link_map *l, size_t index) } #endif /* SHARED */ -#if THREAD_GSCOPE_IN_TCB void __thread_gscope_wait (void) attribute_hidden; # define THREAD_GSCOPE_WAIT() __thread_gscope_wait () -#endif __END_DECLS diff --git a/sysdeps/htl/dl-thread_gscope_wait.c b/sysdeps/htl/dl-thread_gscope_wait.c new file mode 100644 index 00000000..66b75194 --- /dev/null +++ b/sysdeps/htl/dl-thread_gscope_wait.c @@ -0,0 +1,36 @@ +/* TODO: copyright heading */ + +#include <ldsodefs.h> +#include <pthread.h> +#include <htl/pt-internal.h> + +void +__thread_gscope_wait (void) +{ + size_t i; + struct __pthread *t; + int *flag_ptr; + + lll_lock (GL (dl_pthread_threads_lock), 0); + + for (i = 0; i < GL (dl_pthread_num_threads); ++i) + { + t = GL (dl_pthread_threads[i]); + if (t == NULL) + continue; + + flag_ptr = &t->tcb->gscope_flag; + again: + if (atomic_load_acquire (flag_ptr) == THREAD_GSCOPE_FLAG_UNUSED) + continue; + + if (atomic_compare_and_exchange_bool_acq (flag_ptr, + THREAD_GSCOPE_FLAG_WAIT, + THREAD_GSCOPE_FLAG_USED)) + goto again; + + lll_wait (flag_ptr, THREAD_GSCOPE_FLAG_WAIT, 0); + } + + lll_unlock (GL (dl_pthread_threads_lock), 0); +} diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h index 057b2613..0ca4e641 100644 --- a/sysdeps/mach/hurd/i386/tls.h +++ b/sysdeps/mach/hurd/i386/tls.h @@ -369,6 +369,28 @@ _hurd_tls_new (thread_t child, struct i386_thread_state *state, tcbhead_t *tcb) return err; } +/* Global scope switch support. */ +#define THREAD_GSCOPE_LINK_MAP 0 + +# define THREAD_GSCOPE_FLAG_UNUSED 0 +# define THREAD_GSCOPE_FLAG_USED 1 +# define THREAD_GSCOPE_FLAG_WAIT 2 + +#define THREAD_GSCOPE_SET_FLAG() \ + THREAD_SETMEM (THREAD_SELF, gscope_flag, THREAD_GSCOPE_FLAG_USED) + +#define THREAD_GSCOPE_RESET_FLAG() \ + ({ \ + int __flag; \ + asm volatile ("xchgl %0, %%gs:%P1" \ + : "=r" (__flag) \ + : "i" (offsetof (tcbhead_t, gscope_flag)), \ + "0" (THREAD_GSCOPE_FLAG_UNUSED)); \ + if (__flag == THREAD_GSCOPE_FLAG_WAIT) \ + lll_wake (THREAD_SELF->gscope_flag, GSYNC_BROADCAST); \ + }) + + #endif /* !__ASSEMBLER__ */ #endif /* i386/tls.h */ diff --git a/sysdeps/mach/hurd/tls.h b/sysdeps/mach/hurd/tls.h index 8cbf22aa..8e66d5ff 100644 --- a/sysdeps/mach/hurd/tls.h +++ b/sysdeps/mach/hurd/tls.h @@ -52,26 +52,6 @@ # define GET_DTV(descr) \ (((tcbhead_t *) (descr))->dtv) -/* Global scope switch support. */ -#define THREAD_GSCOPE_LINK_MAP 0 -#define THREAD_GSCOPE_GLOBAL -#define THREAD_GSCOPE_SET_FLAG() \ - atomic_exchange_and_add_acq (&GL(dl_thread_gscope_count), 1) -#define THREAD_GSCOPE_RESET_FLAG() \ - do \ - if (atomic_exchange_and_add_rel (&GL(dl_thread_gscope_count), -1) == 1) \ - lll_wake (GL(dl_thread_gscope_count), 0); \ - while (0) -#define THREAD_GSCOPE_WAIT() \ - do \ - { \ - int count; \ - atomic_write_barrier (); \ - while ((count = GL(dl_thread_gscope_count))) \ - lll_wait (GL(dl_thread_gscope_count), count, 0); \ - } \ - while (0) - #endif /* !ASSEMBLER */ -- 2.31.1