diff options
Diffstat (limited to 'nptl/sysdeps')
162 files changed, 8194 insertions, 3 deletions
diff --git a/nptl/sysdeps/i386/tls.h b/nptl/sysdeps/i386/tls.h index ab42708320..1c29789953 100644 --- a/nptl/sysdeps/i386/tls.h +++ b/nptl/sysdeps/i386/tls.h @@ -78,6 +78,7 @@ typedef struct /* The old way: using LDT. */ +#ifndef NO_SET_THREAD_AREA /* Structure passed to `modify_ldt', 'set_thread_area', and 'clone' calls. */ struct user_desc { @@ -99,6 +100,7 @@ union user_desc_init struct user_desc desc; unsigned int vals[4]; }; +#endif /* NO_SET_THREAD_AREA */ /* Get the thread descriptor definition. */ @@ -188,6 +190,7 @@ union user_desc_init # endif #endif +#ifndef NO_SET_THREAD_AREA /* Code to initially initialize the thread pointer. This might need special attention since 'errno' is not yet available and if the operation can cause a failure 'errno' must not be touched. */ @@ -242,6 +245,7 @@ union user_desc_init \ _result == 0 ? NULL \ : "set_thread_area failed when setting up thread-local storage\n"; }) +#endif /* NO_SET_THREAD_AREA */ /* Return the address of the dtv for the current thread. */ diff --git a/nptl/sysdeps/pthread/bits/stdio-lock.h b/nptl/sysdeps/pthread/bits/stdio-lock.h index 686d88b344..2cda6e549f 100644 --- a/nptl/sysdeps/pthread/bits/stdio-lock.h +++ b/nptl/sysdeps/pthread/bits/stdio-lock.h @@ -26,7 +26,11 @@ /* The locking here is very inexpensive, even for inlining. */ #define _IO_lock_inexpensive 1 +#ifndef lll_define typedef struct { int lock; int cnt; void *owner; } _IO_lock_t; +#else +typedef struct { lll_define (, lock); int cnt; void *owner; } _IO_lock_t; +#endif #define _IO_lock_initializer { LLL_LOCK_INITIALIZER, 0, NULL } diff --git a/nptl/sysdeps/unix/sysv/linux/fork.c b/nptl/sysdeps/unix/sysv/linux/fork.c index 2202b40f6a..071b412a6f 100644 --- a/nptl/sysdeps/unix/sysv/linux/fork.c +++ b/nptl/sysdeps/unix/sysv/linux/fork.c @@ -116,9 +116,11 @@ __libc_fork (void) _IO_list_lock (); +#ifndef PTHREAD_T_IS_TID #ifndef NDEBUG pid_t ppid = THREAD_GETMEM (THREAD_SELF, tid); #endif +#endif /* We need to prevent the getpid() code to update the PID field so that, if a signal arrives in the child very early and the signal @@ -138,13 +140,19 @@ __libc_fork (void) { struct pthread *self = THREAD_SELF; +#ifndef PTHREAD_T_IS_TID assert (THREAD_GETMEM (self, tid) != ppid); +#endif if (__fork_generation_pointer != NULL) *__fork_generation_pointer += 4; /* Adjust the PID field for the new process. */ +#ifndef PTHREAD_T_IS_TID THREAD_SETMEM (self, pid, THREAD_GETMEM (self, tid)); +#else + THREAD_SETMEM (self, pid, getpid ()); +#endif #if HP_TIMING_AVAIL /* The CPU clock of the thread and process have to be set to zero. */ @@ -204,11 +212,17 @@ __libc_fork (void) } /* Initialize the fork lock. */ +#ifndef lll_init __fork_lock = LLL_LOCK_INITIALIZER; +#else + lll_init (__fork_lock); +#endif } else { +#ifndef PTHREAD_T_IS_TID assert (THREAD_GETMEM (THREAD_SELF, tid) == ppid); +#endif /* Restore the PID value. */ THREAD_SETMEM (THREAD_SELF, pid, parentpid); diff --git a/nptl/sysdeps/unix/sysv/linux/fork.h b/nptl/sysdeps/unix/sysv/linux/fork.h index dadd0dfee6..753460abb0 100644 --- a/nptl/sysdeps/unix/sysv/linux/fork.h +++ b/nptl/sysdeps/unix/sysv/linux/fork.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -25,7 +25,11 @@ extern unsigned long int __fork_generation attribute_hidden; extern unsigned long int *__fork_generation_pointer attribute_hidden; /* Lock to protect allocation and deallocation of fork handlers. */ +#ifndef lll_define extern int __fork_lock attribute_hidden; +#else +lll_define (extern, __fork_lock) attribute_hidden; +#endif /* Elements of the fork handler lists. */ struct fork_handler diff --git a/nptl/sysdeps/unix/sysv/linux/register-atfork.c b/nptl/sysdeps/unix/sysv/linux/register-atfork.c index 8b5557d892..49fcd215a7 100644 --- a/nptl/sysdeps/unix/sysv/linux/register-atfork.c +++ b/nptl/sysdeps/unix/sysv/linux/register-atfork.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2005, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -24,7 +24,11 @@ /* Lock to protect allocation and deallocation of fork handlers. */ +#ifndef lll_define_initialized int __fork_lock = LLL_LOCK_INITIALIZER; +#else +lll_define_initialized (, __fork_lock); +#endif /* Number of pre-allocated handler entries. */ diff --git a/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c b/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c index ed006c1223..2c8789b9bb 100644 --- a/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c +++ b/nptl/sysdeps/unix/sysv/linux/unregister-atfork.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2005, 2007, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Implies b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Implies new file mode 100644 index 0000000000..f1b3e8939c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Implies @@ -0,0 +1 @@ +pthread diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile new file mode 100644 index 0000000000..2b02bf7c36 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Makefile @@ -0,0 +1,44 @@ +ifeq ($(subdir),nptl) +headers += synch.h bits/synch.h sys/synch.h thread.h sys/lwp.h +sysdep_routines += register-atfork unregister-atfork libc_pthread_init \ + libc_multiple_threads fastlock +libpthread-sysdep_routines += pt-fork fastlock clock_gettime \ + sys_lwp_mutex_timedlock sys_lwp_mutex_trylock sys_lwp_mutex_unlock \ + sys_lwp_mutex_register sys_lwp_cond_wait sys_lwp_cond_signal \ + sys_lwp_cond_broadcast sys_lwp_sema_post sys_lwp_sema_trywait \ + sys_lwp_sema_timedwait sys_lwp_create sys_lwp_wait sys_lwp_exit \ + sys_lwp_kill sys_lwp_suspend sys_lwp_continue sys_lwp_sigmask + +# solaris threads/synch +libpthread-routines += mutex_init mutex_lock mutex_trylock mutex_unlock \ + mutex_destroy mutex_timedlock mutex_reltimedlock mutex_consistent \ + _mutex_held cond_init cond_wait cond_timedwait cond_reltimedwait \ + cond_signal cond_broadcast cond_destroy rwlock_init rwlock_destroy \ + rw_rdlock rw_wrlock rw_unlock rw_tryrdlock rw_trywrlock rw_timedrdlock \ + rw_timedwrlock sema_init sema_destroy sema_wait sema_trywait sema_post \ + sema_timedwait thr_create thr_join thr_exit thr_self thr_yield \ + thr_sigsetmask thr_getspecific thr_setspecific thr_keycreate \ + thr_keycreate_once thr_min_stack thr_getconcurrency thr_setconcurrency \ + thr_continue thr_suspend thr_getprio thr_setprio _lwp_sema_init _lwp_info \ + __nthreads pthread_cond_reltimedwait_np pthread_mutex_reltimedlock_np +endif + +ifeq ($(subdir),posix) +CFLAGS-fork.c = -D_IO_MTSAFE_IO +sysdep_routines += sys_forkx +endif + +ifeq ($(subdir),misc) +sysdep_routines += thr_main thr_stksegment +endif + +# Needed in both the signal and nptl subdir. +# We also need to enable exceptions. +CFLAGS-sigaction.c = -DWRAPPER_INCLUDE='<nptl/sigaction.c>' -fexceptions + +# The following are cancellation points. Some of the functions can +# block and therefore temporarily enable asynchronous cancellation. +# Those must be compiled asynchronous unwind tables. +CFLAGS-cond_reltimedwait.c = -fexceptions -fasynchronous-unwind-tables +CFLAGS-cond_timedwait.c = -fexceptions -fasynchronous-unwind-tables +CFLAGS-cond_wait.c = -fexceptions -fasynchronous-unwind-tables diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions new file mode 100644 index 0000000000..964023da65 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/Versions @@ -0,0 +1,57 @@ +libc { + GLIBC_2.3.2 { + __register_atfork; + } + GLIBC_2.7 { + thr_stksegment; thr_main; + } + GLIBC_PRIVATE { + __libc_pthread_init; + __libc_current_sigrtmin_private; __libc_current_sigrtmax_private; + __libc_allocate_rtsig_private; + __resp; + } +} +libpthread { + GLIBC_2.0 { + fork; __fork; + } + GLIBC_2.7 { + # c + cond_init; cond_destroy; cond_wait; cond_timedwait; cond_reltimedwait; + cond_signal; cond_broadcast; + + # l + _lwp_cond_broadcast; _lwp_cond_timedwait; _lwp_cond_reltimedwait; + _lwp_cond_signal; _lwp_cond_wait; _lwp_continue; _lwp_info; _lwp_kill; + _lwp_mutex_lock; _lwp_mutex_trylock; _lwp_mutex_unlock; _lwp_self; + _lwp_sema_init; _lwp_sema_post; _lwp_sema_trywait; _lwp_sema_wait; + _lwp_suspend; + + # m + mutex_init; mutex_destroy; mutex_consistent; mutex_lock; mutex_trylock; + mutex_unlock; _mutex_held; + + # n + __nthreads; + + # p + pthread_cond_reltimedwait_np; pthread_mutex_reltimedlock_np; + pthread_rwlock_reltimedrdlock_np; pthread_rwlock_reltimedwrlock_np; + pthread_key_create_once_np; + + # r + rwlock_init; rwlock_destroy; rw_rdlock; rw_wrlock; rw_unlock; rw_tryrdlock; + rw_trywrlock; _rw_read_held; _rw_write_held; + + # s + sema_init; sema_destroy; sema_wait; sema_timedwait; sema_reltimedwait; + sema_post; sema_trywait; _sema_held; + + # t + thr_create; thr_join; thr_exit; thr_suspend; thr_continue; thr_self; + thr_setconcurrency; thr_getconcurrency; thr_main; thr_kill; thr_yield; + thr_setprio; thr_getprio; thr_keycreate; thr_keycreate_once; thr_min_stack; + thr_getspecific; thr_setspecific; thr_sigsetmask; + } +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/__nthreads.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/__nthreads.c new file mode 100644 index 0000000000..d84ee9698e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/__nthreads.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> + +int __nthreads (void) +{ + return __nptl_nthreads; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/_lwp_sema_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/_lwp_sema_init.c new file mode 100644 index 0000000000..dad47f6220 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/_lwp_sema_init.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + + +int _lwp_sema_init (sem, count) + sema_t *sem; + int count; +{ + /* Parameter sanity check. */ + if (__builtin_expect (count > SEM_VALUE_MAX, 0)) + return EINVAL; + + memset (sem, 0, sizeof(sema_t)); + sem->count = (uint32_t)count; + sem->type = LOCK_SHARED; + sem->magic = SEMA_MAGIC; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/_mutex_held.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/_mutex_held.c new file mode 100644 index 0000000000..22dd75a54b --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/_mutex_held.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int _mutex_held (mutex_t *mutex) +{ + return MUTEX_IS_OWNER (mutex); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/abstime-to-reltime.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/abstime-to-reltime.h new file mode 100644 index 0000000000..77373d1df3 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/abstime-to-reltime.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <time.h> +#include <stddef.h> + +static inline struct timespec * abstime_to_reltime ( + const struct timespec *abstime, struct timespec *reltime) +{ + if (!abstime) + return NULL; + + struct timespec now; + clock_gettime (CLOCK_REALTIME, &now); + reltime->tv_sec = abstime->tv_sec - now.tv_sec; + reltime->tv_nsec = abstime->tv_nsec - now.tv_nsec; + if (reltime->tv_nsec < 0) + { + reltime->tv_nsec += 1000000000; + --reltime->tv_sec; + } + return reltime; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/aio_misc.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/aio_misc.h new file mode 100644 index 0000000000..0568129ed1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/aio_misc.h @@ -0,0 +1,50 @@ +/* Copyright (C) 2006, 2007, 2008 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <sys/syscall.h> + +/* This has to be relative or we'll end up including nptl's version. */ +#include "../../../../../../sysdeps/pthread/aio_misc.h" + +/* We can use cond_timedwait, since it returns EINTR, but it can also return + ETIME. We get around this by defining a small inline wrapper. */ + +static inline int +__aio_pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + int res = cond_timedwait ((cond_t *)cond, (mutex_t *)mutex, NULL); + if (res == ETIME) + return ETIMEDOUT; + return res; +} + +static inline int +__aio_pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *abstime) +{ + int res = cond_timedwait ((cond_t *)cond, (mutex_t *)mutex, + (struct timespec *)abstime); + if (res == ETIME) + return ETIMEDOUT; + return res; +} + +#define pthread_cond_wait __aio_pthread_cond_wait +#define pthread_cond_timedwait __aio_pthread_cond_timedwait diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/allocrtsig.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/allocrtsig.c new file mode 100644 index 0000000000..9f359cf96d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/allocrtsig.c @@ -0,0 +1,56 @@ +/* Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <signal.h> + + +static int current_rtmin = __SIGRTMIN; +static int current_rtmax = __SIGRTMAX; + + +/* We reserve __SIGRTMIN for use as the cancelation signal. This + signal is used internally. */ +int +__libc_current_sigrtmin (void) +{ + return current_rtmin; +} +libc_hidden_def (__libc_current_sigrtmin) +strong_alias (__libc_current_sigrtmin, __libc_current_sigrtmin_private) + + +int +__libc_current_sigrtmax (void) +{ + return current_rtmax; +} +libc_hidden_def (__libc_current_sigrtmax) +strong_alias (__libc_current_sigrtmax, __libc_current_sigrtmax_private) + + +int +__libc_allocate_rtsig (int high) +{ + if (current_rtmin == -1 || current_rtmin > current_rtmax) + /* We don't have anymore signal available. */ + return -1; + + return high ? current_rtmin++ : current_rtmax--; +} +strong_alias (__libc_allocate_rtsig, __libc_allocate_rtsig_private) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/libc-lock.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/libc-lock.h new file mode 100644 index 0000000000..48633983a9 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/libc-lock.h @@ -0,0 +1,464 @@ +/* libc-internal interface for mutex locks. OpenSolaris NPTL version. + Copyright (C) 1996-2003, 2005, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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; 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_LIBC_LOCK_H +#define _BITS_LIBC_LOCK_H 1 + +#include <pthread.h> +#define __need_NULL +#include <stddef.h> +#include <sys/synch.h> +#include <synchP.h> + + +/* Mutex type. */ +#if defined _LIBC || defined _IO_MTSAFE_IO +typedef pthread_mutex_t __libc_lock_t; +typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t; +typedef struct { pthread_mutex_t mutex; } __rtld_lock_recursive_t; +# ifdef __USE_UNIX98 +typedef pthread_rwlock_t __libc_rwlock_t; +# else +typedef struct __libc_rwlock_opaque__ __libc_rwlock_t; +# endif +#else +typedef struct __libc_lock_opaque__ __libc_lock_t; +typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; +typedef struct __libc_rwlock_opaque__ __libc_rwlock_t; +#endif + +#ifdef _LIBC +# include <tls.h> +# include <pthread-functions.h> +#endif + +/* Type for key to thread-specific data. */ +typedef pthread_key_t __libc_key_t; + +/* Define a lock variable NAME with storage class CLASS. The lock must be + initialized with __libc_lock_init before it can be used (or define it + with __libc_lock_define_initialized, below). Use `extern' for CLASS to + declare a lock defined in another module. In public structure + definitions you must use a pointer to the lock structure (i.e., NAME + begins with a `*'), because its storage size will not be known outside + of libc. */ +#define __libc_lock_define(CLASS,NAME) \ + CLASS __libc_lock_t NAME; +#define __libc_rwlock_define(CLASS,NAME) \ + CLASS __libc_rwlock_t NAME; +#define __libc_lock_define_recursive(CLASS,NAME) \ + CLASS __libc_lock_recursive_t NAME; +#define __rtld_lock_define_recursive(CLASS,NAME) \ + CLASS __rtld_lock_recursive_t NAME; + +/* Define an initialized lock variable NAME with storage class CLASS. */ + +#define __libc_lock_define_initialized(CLASS,NAME) \ + CLASS __libc_lock_t NAME = PTHREAD_MUTEX_INITIALIZER; +#define __libc_rwlock_define_initialized(CLASS,NAME) \ + CLASS __libc_rwlock_t NAME = PTHREAD_RWLOCK_INITIALIZER; + +/* Define an initialized recursive lock variable NAME with storage + class CLASS. */ +#define __libc_lock_define_initialized_recursive(CLASS,NAME) \ + CLASS __libc_lock_recursive_t NAME = _LIBC_LOCK_RECURSIVE_INITIALIZER; +#define _LIBC_LOCK_RECURSIVE_INITIALIZER \ + {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP} + +#define __rtld_lock_define_initialized_recursive(CLASS,NAME) \ + CLASS __rtld_lock_recursive_t NAME = _RTLD_LOCK_RECURSIVE_INITIALIZER; +#define _RTLD_LOCK_RECURSIVE_INITIALIZER \ + {PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP} + +#define __rtld_lock_initialize(NAME) \ + (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER) + +#define __rtld_lock_recursive_reinitialize(NAME) \ + ({ \ + unsigned int ___rtld_lock_count = (NAME).mutex.mutex_rcount; \ + memset (&(NAME).mutex, 0, sizeof (pthread_mutex_t)); \ + (NAME).mutex.mutex_type = LOCK_RECURSIVE; \ + (NAME).mutex.mutex_flag = LOCK_INITED; \ + (NAME).mutex.mutex_magic = MUTEX_MAGIC; \ + ___rtld_lock_count; \ + }) + +/* If we check for a weakly referenced symbol and then perform a + normal jump to it te code generated for some platforms in case of + PIC is unnecessarily slow. What would happen is that the function + is first referenced as data and then it is called indirectly + through the PLT. We can make this a direct jump. */ +#ifdef __PIC__ +# define __libc_maybe_call(FUNC, ARGS, ELSE) \ + (__extension__ ({ __typeof (FUNC) *_fn = (FUNC); \ + _fn != NULL ? (*_fn) ARGS : ELSE; })) +#else +# define __libc_maybe_call(FUNC, ARGS, ELSE) \ + (FUNC != NULL ? FUNC ARGS : ELSE) +#endif + +/* Call thread functions through the function pointer table. */ +#if defined SHARED && !defined NOT_IN_libc +# define PTFAVAIL(NAME) __libc_pthread_functions_init +# define __libc_ptf_call(FUNC, ARGS, ELSE) \ + (__libc_pthread_functions_init ? PTHFCT_CALL (ptr_##FUNC, ARGS) : ELSE) +# define __libc_ptf_call_always(FUNC, ARGS) \ + PTHFCT_CALL (ptr_##FUNC, ARGS) +#else +# define PTFAVAIL(NAME) (NAME != NULL) +# define __libc_ptf_call(FUNC, ARGS, ELSE) \ + __libc_maybe_call (FUNC, ARGS, ELSE) +# define __libc_ptf_call_always(FUNC, ARGS) \ + FUNC ARGS +#endif + + +/* Initialize the named lock variable, leaving it in a consistent, unlocked + state. */ +#define __libc_lock_init(NAME) \ + __libc_maybe_call (__pthread_mutex_init, (&(NAME), NULL), 0) +#define __libc_rwlock_init(NAME) \ + __libc_maybe_call (__pthread_rwlock_init, (&(NAME), NULL), 0) + +/* Same as last but this time we initialize a recursive mutex. */ +#define __libc_lock_init_recursive(NAME) \ + do { \ + if (__pthread_mutex_init != NULL) \ + { \ + pthread_mutexattr_t __attr; \ + __pthread_mutexattr_init (&__attr); \ + __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \ + __pthread_mutex_init (&(NAME).mutex, &__attr); \ + __pthread_mutexattr_destroy (&__attr); \ + } \ + } while (0) + +#define __rtld_lock_init_recursive(NAME) \ + do { \ + if (__pthread_mutex_init != NULL) \ + { \ + pthread_mutexattr_t __attr; \ + __pthread_mutexattr_init (&__attr); \ + __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \ + __pthread_mutex_init (&(NAME).mutex, &__attr); \ + __pthread_mutexattr_destroy (&__attr); \ + } \ + } while (0) + +/* Finalize the named lock variable, which must be locked. It cannot be + used again until __libc_lock_init is called again on it. This must be + called on a lock variable before the containing storage is reused. */ +#define __libc_lock_fini(NAME) \ + __libc_maybe_call (__pthread_mutex_destroy, (&(NAME)), 0) +#define __libc_rwlock_fini(NAME) \ + __libc_maybe_call (__pthread_rwlock_destroy, (&(NAME)), 0) + +/* Finalize recursive named lock. */ +#define __libc_lock_fini_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_destroy, (&(NAME).mutex), 0) + +/* Lock the named lock variable. */ +#define __libc_lock_lock(NAME) \ + __libc_maybe_call (__pthread_mutex_lock, (&(NAME)), 0) +#define __libc_rwlock_rdlock(NAME) \ + __libc_ptf_call (__pthread_rwlock_rdlock, (&(NAME)), 0) +#define __libc_rwlock_wrlock(NAME) \ + __libc_ptf_call (__pthread_rwlock_wrlock, (&(NAME)), 0) + +/* Lock the recursive named lock variable. */ +#define __libc_lock_lock_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0) + +/* Try to lock the named lock variable. */ +#define __libc_lock_trylock(NAME) \ + __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0) +#define __libc_rwlock_tryrdlock(NAME) \ + __libc_maybe_call (__pthread_rwlock_tryrdlock, (&(NAME)), 0) +#define __libc_rwlock_trywrlock(NAME) \ + __libc_maybe_call (__pthread_rwlock_trywrlock, (&(NAME)), 0) + +/* Try to lock the recursive named lock variable. */ +#define __libc_lock_trylock_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_trylock, (&(NAME)), 0) + +#define __rtld_lock_trylock_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_trylock, (&(NAME).mutex), 0) + +/* Unlock the named lock variable. */ +#define __libc_lock_unlock(NAME) \ + __libc_maybe_call (__pthread_mutex_unlock, (&(NAME)), 0) +#define __libc_rwlock_unlock(NAME) \ + __libc_ptf_call (__pthread_rwlock_unlock, (&(NAME)), 0) + +/* Unlock the recursive named lock variable. */ +#define __libc_lock_unlock_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_unlock, (&(NAME).mutex), 0) + +#if defined _LIBC && defined SHARED +# define __rtld_lock_default_lock_recursive(lock) \ + ++((pthread_mutex_t *)(lock))->mutex_rcount; + +# define __rtld_lock_default_unlock_recursive(lock) \ + --((pthread_mutex_t *)(lock))->mutex_rcount; + +# define __rtld_lock_lock_recursive(NAME) \ + GL(dl_rtld_lock_recursive) (&(NAME).mutex) + +# define __rtld_lock_unlock_recursive(NAME) \ + GL(dl_rtld_unlock_recursive) (&(NAME).mutex) +#else +# define __rtld_lock_lock_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_lock, (&(NAME).mutex), 0) + +# define __rtld_lock_unlock_recursive(NAME) \ + __libc_maybe_call (__pthread_mutex_unlock, (&(NAME).mutex), 0) +#endif + +/* Define once control variable. */ +#if PTHREAD_ONCE_INIT == 0 +/* Special case for static variables where we can avoid the initialization + if it is zero. */ +# define __libc_once_define(CLASS, NAME) \ + CLASS pthread_once_t NAME +#else +# define __libc_once_define(CLASS, NAME) \ + CLASS pthread_once_t NAME = PTHREAD_ONCE_INIT +#endif + +/* Call handler iff the first call. */ +#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \ + do { \ + if (PTFAVAIL (__pthread_once)) \ + __libc_ptf_call_always (__pthread_once, (&(ONCE_CONTROL), \ + INIT_FUNCTION)); \ + else if ((ONCE_CONTROL) == PTHREAD_ONCE_INIT) { \ + INIT_FUNCTION (); \ + (ONCE_CONTROL) |= 2; \ + } \ + } while (0) + + +/* Note that for I/O cleanup handling we are using the old-style + cancel handling. It does not have to be integrated with C++ snce + no C++ code is called in the middle. The old-style handling is + faster and the support is not going away. */ +extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, + void (*routine) (void *), void *arg); +extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer, + int execute); +extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer, + void (*routine) (void *), void *arg); +extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, + int execute); + +/* Start critical region with cleanup. */ +#define __libc_cleanup_region_start(DOIT, FCT, ARG) \ + { struct _pthread_cleanup_buffer _buffer; \ + int _avail; \ + if (DOIT) { \ + _avail = PTFAVAIL (_pthread_cleanup_push_defer); \ + if (_avail) { \ + __libc_ptf_call_always (_pthread_cleanup_push_defer, (&_buffer, FCT, \ + ARG)); \ + } else { \ + _buffer.__routine = (FCT); \ + _buffer.__arg = (ARG); \ + } \ + } else { \ + _avail = 0; \ + } + +/* End critical region with cleanup. */ +#define __libc_cleanup_region_end(DOIT) \ + if (_avail) { \ + __libc_ptf_call_always (_pthread_cleanup_pop_restore, (&_buffer, DOIT));\ + } else if (DOIT) \ + _buffer.__routine (_buffer.__arg); \ + } + +/* Sometimes we have to exit the block in the middle. */ +#define __libc_cleanup_end(DOIT) \ + if (_avail) { \ + __libc_ptf_call_always (_pthread_cleanup_pop_restore, (&_buffer, DOIT));\ + } else if (DOIT) \ + _buffer.__routine (_buffer.__arg) + + +/* Normal cleanup handling, based on C cleanup attribute. */ +__extern_inline void +__libc_cleanup_routine (struct __pthread_cleanup_frame *f) +{ + if (f->__do_it) + f->__cancel_routine (f->__cancel_arg); +} + +#define __libc_cleanup_push(fct, arg) \ + do { \ + struct __pthread_cleanup_frame __clframe \ + __attribute__ ((__cleanup__ (__libc_cleanup_routine))) \ + = { .__cancel_routine = (fct), .__cancel_arg = (arg), \ + .__do_it = 1 }; + +#define __libc_cleanup_pop(execute) \ + __clframe.__do_it = (execute); \ + } while (0) + + +/* Create thread-specific key. */ +#define __libc_key_create(KEY, DESTRUCTOR) \ + __libc_ptf_call (__pthread_key_create, (KEY, DESTRUCTOR), 1) + +/* Get thread-specific data. */ +#define __libc_getspecific(KEY) \ + __libc_ptf_call (__pthread_getspecific, (KEY), NULL) + +/* Set thread-specific data. */ +#define __libc_setspecific(KEY, VALUE) \ + __libc_ptf_call (__pthread_setspecific, (KEY, VALUE), 0) + + +/* Register handlers to execute before and after `fork'. Note that the + last parameter is NULL. The handlers registered by the libc are + never removed so this is OK. */ +#define __libc_atfork(PREPARE, PARENT, CHILD) \ + __register_atfork (PREPARE, PARENT, CHILD, NULL) +extern int __register_atfork (void (*__prepare) (void), + void (*__parent) (void), + void (*__child) (void), + void *__dso_handle); + +/* Functions that are used by this file and are internal to the GNU C + library. */ + +extern int __pthread_mutex_init (pthread_mutex_t *__mutex, + __const pthread_mutexattr_t *__mutex_attr); + +extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex); + +extern int __pthread_mutex_trylock (pthread_mutex_t *__mutex); + +extern int __pthread_mutex_lock (pthread_mutex_t *__mutex); + +extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex); + +extern int __pthread_mutexattr_init (pthread_mutexattr_t *__attr); + +extern int __pthread_mutexattr_destroy (pthread_mutexattr_t *__attr); + +extern int __pthread_mutexattr_settype (pthread_mutexattr_t *__attr, + int __kind); + +#ifdef __USE_UNIX98 +extern int __pthread_rwlock_init (pthread_rwlock_t *__rwlock, + __const pthread_rwlockattr_t *__attr); + +extern int __pthread_rwlock_destroy (pthread_rwlock_t *__rwlock); + +extern int __pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock); + +extern int __pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock); + +extern int __pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock); + +extern int __pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock); + +extern int __pthread_rwlock_unlock (pthread_rwlock_t *__rwlock); +#endif + +extern int __pthread_key_create (pthread_key_t *__key, + void (*__destr_function) (void *)); + +extern int __pthread_setspecific (pthread_key_t __key, + __const void *__pointer); + +extern void *__pthread_getspecific (pthread_key_t __key); + +extern int __pthread_once (pthread_once_t *__once_control, + void (*__init_routine) (void)); + +extern int __pthread_atfork (void (*__prepare) (void), + void (*__parent) (void), + void (*__child) (void)); + + + +/* Make the pthread functions weak so that we can elide them from + single-threaded processes. */ +#ifndef __NO_WEAK_PTHREAD_ALIASES +# ifdef weak_extern +# if _LIBC +# include <bp-sym.h> +# else +# define BP_SYM (sym) sym +# endif +weak_extern (BP_SYM (__pthread_mutex_init)) +weak_extern (BP_SYM (__pthread_mutex_destroy)) +weak_extern (BP_SYM (__pthread_mutex_lock)) +weak_extern (BP_SYM (__pthread_mutex_trylock)) +weak_extern (BP_SYM (__pthread_mutex_unlock)) +weak_extern (BP_SYM (__pthread_mutexattr_init)) +weak_extern (BP_SYM (__pthread_mutexattr_destroy)) +weak_extern (BP_SYM (__pthread_mutexattr_settype)) +weak_extern (BP_SYM (__pthread_rwlock_init)) +weak_extern (BP_SYM (__pthread_rwlock_destroy)) +weak_extern (BP_SYM (__pthread_rwlock_rdlock)) +weak_extern (BP_SYM (__pthread_rwlock_tryrdlock)) +weak_extern (BP_SYM (__pthread_rwlock_wrlock)) +weak_extern (BP_SYM (__pthread_rwlock_trywrlock)) +weak_extern (BP_SYM (__pthread_rwlock_unlock)) +weak_extern (BP_SYM (__pthread_key_create)) +weak_extern (BP_SYM (__pthread_setspecific)) +weak_extern (BP_SYM (__pthread_getspecific)) +weak_extern (BP_SYM (__pthread_once)) +weak_extern (__pthread_initialize) +weak_extern (__pthread_atfork) +weak_extern (BP_SYM (_pthread_cleanup_push_defer)) +weak_extern (BP_SYM (_pthread_cleanup_pop_restore)) +weak_extern (BP_SYM (pthread_setcancelstate)) +# else +# pragma weak __pthread_mutex_init +# pragma weak __pthread_mutex_destroy +# pragma weak __pthread_mutex_lock +# pragma weak __pthread_mutex_trylock +# pragma weak __pthread_mutex_unlock +# pragma weak __pthread_mutexattr_init +# pragma weak __pthread_mutexattr_destroy +# pragma weak __pthread_mutexattr_settype +# pragma weak __pthread_rwlock_init +# pragma weak __pthread_rwlock_destroy +# pragma weak __pthread_rwlock_rdlock +# pragma weak __pthread_rwlock_tryrdlock +# pragma weak __pthread_rwlock_wrlock +# pragma weak __pthread_rwlock_trywrlock +# pragma weak __pthread_rwlock_unlock +# pragma weak __pthread_key_create +# pragma weak __pthread_setspecific +# pragma weak __pthread_getspecific +# pragma weak __pthread_once +# pragma weak __pthread_initialize +# pragma weak __pthread_atfork +# pragma weak _pthread_cleanup_push_defer +# pragma weak _pthread_cleanup_pop_restore +# pragma weak pthread_setcancelstate +# endif +#endif + +#endif /* bits/libc-lock.h */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/pthreadtypes.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/pthreadtypes.h new file mode 100644 index 0000000000..1047f1006b --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/pthreadtypes.h @@ -0,0 +1,125 @@ +/* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#if !defined _BITS_TYPES_H && !defined _PTHREAD_H +# error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead." +#endif + +#ifndef _BITS_PTHREADTYPES_H +#define _BITS_PTHREADTYPES_H 1 + +#define __need_schedparam +#include <bits/sched.h> +#include <stdint.h> +#define __need_pthread_bits +#include <bits/synch.h> + +#define __SIZEOF_PTHREAD_ATTR_T 76 +#define __SIZEOF_PTHREAD_MUTEX_T 24 +#define __SIZEOF_PTHREAD_MUTEXATTR_T 4 +#define __SIZEOF_PTHREAD_COND_T 16 +#define __SIZEOF_PTHREAD_CONDATTR_T 4 +#define __SIZEOF_PTHREAD_RWLOCK_T 80 +#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 +#define __SIZEOF_PTHREAD_BARRIER_T 56 +#define __SIZEOF_PTHREAD_BARRIERATTR_T 4 + + +/* Thread identifiers. The structure of the attribute type is not + exposed on purpose. */ +typedef unsigned int pthread_t; + + +typedef union +{ + char __size[__SIZEOF_PTHREAD_ATTR_T]; + long int __align; +} pthread_attr_t; + + +typedef struct __pthread_internal_slist +{ + struct __pthread_internal_slist *__next; +} __pthread_slist_t; + + +/* Data structures for mutex handling. The structure of the attribute + type is not exposed on purpose. */ +typedef union +{ + char __size[__SIZEOF_PTHREAD_MUTEXATTR_T]; + long int __align; +} pthread_mutexattr_t; + + +/* Data structure for conditional variable handling. The structure of + the attribute type is not exposed on purpose. */ +typedef union +{ + char __size[__SIZEOF_PTHREAD_CONDATTR_T]; + long int __align; +} pthread_condattr_t; + + +/* Keys for thread-specific data */ +typedef unsigned int pthread_key_t; + + +/* Once-only execution */ +typedef int pthread_once_t; + + +#if defined __USE_UNIX98 || defined __USE_XOPEN2K +/* Data structure for read-write lock variable handling. The + structure of the attribute type is not exposed on purpose. */ +typedef union +{ + char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T]; + long int __align; +} pthread_rwlockattr_t; +#endif + + +#ifdef __USE_XOPEN2K +/* POSIX spinlock data type. */ +typedef volatile int pthread_spinlock_t; + + +/* POSIX barriers data type. The structure of the type is + deliberately not exposed. */ +typedef union +{ + char __size[__SIZEOF_PTHREAD_BARRIER_T]; + long int __align; +} pthread_barrier_t; + +typedef union +{ + char __size[__SIZEOF_PTHREAD_BARRIERATTR_T]; + int __align; +} pthread_barrierattr_t; +#endif + + +/* Extra attributes for the cleanup functions. */ +#define __cleanup_fct_attribute __attribute__ ((__regparm__ (1))) + +#endif /* bits/pthreadtypes.h */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/semaphore.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/semaphore.h new file mode 100644 index 0000000000..91874b2b97 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/semaphore.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2002, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SEMAPHORE_H +# error "Never use <bits/semaphore.h> directly; include <semaphore.h> instead." +#endif + + +#define __SIZEOF_SEM_T 16 + + +/* Value returned if `sem_open' failed. */ +#define SEM_FAILED ((sem_t *) -1) + +#define __need_semaphore_bits +#include <bits/synch.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/synch.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/synch.h new file mode 100644 index 0000000000..c977614115 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/bits/synch.h @@ -0,0 +1,164 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <bits/types.h> + +#if (defined __need_pthread_bits && !defined __pthread_bits_defined) || \ + (defined __need_synch_bits && !defined __synch_bits_defined) + +# ifdef __need_pthread_bits +typedef struct +# else +typedef struct _lwp_mutex +# endif + { + struct + { + __uint16_t flag1; + __uint8_t flag2; + __uint8_t ceiling; + union + { + __uint16_t bcptype; + struct + { + __uint8_t count_type1; + __uint8_t count_type2; + } mtype_rcount; + } mbcp_type_un; + __uint16_t magic; + } flags; + union + { + struct + { + __uint8_t pad[8]; + } lock64; + struct + { + __uint32_t ownerpid; + __uint32_t lockword; + } lock32; + __uint64_t owner64; + } lock; +/* XXX: This is a non-standard use of data (see NOTES.opensolaris). */ + union + { + __uint64_t data64; + struct + { + __uint32_t owner; + __uint32_t cond_waiters; + } data32; + } data; +# ifdef __need_pthread_bits + } pthread_mutex_t; +# else + } lwp_mutex_t; +# endif + +# ifdef __need_pthread_bits +typedef struct +# else +typedef struct _lwp_cond +# endif +{ + struct + { + __uint8_t flag[4]; + __uint16_t type; + __uint16_t magic; + } flags; + __uint64_t data; +# ifdef __need_pthread_bits + } pthread_cond_t; +# else + } lwp_cond_t; +# endif + +#endif /* defined __need_pthread_bits && !defined ... */ + +#if (defined __need_pthread_bits && (defined __USE_UNIX98 || \ + defined __USE_XOPEN2K) && !defined __pthread_bits_defined) || \ + (defined __need_synch_bits && !defined __synch_bits_defined) + +# ifdef __need_pthread_bits +typedef struct +# else +typedef struct _lwp_rwlock +# endif + { + __int32_t readers; + __uint16_t type; + __uint16_t magic; +# ifdef __need_pthread_bits + pthread_mutex_t mutex; + pthread_cond_t readercv; + pthread_cond_t writercv; +# else + lwp_mutex_t mutex; + lwp_cond_t readercv; + lwp_cond_t writercv; +# endif +/* XXX: These are non-standard additions (see NOTES.opensolaris). */ + __uint64_t owner; + __uint32_t ownerpid; + __uint32_t pad; +# ifdef __need_pthread_bits + } pthread_rwlock_t; +# else +} lwp_rwlock_t; +# endif + +#endif /* defined __need_pthread_bits && !defined ... */ + +#if (defined __need_semaphore_bits && !defined __semaphore_bits_defined) || \ + (defined __need_synch_bits && !defined __synch_bits_defined) + +#ifdef __need_semaphore_bits +typedef struct +#else +typedef struct _lwp_sema +#endif + { + __uint32_t count; + __uint16_t type; + __uint16_t magic; + __uint8_t flags[8]; + __uint64_t data; +#ifdef __need_semaphore_bits + } sem_t; +#else + } lwp_sema_t; +#endif + +#endif /* defined __need_semaphore_bits && !defined ... */ + +#ifdef __need_pthread_bits +# undef __need_pthread_bits +# define __pthread_bits_defined +#endif +#ifdef __need_semaphore_bits +# undef __need_semaphore_bits +# define __semaphore_bits_defined +#endif +#ifdef __need_synch_bits +# undef __need_synch_bits +# define __synch_bits_defined +#endif diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_broadcast.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_broadcast.c new file mode 100644 index 0000000000..1681df6c2c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_broadcast.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + +DECLARE_INLINE_SYSCALL (int, lwp_cond_broadcast, cond_t *cv); + + +int cond_broadcast (cond) + cond_t *cond; +{ + /* Don't bother entering the kernel if there are no waiters. */ + if (cond->cond_waiters_kernel == 0) + return 0; + + return INLINE_SYSCALL (lwp_cond_broadcast, 1, cond); +} + +weak_alias (cond_broadcast, _lwp_cond_broadcast) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_destroy.c new file mode 100644 index 0000000000..2b502eeafb --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_destroy.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + + +int cond_destroy (cond) + cond_t *cond; +{ + memset (cond, 0, sizeof(cond_t)); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_init.c new file mode 100644 index 0000000000..b27f7d744f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_init.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + + +int cond_init (cond, type, arg) + cond_t *cond; + int type; + void *arg; +{ + if (type != LOCK_NORMAL && type != LOCK_SHARED) + return EINVAL; + + memset (cond, 0, sizeof(cond_t)); + cond->cond_type = type; + cond->cond_magic = COND_MAGIC; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_reltimedwait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_reltimedwait.c new file mode 100644 index 0000000000..61af00a1ea --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_reltimedwait.c @@ -0,0 +1,162 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + +DECLARE_INLINE_SYSCALL (int, lwp_cond_wait, cond_t *cv, mutex_t *mp, + struct timespec *tsp, int check_park); + +struct _condvar_cleanup_buffer +{ + int oldtype; + cond_t *cond; + mutex_t *mutex; + int recursive; + uint8_t old_mutex_rcount; +}; + +void +__attribute__ ((visibility ("hidden"))) +__condvar_cleanup (void *arg) +{ + struct _condvar_cleanup_buffer *cbuffer = + (struct _condvar_cleanup_buffer *) arg; + mutex_t *mutex = cbuffer->mutex; + + /* Note: we don't whether the mutex was unlocked by the kernel or not. */ + + int errval = 0; + while (1) + { + if (MUTEX_IS_OWNER (mutex)) + { + /* The lock is held by us (we didn't get signaled). */ + break; + } + else + { + /* The mutex was unlocked so we claim it, */ + errval = mutex_lock (mutex); + break; + } + } + + /* Restore the mutex_rcount. */ + if (errval == 0) + mutex->mutex_rcount = cbuffer->old_mutex_rcount; + + /* The condition variable is no longer using the mutex. */ + atomic_decrement (&mutex->mutex_cond_waiters); +} + + +int +__cond_reltimedwait_internal (cond, mutex, reltime, cancel) + cond_t *cond; + mutex_t *mutex; + struct timespec *reltime; + int cancel; +{ + struct _pthread_cleanup_buffer buffer; + struct _condvar_cleanup_buffer cbuffer = { + .recursive = 0 + }; + + /* Reject invalid timeouts. */ + if (PAST_TIMESPEC (reltime)) + return ETIME; + else if (INVALID_TIMESPEC (reltime)) + return EINVAL; + + if ((mutex->mutex_type & LOCK_ERRORCHECK) && MUTEX_NOT_OWNER (mutex)) + { + /* Error checking: lock not held by this thread. */ + return EPERM; + } + else if ((mutex->mutex_type & LOCK_RECURSIVE) && MUTEX_IS_OWNER (mutex) && + mutex->mutex_rcount > 0) + { + /* Recursively held lock. XXX: Using recursive mutexes with condition + variables is undefined; we do what sun's libc does, namely fully + release the lock. */ + cbuffer.recursive = 1; + cbuffer.old_mutex_rcount = mutex->mutex_rcount; + mutex->mutex_rcount = 0; + } + + /* Mark the mutex as still in use. */ + atomic_increment (&mutex->mutex_cond_waiters); + + /* Prepare structure passed to cancellation handler. */ + cbuffer.cond = cond; + cbuffer.mutex = mutex; + + if (cancel) + { + /* Before we block we enable cancellation. Therefore we have to + install a cancellation handler. */ + __pthread_cleanup_push (&buffer, __condvar_cleanup, &cbuffer); + + /* Enable asynchronous cancellation. Required by the standard. */ + cbuffer.oldtype = __pthread_enable_asynccancel (); + } + + int errval = INLINE_SYSCALL (lwp_cond_wait, 4, cond, mutex, reltime, 1); + + if (cancel) + { + /* Disable asynchronous cancellation. */ + __pthread_disable_asynccancel (cbuffer.oldtype); + + /* The cancellation handling is back to normal, remove the handler. */ + __pthread_cleanup_pop (&buffer, 0); + } + + /* Re-acquire the lock. The docs say we must always re-acquire so we don't + use __mutex_timedlock. Note that even if the above wait fails the kernel + always unlocks the mutex. */ + int errval2 = mutex_lock (mutex); + if (errval2 == EOWNERDEAD) + errval = errval2; + else if (errval == 0) + errval = errval2; + + /* Restore the mutex_rcount. */ + if ((errval2 == 0 || errval2 == EOWNERDEAD) && cbuffer.recursive) + mutex->mutex_rcount = cbuffer.old_mutex_rcount; + + /* The condition variable is no longer using the mutex. */ + atomic_decrement (&mutex->mutex_cond_waiters); + + return errval; +} + + +int cond_reltimedwait (cond, mutex, reltime) + cond_t *cond; + mutex_t *mutex; + struct timespec *reltime; +{ + return __cond_reltimedwait_internal (cond, mutex, reltime, 1); +} + +weak_alias (cond_reltimedwait, _lwp_cond_reltimedwait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_signal.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_signal.c new file mode 100644 index 0000000000..4173672527 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_signal.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + +DECLARE_INLINE_SYSCALL (int, lwp_cond_signal, cond_t *cv); + + +int cond_signal (cond) + cond_t *cond; +{ + /* Don't bother entering the kernel if there are no waiters. */ + if (cond->cond_waiters_kernel == 0) + return 0; + + return INLINE_SYSCALL (lwp_cond_signal, 1, cond); +} + +weak_alias (cond_signal, _lwp_cond_signal) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_timedwait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_timedwait.c new file mode 100644 index 0000000000..9d6e2bd5ca --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_timedwait.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <abstime-to-reltime.h> + + +int cond_timedwait (cond, mutex, abstime) + cond_t *cond; + mutex_t *mutex; + struct timespec *abstime; +{ + /* Reject invalid timeouts. */ + if (INVALID_TIMESPEC (abstime)) + return EINVAL; + + struct timespec _reltime; + struct timespec *reltime = abstime_to_reltime (abstime, &_reltime); + return cond_reltimedwait (cond, mutex, reltime); +} + +weak_alias (cond_timedwait, _lwp_cond_timedwait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_wait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_wait.c new file mode 100644 index 0000000000..2a8aae5a83 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/cond_wait.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + + +int cond_wait (cond, mutex) + cond_t *cond; + mutex_t *mutex; +{ + return cond_reltimedwait (cond, mutex, NULL); +} + +weak_alias (cond_wait, _lwp_cond_wait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c new file mode 100644 index 0000000000..0bb1b81c0a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/createthread.c @@ -0,0 +1,137 @@ +/* Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <tls.h> +#include <ucontext.h> +#include <sys/stack.h> +#include <sys/stack.h> +#include <sys/regset.h> +#include <sys/lwp.h> +#include <inline-syscall.h> +#include <schedP.h> +#include <createthread_arch.c> + +DECLARE_INLINE_SYSCALL (int, lwp_create, ucontext_t *ucp, int flags, + pthread_t *new_lwp); +DECLARE_INLINE_SYSCALL (int, lwp_continue, pthread_t lwpid); +DECLARE_INLINE_SYSCALL (int, lwp_kill, pthread_t lwpid, int sig); + +#ifndef TLS_MULTIPLE_THREADS_IN_TCB +/* Pointer to the corresponding variable in libc. */ +int *__libc_multiple_threads_ptr attribute_hidden; +#endif + +static int +create_thread (struct pthread *pd, const struct pthread_attr *attr, + STACK_VARIABLES_PARMS) +{ +#ifdef TLS_TCB_AT_TP + assert (pd->header.tcb != NULL); +#endif + + /* Do arch-specific creation. */ + ucontext_t ctx = {0}; + int errval = create_thread_arch (&ctx, pd, attr, STACK_VARIABLES_ARGS); + if (errval != 0) + return errval; + + /* Threads inherit the parent's sigmask. */ + pthread_sigmask (SIG_SETMASK, NULL, &ctx.uc_sigmask); + + /* One more thread. We cannot have the thread do this itself, since it + might exist but not have been scheduled yet by the time we've returned + and need to check the value to behave correctly. We must do it before + creating the thread, in case it does get scheduled first and then + might mistakenly think it was the only thread. In the failure case, + we momentarily store a false value; this doesn't matter because there + is no kosher thing a signal handler interrupting us right here can do + that cares whether the thread count is correct. */ + atomic_increment (&__nptl_nthreads); + + /* We set the thread to be initially suspended so that we can set + scheduling magic. */ + int lwp_flags = + ((attr->flags & ATTR_FLAG_DAEMON) ? LWP_DAEMON : 0) | + ((attr->flags & ATTR_FLAG_DETACHSTATE) ? LWP_DETACHED : 0); + if ((attr->flags & ATTR_FLAG_THR_CREATE) == 0) + lwp_flags |= LWP_SUSPENDED; + errval = INLINE_SYSCALL (lwp_create, 3, &ctx, lwp_flags, &pd->tid); + if (errval == 0 && (attr->flags & ATTR_FLAG_THR_CREATE) == 0) + { + /* Set scheduling. */ + if (attr->flags & (ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET)) + { + int policy, priority; + errval = __sched_getscheduler_id (P_LWPID, pd->tid, + &policy, &priority); + if (errval == 0) + { + if (attr->flags & ATTR_FLAG_SCHED_SET) + priority = attr->schedparam.__sched_priority; + if (attr->flags & ATTR_FLAG_POLICY_SET) + policy = attr->schedpolicy; + + errval = __sched_setscheduler_id (P_LWPID, pd->tid, + policy, priority); + } + + if (errval != 0) + errval = EPERM; + } + + /* TODO: remove this hack once scheduling works. */ + errval = 0; + + if (errval == 0 && !(attr->flags & ATTR_FLAG_SUSPENDED)) + { + errval = INLINE_SYSCALL (lwp_continue, 1, pd->tid); + } + else if (errval != 0) + { + pd->flags |= ATTR_FLAG_CREATE_FAILED; + INLINE_SYSCALL (lwp_continue, 1, pd->tid); + + if (!IS_DETACHED (pd)) + { + int result; + lll_wait_tid (pd->tid); + } + + /* Note: if the thread is detached, start_thread will free pd; + otherwise the caller of create_thread will free pd. */ + } + } + + if (errval == 0) + { + /* We now have for sure more than one thread. The main thread might + not yet have the flag set. No need to set the global variable + again if this is what we use. */ + THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); + } + else + { + atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */ + } + + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fastlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fastlock.c new file mode 100644 index 0000000000..4612de0866 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fastlock.c @@ -0,0 +1,135 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synchP.h> +#include <sys/synch.h> +#include <stdbool.h> +#include <assert.h> + +int __mutex_lock_fast (mutex_t *mutex, bool try) +{ + if (mutex->mutex_lockword32 == LOCKWORD32_UNSET_NO_WAITERS) + { + /* The mutex is not held by anyone so try to grab it. */ + if (mutex->mutex_type & LOCK_SHARED) + { + uint64_t new_lockword64 = LOCKWORD64_SET_NO_WAITERS | + (THREAD_GETMEM (THREAD_SELF, pid) << MUTEX_OWNERPID_SHIFT); + uint64_t old_lockword64 = atomic_compare_and_exchange_val_acq ( + &mutex->mutex_lockword64, new_lockword64, + LOCKWORD64_UNSET_NO_WAITERS); + if (__builtin_expect (old_lockword64 == + LOCKWORD64_UNSET_NO_WAITERS, 1)) + { + mutex->mutex_owner = THREAD_GETMEM (THREAD_SELF, tid); + return 0; + } + } + else + { + uint32_t old_lockword32 = atomic_compare_and_exchange_val_acq ( + &mutex->mutex_lockword32, LOCKWORD32_SET_NO_WAITERS, + LOCKWORD32_UNSET_NO_WAITERS); + if (__builtin_expect (old_lockword32 == + LOCKWORD32_UNSET_NO_WAITERS, 1)) + { + mutex->mutex_owner = THREAD_GETMEM (THREAD_SELF, tid); + return 0; + } + } + } + else if ((mutex->mutex_type & LOCK_RECURSIVE) && MUTEX_IS_OWNER (mutex)) + { + /* Recursively held lock. */ + if (mutex->mutex_rcount == RECURSION_MAX) + return EAGAIN; + mutex->mutex_rcount++; + return 0; + } + else if ((mutex->mutex_type & LOCK_ERRORCHECK) && MUTEX_IS_OWNER (mutex)) + { + /* Error checking: lock already held. */ + return EDEADLK; + } + else if (try && mutex->mutex_lockbyte == LOCKBYTE_SET) + { + /* Tried to lock but lock was held. */ + return EBUSY; + } + + /* Need to use the slow code. */ + return -1; +} + + +int __mutex_unlock_fast (mutex_t *mutex) +{ + if ((mutex->mutex_type & LOCK_RECURSIVE) && MUTEX_IS_OWNER (mutex) && + mutex->mutex_rcount > 0) + { + /* Recursively held lock. */ + --mutex->mutex_rcount; + return 0; + } + else if ((mutex->mutex_type & LOCK_ERRORCHECK) && MUTEX_NOT_OWNER (mutex)) + { + /* error checking: lock not held by this thread */ + return EPERM; + } + else if (mutex->mutex_lockword32 == LOCKWORD32_SET_NO_WAITERS) + { + /* We need to clear the owner before we fully unlock. Otherwise + we have a race condition where we might clear the owner after + another thread sets the lock word. If we fail to unlock here + we don't need to reset the owner as we're just going to unlock + in the kernel (which doesn't check this field anyhow). */ + mutex->mutex_owner = 0; + + /* Nobody is waiting on the mutex so we can try to release it. */ + if (mutex->mutex_type & LOCK_SHARED) + { + uint64_t test_lockword64 = LOCKWORD64_SET_NO_WAITERS | + (mutex->mutex_ownerpid << MUTEX_OWNERPID_SHIFT); + (THREAD_GETMEM (THREAD_SELF, pid) << MUTEX_OWNERPID_SHIFT); + uint64_t old_lockword64 = atomic_compare_and_exchange_val_acq ( + &mutex->mutex_lockword64, LOCKWORD64_UNSET_NO_WAITERS, + test_lockword64); + if (__builtin_expect (old_lockword64 == test_lockword64, 1)) + { + return 0; + } + } + else + { + uint32_t old_lockword32 = atomic_compare_and_exchange_val_acq ( + &mutex->mutex_lockword32, LOCKWORD32_UNSET_NO_WAITERS, + LOCKWORD32_SET_NO_WAITERS); + if (__builtin_expect (old_lockword32 == + LOCKWORD32_SET_NO_WAITERS, 1)) + { + return 0; + } + } + } + + /* Need to use the slow code. */ + return -1; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fork.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fork.c new file mode 100644 index 0000000000..a0e03945bb --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fork.c @@ -0,0 +1,44 @@ +/* Copyright (C) 2002, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <sysdep.h> +#include <tls.h> + +DECLARE_INLINE_SYSCALL (int64_t, forkx, int flags); + +static inline pid_t ARCH_FORK(void) +{ + rval_t res; + res.rval64 = INLINE_SYSCALL (forkx, 1, 0); + + /* Only the lower 32-bits are set to -1 on error (see NOTES.opensolaris). */ + if (res.rval1 == -1) + return (pid_t)-1; + else if (res.rval2 != 0) + return 0; + else + return (pid_t)res.rval1; +} +#define ARCH_FORK ARCH_FORK + +#include <nptl/sysdeps/unix/sysv/linux/fork.c> +weak_alias (__libc_fork, fork1) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fork.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fork.h new file mode 100644 index 0000000000..bcf670035c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/fork.h @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/fork.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/gai_misc.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/gai_misc.h new file mode 100644 index 0000000000..8601d8325d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/gai_misc.h @@ -0,0 +1,73 @@ +/* Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* We define a special synchronization primitive for AIO. POSIX + conditional variables would be ideal but the pthread_cond_*wait + operations do not return on EINTR. This is a requirement for + correct aio_suspend and lio_listio implementations. */ + +#include <assert.h> +#include <signal.h> +#include <pthreadP.h> + +#undef DONT_NEED_GAI_MISC_COND + + +#define gai_start_notify_thread __gai_start_notify_thread +#define gai_create_helper_thread __gai_create_helper_thread + +extern inline void +__gai_start_notify_thread (void) +{ + sigset_t ss; + sigemptyset (&ss); + sigprocmask (SIG_SETMASK, &ss, NULL); +} + +extern inline int +__gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *), + void *arg) +{ + pthread_attr_t attr; + + /* Make sure the thread is created detached. */ + pthread_attr_init (&attr); + pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + + /* The helper thread needs only very little resources. */ + (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); + + /* Block all signals in the helper thread. To do this thoroughly we + temporarily have to block all signals here. */ + sigset_t ss; + sigset_t oss; + sigfillset (&ss); + sigprocmask (SIG_SETMASK, &ss, &oss); + + int ret = pthread_create (threadp, &attr, tf, arg); + + /* Restore the signal mask. */ + sigprocmask (SIG_SETMASK, &oss, NULL); + + (void) pthread_attr_destroy (&attr); + return ret; +} + +#include <resolv/gai_misc.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/Implies b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/Implies new file mode 100644 index 0000000000..772b20e20f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/Implies @@ -0,0 +1 @@ +unix/sysv/solaris2/kopensolaris-gnu/x86 diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/createthread_arch.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/createthread_arch.c new file mode 100644 index 0000000000..4241f9182c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/createthread_arch.c @@ -0,0 +1,52 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define LWPGS_SEL 0x01C3 + +static int +create_thread_arch (ucontext_t *ctx, struct pthread *pd, + const struct pthread_attr *attr, STACK_VARIABLES_PARMS) +{ + /* Clone the segment registers (except gs - see below). */ + ucontext_t _ctx; + _ctx.uc_flags = UC_CPU; + if (getcontext(&_ctx) != 0) + return errno; + ctx->uc_mcontext.gregs[CS] = _ctx.uc_mcontext.gregs[CS]; + ctx->uc_mcontext.gregs[DS] = _ctx.uc_mcontext.gregs[DS]; + ctx->uc_mcontext.gregs[ES] = _ctx.uc_mcontext.gregs[ES]; + ctx->uc_mcontext.gregs[FS] = _ctx.uc_mcontext.gregs[FS]; + ctx->uc_mcontext.gregs[SS] = _ctx.uc_mcontext.gregs[SS]; + + /* Setup the stack (note that it grows down). */ + uint32_t *stack_ptr = (uint32_t *)((uintptr_t)((uint32_t *)stackaddr - 1) & + ~(STACK_ALIGN - 1)) + 1; + *--stack_ptr = (uint32_t)pd; /* arg 1 */ + *--stack_ptr = 0; /* return addr (thread_start never returns) */ + ctx->uc_mcontext.gregs[UESP] = (greg_t)stack_ptr; + ctx->uc_mcontext.gregs[EBP] = 0; + ctx->uc_mcontext.gregs[EIP] = (greg_t)start_thread; + ctx->uc_flags |= UC_CPU; + + /* This is a hack to get the kernel to set gs for us. */ + ctx->uc_mcontext.gregs[GS] = (greg_t)LWPGS_SEL; + ctx->uc_mcontext.gregs[ESP] = (greg_t)pd; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/sysdep-cancel.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/sysdep-cancel.h new file mode 100644 index 0000000000..480283a22e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/sysdep-cancel.h @@ -0,0 +1,186 @@ +/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2002. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep.h> +#include <tls.h> +#ifndef __ASSEMBLER__ +# include <pthreadP.h> +#endif + +/* XXX: We don't support _NOERRNO or _ERRVAL varietites. */ +#undef PSEUDO_ERRNO +#undef PSEUDO_SUBCALL_NOERRNO +#undef PSEUDO_ERRVAL +#undef PSEUDO_SUBCALL_NOERRNO + +/* This is needed so that we don't clobber %edx in the cancellation calls. */ +#ifdef SYSCALL_64BIT_RETURN +# define SYSCALL_64BIT_PUSH_ASM pushl %edx; cfi_adjust_cfa_offset (4); +# define SYSCALL_64BIT_POP_ASM popl %edx; cfi_adjust_cfa_offset (-4); +#else +# define SYSCALL_64BIT_PUSH_ASM +# define SYSCALL_64BIT_POP_ASM +#endif + +#ifdef SYSCALL_RESTARTABLE +# define DO_RESTART_CANCEL \ + cmpl $ERESTART, %eax; \ + je L(restart_cancel); +#else +# define DO_RESTART_CANCEL +#endif + +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt + +/* Note that CDISABLE is an internal function, so we need to + pass-by-register (we pass the argument in %eax). */ + +# undef PSEUDO +# define PSEUDO(name, syscall_name, args) \ + .text; \ + ENTRY (name) \ + cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \ + jne L(pseudo_cancel); \ + .type __##syscall_name##_nocancel,@function; \ + .globl __##syscall_name##_nocancel; \ + __##syscall_name##_nocancel: \ + L(restart): \ + DO_CALL (syscall_name, args); \ + jnb 2f; \ + DO_RESTART \ + jmp SYSCALL_ERROR_LABEL; \ +2: ret; \ + .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \ + L(pseudo_cancel): \ + L(restart_cancel): \ + CENABLE; \ + movl %eax, %ecx; \ + DO_CALL (syscall_name, args); \ + jnb 3f; \ + DO_RESTART_CANCEL \ + pushl %eax; cfi_adjust_cfa_offset (4); \ + SYSCALL_64BIT_PUSH_ASM \ + movl %ecx, %eax; \ + CDISABLE; \ + SYSCALL_64BIT_POP_ASM \ + popl %eax; cfi_adjust_cfa_offset (-4); \ + jmp SYSCALL_ERROR_LABEL; \ +3: \ + pushl %eax; cfi_adjust_cfa_offset (4); \ + SYSCALL_64BIT_PUSH_ASM \ + movl %ecx, %eax; \ + CDISABLE; \ + SYSCALL_64BIT_POP_ASM \ + popl %eax; cfi_adjust_cfa_offset (-4); \ + L(pseudo_end): + +# undef PSEUDO_SUBCALL +# define PSEUDO_SUBCALL(name, syscall_name, subcall_name, args) \ + .text; \ + ENTRY (name) \ + cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \ + jne L(pseudo_cancel); \ + .type __##subcall_name##_nocancel,@function; \ + .globl __##subcall_name##_nocancel; \ + __##subcall_name##_nocancel: \ + movl 0(%esp), %ecx; \ + movl %ecx, -4(%esp); \ + addl $-4, %esp; \ + movl $SYS_ify (SUB_##subcall_name), 4(%esp); \ + L(restart): \ + DO_CALL (syscall_name, args); \ + jnb 2f; \ + DO_RESTART \ + movl %ecx, 4(%esp); \ + addl $-4, %esp; \ + jmp SYSCALL_ERROR_LABEL; \ +2: \ + addl $4, %esp; \ + movl %ecx, 0(%esp); \ + ret; \ + .size __##subcall_name##_nocancel,.-__##subcall_name##_nocancel; \ + L(pseudo_cancel): \ + CENABLE; \ + movl %eax, %ecx; \ + movl 0(%esp), %edx; \ + movl %edx, -4(%esp); \ + addl $-4, %esp; \ + movl $SYS_ify (SUB_##subcall_name), 4(%esp); \ + L(restart_cancel): \ + DO_CALL (syscall_name, args); \ + jnb 3f; \ + DO_RESTART_CANCEL \ + pushl %eax; cfi_adjust_cfa_offset (4); \ + SYSCALL_64BIT_PUSH_ASM \ + movl %ecx, %eax; \ + CDISABLE; \ + SYSCALL_64BIT_POP_ASM \ + popl %eax; cfi_adjust_cfa_offset (-4); \ + movl 0(%esp), %ecx; \ + movl %ecx, 4(%esp); \ + addl $4, %esp; \ + jmp SYSCALL_ERROR_LABEL; \ +3: \ + pushl %eax; cfi_adjust_cfa_offset (4); \ + SYSCALL_64BIT_PUSH_ASM \ + movl %ecx, %eax; \ + CDISABLE; \ + SYSCALL_64BIT_POP_ASM \ + popl %eax; cfi_adjust_cfa_offset (-4); \ + movl 0(%esp), %ecx; \ + movl %ecx, 4(%esp); \ + addl $4, %esp; \ + L(pseudo_end): + + +# define SAVE_OLDTYPE movl %eax, %ecx; +# ifdef IS_IN_libpthread +# define CENABLE call __pthread_enable_asynccancel; +# define CDISABLE call __pthread_disable_asynccancel +# elif !defined NOT_IN_libc +# define CENABLE call __libc_enable_asynccancel; +# define CDISABLE call __libc_disable_asynccancel +# elif defined IS_IN_librt +# define CENABLE call __librt_enable_asynccancel; +# define CDISABLE call __librt_disable_asynccancel +# else +# error Unsupported library +# endif + +# ifndef __ASSEMBLER__ +# define SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) == 0, 1) +# else +# define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET +# endif + +#elif !defined __ASSEMBLER__ + +# define SINGLE_THREAD_P (1) +# define NO_CANCELLATION 1 + +#endif + +#ifndef __ASSEMBLER__ +# define RTLD_SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) == 0, 1) +#endif diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/tcb-offsets.sym b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/tcb-offsets.sym new file mode 100644 index 0000000000..4db5d95e11 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/tcb-offsets.sym @@ -0,0 +1,8 @@ +#include <sysdep.h> +#include <tls.h> + +MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) +#ifdef NEED_DL_SYSINFO +SYSINFO_OFFSET offsetof (tcbhead_t, sysinfo) +#endif +POINTER_GUARD offsetof (tcbhead_t, pointer_guard) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/tls.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/tls.h new file mode 100644 index 0000000000..6bacdd859e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/i386/tls.h @@ -0,0 +1,61 @@ +/* Definition for thread-local data handling. OpenSolaris/i386 version. + Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _OPENSOLARIS_TLS_H +#define _OPENSOLARIS_TLS_H 1 + +/* __thread doesn't work for statically-linked executables. */ +#if !defined (SHARED) +# undef HAVE___THREAD +#endif + +/* We can use most of the code from the nptl tls.h. */ +#include_next <tls.h> + +#ifndef __ASSEMBLER__ + +/* OpenSolaris has lwp_private in order to set the thread data. */ +# include <sys/lwp.h> +# include <sys/syscall.h> + +# undef TLS_INIT_TP +# define TLS_INIT_TP(thrdescr, secondcall) \ + ({ void *_thrdescr = (thrdescr); \ + tcbhead_t *_head = _thrdescr; \ + sysret_t ret; \ + \ + _head->tcb = _thrdescr; \ + /* For now the thread descriptor is at the same address. */ \ + _head->self = _thrdescr; \ + /* New syscall handling support. */ \ + INIT_SYSINFO; \ + \ + (__systemcall (&ret, SYS_lwp_private, _LWP_SETPRIVATE, _LWP_GSBASE, \ + (uintptr_t)_thrdescr) != 0) \ + ? "lwp_private failed when setting up thread-local storage\n" : NULL; \ + }) + +/* TODO: Figure out what to define this as. */ +# undef DB_THREAD_SELF + +# endif /* __ASSEMBLER__ */ + +#endif /* _OPENSOLARIS_TLS_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h new file mode 100644 index 0000000000..c6ab6ec144 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/internaltypes.h @@ -0,0 +1,158 @@ +/* Copyright (C) 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _INTERNALTYPES_H +#define _INTERNALTYPES_H 1 + +#include <stdint.h> +#include <time.h> +#include <stdbool.h> + + +struct pthread_attr +{ + /* Scheduler parameters and priority. */ + struct sched_param schedparam; + int schedpolicy; + /* Various flags like detachstate, scope, etc. */ + int flags; + /* Size of guard area. */ + size_t guardsize; + /* Stack handling. */ + void *stackaddr; + size_t stacksize; + /* Affinity map. */ + cpu_set_t *cpuset; + size_t cpusetsize; +}; + +#define ATTR_FLAG_DETACHSTATE 0x0001 +#define ATTR_FLAG_NOTINHERITSCHED 0x0002 +#define ATTR_FLAG_SCOPEPROCESS 0x0004 +#define ATTR_FLAG_STACKADDR 0x0008 +#define ATTR_FLAG_OLDATTR 0x0010 +#define ATTR_FLAG_SCHED_SET 0x0020 +#define ATTR_FLAG_POLICY_SET 0x0040 +#define ATTR_FLAG_DAEMON 0x0080 +#define ATTR_FLAG_SUSPENDED 0x0100 +#define ATTR_FLAG_THR_CREATE 0x0200 +#define ATTR_FLAG_CREATE_FAILED 0x0400 + + +/* Mutex attribute data structure. */ +struct pthread_mutexattr +{ + /* Identifier for the kind of mutex. + + Bit 31 is set if the mutex is to be shared between processes. + + Bit 0 to 30 contain one of the PTHREAD_MUTEX_ values to identify + the type of the mutex. */ + int mutexkind; +}; + + +/* Conditional variable attribute data structure. */ +struct pthread_condattr +{ + /* Combination of values: + + Bit 0 : flag whether coditional variable will be shareable between + processes. + + Bit 1-7: clock ID. */ + int value; +}; + + +/* The __NWAITERS field is used as a counter and to house the number + of bits for other purposes. COND_CLOCK_BITS is the number + of bits needed to represent the ID of the clock. COND_NWAITERS_SHIFT + is the number of bits reserved for other purposes like the clock. */ +#define COND_CLOCK_BITS 3 +#define COND_NWAITERS_SHIFT 3 + + +/* Read-write lock variable attribute data structure. */ +struct pthread_rwlockattr +{ + int lockkind; + int pshared; +}; + +#define BARRIER_EXITING 0x01 + +/* Barrier data structure. */ +struct pthread_barrier +{ + pthread_mutex_t mutex; + pthread_cond_t cond; + unsigned int curr_event; + unsigned int left; + unsigned int init_count; + unsigned int flag; +}; + + +/* Barrier variable attribute data structure. */ +struct pthread_barrierattr +{ + int pshared; +}; + + +/* Thread-local data handling. */ +struct pthread_key_struct +{ + /* Sequence numbers. Even numbers indicated vacant entries. Note + that zero is even. We use uintptr_t to not require padding on + 32- and 64-bit machines. On 64-bit machines it helps to avoid + wrapping, too. */ + uintptr_t seq; + + /* Destructor for the data. */ + void (*destr) (void *); +}; + +/* Check whether an entry is unused. */ +#define KEY_UNUSED(p) (((p) & 1) == 0) +/* Check whether a key is usable. We cannot reuse an allocated key if + the sequence counter would overflow after the next destroy call. + This would mean that we potentially free memory for a key with the + same sequence. This is *very* unlikely to happen, A program would + have to create and destroy a key 2^31 times (on 32-bit platforms, + on 64-bit platforms that would be 2^63). If it should happen we + simply don't use this specific key anymore. */ +#define KEY_USABLE(p) (((uintptr_t) (p)) < ((uintptr_t) ((p) + 2))) + + +/* Handling of read-write lock data. */ +// XXX For now there is only one flag. Maybe more in future. +//#define RWLOCK_RECURSIVE(rwlock) ((rwlock)->__data.__flags != 0) + + +/* Compatibility type for old conditional variable interfaces. */ +typedef struct +{ + pthread_cond_t *cond; +} pthread_cond_2_0_t; + +#endif /* internaltypes.h */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/jmp-unwind.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/jmp-unwind.c new file mode 100644 index 0000000000..f2604ef3f4 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/jmp-unwind.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/jmp-unwind.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc-lowlevellock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc-lowlevellock.c new file mode 100644 index 0000000000..78c211776f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc-lowlevellock.c @@ -0,0 +1 @@ +#include <lowlevellock.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc_multiple_threads.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc_multiple_threads.c new file mode 100644 index 0000000000..e34c282241 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc_multiple_threads.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/libc_multiple_threads.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc_pthread_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc_pthread_init.c new file mode 100644 index 0000000000..dfc2501847 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/libc_pthread_init.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/libc_pthread_init.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/linux_fsinfo.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/linux_fsinfo.h new file mode 100644 index 0000000000..6bd482b9bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/linux_fsinfo.h @@ -0,0 +1 @@ +/* This exists to make nptl/sem_open.c happy. */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevellock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevellock.c new file mode 100644 index 0000000000..866b304c0e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevellock.c @@ -0,0 +1 @@ +/* See lowlevellock.h */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevellock.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevellock.h new file mode 100644 index 0000000000..aad334c15a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevellock.h @@ -0,0 +1,49 @@ +#ifndef _LOWLEVELLOCK_H +#define _LOWLEVELLOCK_H 1 + +#include <pthread.h> + +#define lll_define(class, futex) \ + class pthread_mutex_t futex + +#define LLL_LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER + +#define lll_define_initialized(class, futex) \ + class pthread_mutex_t futex = PTHREAD_MUTEX_INITIALIZER + +#include <stddef.h> +#include <sys/syscall.h> +#include <bits/libc-lock.h> + +#define lll_init(futex) \ + __libc_lock_init (futex) + +#define lll_lock(futex, private) \ + __libc_lock_lock (futex) + +#define lll_trylock(futex) \ + __libc_lock_trylock (futex) + +#define lll_unlock(futex, private) \ + __libc_lock_unlock (futex) + +/* XXX: We emulate futex_wait/wake via busy waiting. */ + +#define lll_futex_wait(futex, val, private) \ + sched_yield () + +#define lll_futex_wake(futex, nr, private) \ + sched_yield () + +/* XXX: We really shouldn't assume the existence of result. */ +#define lll_wait_tid(tid) \ + do { \ + sysret_t __ret; \ + result = __systemcall (&__ret, SYS_lwp_wait, (tid), NULL); \ + } while (result == EINTR || result == ERESTART); + +#define lll_tryjoin(tid) \ + ({sysret_t __ret; \ + __systemcall (&__ret, SYS_lwp_kill, (tid), 0) != ESRCH;}) + +#endif /* _LOWLEVELLOCK_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevelrobustlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevelrobustlock.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/lowlevelrobustlock.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/malloc-machine.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/malloc-machine.h new file mode 100644 index 0000000000..41ba65c1d5 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/malloc-machine.h @@ -0,0 +1,64 @@ +/* Basic platform-independent macro definitions for mutexes, + thread-specific data and parameters for malloc. + Copyright (C) 2003, 2008 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _MALLOC_MACHINE_H +#define _MALLOC_MACHINE_H + +#undef thread_atfork_static + +#include <atomic.h> +#include <bits/libc-lock.h> + +#include <synch.h> + +#define mutex_t pthread_mutex_t +#define mutex_init(m) __libc_lock_init (*(m)) +#define mutex_lock(m) __libc_lock_lock (*(m)) +#define mutex_trylock(m) __libc_lock_trylock (*(m)) +#define mutex_unlock(m) __libc_lock_unlock (*(m)) + +/* This is defined by newer gcc version unique for each module. */ +extern void *__dso_handle __attribute__ ((__weak__)); + +#include <fork.h> + +#ifdef SHARED +# define thread_atfork(prepare, parent, child) \ + __register_atfork (prepare, parent, child, __dso_handle) +#else +# define thread_atfork(prepare, parent, child) \ + __register_atfork (prepare, parent, child, \ + &__dso_handle == NULL ? NULL : __dso_handle) +#endif + +/* thread specific data for glibc */ + +#include <bits/libc-tsd.h> + +typedef int tsd_key_t[1]; /* no key data structure, libc magic does it */ +__libc_tsd_define (static, MALLOC) /* declaration/common definition */ +#define tsd_key_create(key, destr) ((void) (key)) +#define tsd_setspecific(key, data) __libc_tsd_set (MALLOC, (data)) +#define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (MALLOC)) + +#include <ldsodefs.h> +#define MALLOC_PROT_EXEC GLRO(dl_malloc_prot_exec) + +#endif /* !defined(_MALLOC_MACHINE_H) */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_consistent.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_consistent.c new file mode 100644 index 0000000000..9227bb2aa3 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_consistent.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + + +int mutex_consistent (mutex) + mutex_t *mutex; +{ + if ((mutex->mutex_type & LOCK_ROBUST) == 0 || + (mutex->mutex_flag & LOCK_INITED) == 0 || + (mutex->mutex_flag & (LOCK_OWNERDEAD | LOCK_UNMAPPED)) == 0) + return EINVAL; + + mutex->mutex_flag &= ~(LOCK_OWNERDEAD | LOCK_UNMAPPED); + + /* The lock cannot be recursively held since it was just reclaimed. */ + mutex->mutex_rcount = 0; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_destroy.c new file mode 100644 index 0000000000..cef57fef0b --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_destroy.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> +#include <synchP.h> + + +int mutex_destroy (mutex) + mutex_t *mutex; +{ + if (mutex->mutex_type & LOCK_ROBUST) + memset (mutex, 0, sizeof(mutex_t)); + else + mutex->mutex_magic = -1; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_init.c new file mode 100644 index 0000000000..6b2977cc00 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_init.c @@ -0,0 +1,63 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> + +DECLARE_INLINE_SYSCALL (int, lwp_mutex_register, mutex_t *lp); + + +int mutex_init (mutex, type, arg) + mutex_t *mutex; + int type; + void * arg; +{ + // TODO: check type + + /* USYNC_PROCESS_ROBUST must be mapped to LOCK_SHARED | LOCK_ROBUST. */ + if (type & USYNC_PROCESS_ROBUST) + type = (type & ~USYNC_PROCESS_ROBUST) | LOCK_SHARED | LOCK_ROBUST; + + if (type & LOCK_ROBUST) + { + if ((mutex->mutex_type & LOCK_INITED)) + return EBUSY; + } + else + { + memset (mutex, 0, sizeof(mutex_t)); + } + mutex->mutex_type = type; + mutex->mutex_flag = LOCK_INITED; + mutex->mutex_magic = MUTEX_MAGIC; + mutex->mutex_ceiling = (int)arg; + mutex->mutex_cond_waiters = 0; + + /* Register robust shared lock. */ + if ((type & (LOCK_ROBUST | LOCK_SHARED)) == (LOCK_ROBUST | LOCK_SHARED)) + { + int errval = INLINE_SYSCALL (lwp_mutex_register, 1, mutex); + if (errval != 0) + return errval; + } + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_lock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_lock.c new file mode 100644 index 0000000000..72baceaaf1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_lock.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int mutex_lock (mutex) + mutex_t *mutex; +{ + return __mutex_timedlock (mutex, NULL); +} + +weak_alias (mutex_lock, _lwp_mutex_lock) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_reltimedlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_reltimedlock.c new file mode 100644 index 0000000000..fa13d50bc1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_reltimedlock.c @@ -0,0 +1,106 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> +#include <time.h> +#include <synchP.h> + +DECLARE_INLINE_SYSCALL (int, lwp_mutex_timedlock, mutex_t *lp, + struct timespec *tsp); + +extern int __mutex_lock_fast (mutex_t *mutex, bool try); + + +int __mutex_reltimedlock (mutex, reltime) + mutex_t *mutex; + const struct timespec *reltime; +{ + /* Handle inconsistent robust mutexes. */ + if ((mutex->mutex_type & LOCK_ROBUST) && + (mutex->mutex_flag & LOCK_NOTRECOVERABLE)) + return ENOTRECOVERABLE; + + /* Always hit the kernel for priority inherit locks. */ + if ((mutex->mutex_type & LOCK_PRIO_INHERIT) == 0) + { + int res = __mutex_lock_fast (mutex, false); + if(res >= 0) + return res; + } + else + { + /* Except when we already hold a recursive lock. */ + if ((mutex->mutex_type & LOCK_RECURSIVE) && MUTEX_IS_OWNER (mutex)) + { + /* XXX: Solaris mutexes have no overflow check and don't know about + EAGAIN; in practice overflow will not occur so we don't care. */ + if (mutex->mutex_rcount == RECURSION_MAX) + return EAGAIN; + ++mutex->mutex_rcount; + return 0; + } + } + + /* Reject invalid timeouts. */ + if (PAST_TIMESPEC (reltime)) + return ETIME; + else if (INVALID_TIMESPEC (reltime)) + return EINVAL; + + int errval; + COPY_TIMESPEC (reltime) + do + errval = INLINE_SYSCALL (lwp_mutex_timedlock, 2, mutex, __reltime); + while (errval == EINTR); + + /* The kernel sets EDEADLK for priority inherit mutexes. */ + if (errval == EDEADLK && (mutex->mutex_type & LOCK_PRIO_INHERIT) && + (mutex->mutex_type & LOCK_ERRORCHECK) == 0) + { + /* We aren't an error checking mutex so we need to block. */ + INTERNAL_SYSCALL_DECL (err); + if (reltime) + { + int res = INTERNAL_SYSCALL (nanosleep, err, 2, __reltime, __reltime); + do + errval = INTERNAL_SYSCALL_ERRNO (res, err) ? EINTR : ETIMEDOUT; + while (errval == EINTR); + } + else + { + do + INTERNAL_SYSCALL (pause, err, 1, 0); + while (1); + } + } + if (errval != 0 && errval != EOWNERDEAD) + return errval; + + /* The kernel does not set mutex_owner so we set it here. */ + mutex->mutex_owner = THREAD_GETMEM (THREAD_SELF, tid); + + /* The kernel does not set the lockbyte for priority inherit mutexes. */ + if (mutex->mutex_type & LOCK_PRIO_INHERIT) + mutex->mutex_lockbyte = 1; + + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_timedlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_timedlock.c new file mode 100644 index 0000000000..ba6a0be954 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_timedlock.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <abstime-to-reltime.h> + + +int __mutex_timedlock (mutex, abstime) + mutex_t *mutex; + const struct timespec *abstime; +{ + /* Reject invalid timeouts. */ + if (INVALID_TIMESPEC (abstime)) + return EINVAL; + + struct timespec _reltime; + struct timespec *reltime = abstime_to_reltime (abstime, &_reltime); + return __mutex_reltimedlock (mutex, reltime); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_trylock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_trylock.c new file mode 100644 index 0000000000..99ba7a13da --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_trylock.c @@ -0,0 +1,77 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> +#include <synchP.h> + +DECLARE_INLINE_SYSCALL (int, lwp_mutex_trylock, mutex_t *lp); + +extern int __mutex_lock_fast (mutex_t *mutex, bool try); + + +int mutex_trylock (mutex) + mutex_t *mutex; +{ + /* Handle inconsistent robust mutexes. */ + if ((mutex->mutex_type & LOCK_ROBUST) && + (mutex->mutex_flag & LOCK_NOTRECOVERABLE)) + return ENOTRECOVERABLE; + + /* Always hit the kernel for priority inherit locks. */ + if ((mutex->mutex_type & LOCK_PRIO_INHERIT) == 0) + { + int result = __mutex_lock_fast (mutex, true); + if(result >= 0) + return result; + } + else + { + /* Except when we already hold a recursive lock. */ + if ((mutex->mutex_type & LOCK_RECURSIVE) && MUTEX_IS_OWNER (mutex) && + mutex->mutex_rcount > 0) + { + if (mutex->mutex_rcount == RECURSION_MAX) + return EAGAIN; + ++mutex->mutex_rcount; + return 0; + } + } + + int errval = INLINE_SYSCALL (lwp_mutex_trylock, 1, mutex); + + /* The kernel sets EDEADLK for priority inherit mutexes. */ + if (mutex->mutex_type & LOCK_PRIO_INHERIT && errval == EDEADLK) + return EBUSY; + if (errval != 0 && errval != EOWNERDEAD) + return errval; + + /* The kernel does not set mutex_owner so we set it here. */ + mutex->mutex_owner = THREAD_GETMEM (THREAD_SELF, tid); + + /* The kernel does not set the lockbyte for priority inherit mutexes. */ + if (mutex->mutex_type & LOCK_PRIO_INHERIT) + mutex->mutex_lockbyte = 1; + + return errval; +} + +weak_alias (mutex_trylock, _lwp_mutex_trylock) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_unlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_unlock.c new file mode 100644 index 0000000000..73e1bd29e0 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/mutex_unlock.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <inline-syscall.h> +#include <pthreadP.h> +#include <synch.h> +#include <errno.h> +#include <synchP.h> + +DECLARE_INLINE_SYSCALL (int, lwp_mutex_unlock, mutex_t *lp); + +int __mutex_unlock_fast (mutex_t *mutex); + + +int mutex_unlock (mutex) + mutex_t *mutex; +{ + /* Handle inconsistent robust mutexes. */ + if ((mutex->mutex_type & LOCK_ROBUST) && + (mutex->mutex_flag & LOCK_NOTRECOVERABLE)) + return ENOTRECOVERABLE; + + /* Always hit the kernel for priority inherit locks. */ + if ((mutex->mutex_type & LOCK_PRIO_INHERIT) == 0) + { + int result = __mutex_unlock_fast (mutex); + if(result >= 0) + return result; + } + else + { + /* Except when we already hold a recursive lock. */ + if ((mutex->mutex_type & LOCK_RECURSIVE) && MUTEX_IS_OWNER (mutex) && + mutex->mutex_rcount > 0) + { + --mutex->mutex_rcount; + return 0; + } + } + + /* The kernel does not clear mutex_owner so we clear it here. */ + mutex->mutex_owner = 0; + + int errval = INLINE_SYSCALL (lwp_mutex_unlock, 1, mutex); + if (errval != 0) + return errval; + + /* The kernel does not clear the lockbyte for priority inherit mutexes. */ + if (mutex->mutex_type & LOCK_PRIO_INHERIT) + mutex->mutex_lockbyte = 0; + + return errval; +} + +weak_alias (mutex_unlock, _lwp_mutex_unlock) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_broadcast.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_broadcast.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_broadcast.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_destroy.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_destroy.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_init.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_init.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_signal.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_signal.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_signal.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_timedwait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_timedwait.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_timedwait.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_wait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_wait.c new file mode 100644 index 0000000000..b4483e95bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/old_pthread_cond_wait.c @@ -0,0 +1 @@ +/* Unimplemented */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pt-fork.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pt-fork.c new file mode 100644 index 0000000000..fb87c6583e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pt-fork.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/pt-fork.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pt-vfork.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pt-vfork.c new file mode 100644 index 0000000000..70b786d12e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pt-vfork.c @@ -0,0 +1 @@ +// TODO diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread.h new file mode 100644 index 0000000000..09c63a095a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread.h @@ -0,0 +1,1113 @@ +/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _PTHREAD_H +#define _PTHREAD_H 1 + +#include <features.h> +#include <endian.h> +#include <sched.h> +#include <time.h> + +#define __need_sigset_t +#include <signal.h> +#include <bits/pthreadtypes.h> +#include <bits/setjmp.h> +#include <bits/wordsize.h> + +/* Detach state. */ +enum +{ + PTHREAD_CREATE_JOINABLE, +#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE + PTHREAD_CREATE_DETACHED +#define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED +}; + + +/* Mutex types. */ +enum +{ + PTHREAD_MUTEX_TIMED_NP = 0x00, + PTHREAD_MUTEX_RECURSIVE_NP = 0x06, /* LOCK_RECURSIVE | LOCK_ERRORCHECK */ + PTHREAD_MUTEX_ERRORCHECK_NP = 0x02, /* LOCK_ERRORCHECK */ + PTHREAD_MUTEX_ADAPTIVE_NP = 0x00 // TODO +#ifdef __USE_UNIX98 + , + PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP, + PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, + PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, + PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL +#endif +#ifdef __USE_GNU + /* For compatibility. */ + , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP +#endif +}; + + +#ifdef __USE_GNU +/* Robust mutex or not flags. */ +enum +{ + PTHREAD_MUTEX_STALLED_NP = 0x00, + PTHREAD_MUTEX_ROBUST_NP = 0x40 /* LOCK_ROBUST */ +}; +#endif + + +#ifdef __USE_UNIX98 +/* Mutex protocols. */ +enum +{ + PTHREAD_PRIO_NONE = 0x00, + PTHREAD_PRIO_INHERIT = 0x10, /* LOCK_PRIO_INHERIT */ + PTHREAD_PRIO_PROTECT = 0x20 /* LOCK_PRIO_PROTECT */ +}; +#endif + + +/* Mutex initializers. */ +#define PTHREAD_MUTEX_INITIALIZER \ + {{0, 0, 0, {PTHREAD_PROCESS_PRIVATE}, 0x4d58 /* MUTEX_MAGIC */ }, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, {0}} +#ifdef __USE_GNU +# define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ + {{0, 0, 0, {PTHREAD_PROCESS_PRIVATE | PTHREAD_MUTEX_RECURSIVE_NP}, \ + 0x4d58 /* MUTEX_MAGIC */}, {{{0, 0, 0, 0, 0, 0, 0, 0}}}, {0}} +# define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ + {{0, 0, 0, {PTHREAD_PROCESS_PRIVATE | PTHREAD_MUTEX_ERRORCHECK_NP}, \ + 0x4d58 /* MUTEX_MAGIC */}, {{{0, 0, 0, 0, 0, 0, 0, 0}}}, {0}} +# define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP // TODO +#endif + + +/* Read-write lock types. */ +#if defined __USE_UNIX98 || defined __USE_XOPEN2K +enum +{ + PTHREAD_RWLOCK_PREFER_READER_NP, + PTHREAD_RWLOCK_PREFER_WRITER_NP, + PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, + PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP +}; +#endif + +/* Read-write lock initializers. */ +#define PTHREAD_RWLOCK_INITIALIZER \ + {0, PTHREAD_PROCESS_PRIVATE, 0x5257 /* RWL_MAGIC */, \ + PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \ + PTHREAD_COND_INITIALIZER, 0, 0, 0} +#ifdef __USE_GNU +# define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ + {0, PTHREAD_PROCESS_PRIVATE | \ + (PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP << 1), \ + 0x5257 /* RWL_MAGIC */, PTHREAD_MUTEX_INITIALIZER, \ + PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0, 0} +#endif /* Unix98 or XOpen2K */ + + +/* Scheduler inheritance. */ +enum +{ + PTHREAD_INHERIT_SCHED = 0x01, +#define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED + PTHREAD_EXPLICIT_SCHED = 0x00 +#define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED +}; + + +/* Scope handling. */ +enum +{ + PTHREAD_SCOPE_SYSTEM = 0x01, /* THR_BOUND */ +#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM + PTHREAD_SCOPE_PROCESS = 0x00 +#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS +}; + + +/* Process shared or private flag. */ +enum +{ + PTHREAD_PROCESS_PRIVATE = 0x00, +#define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE + PTHREAD_PROCESS_SHARED = 0x01 /* LOCK_SHARED */ +#define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED +}; + + + +/* Conditional variable handling. */ +#define PTHREAD_COND_INITIALIZER \ + {{{0, 0, 0, 0}, PTHREAD_PROCESS_PRIVATE, 0x4356 /* COND_MAGIC */}, 0} + + +/* Cleanup buffers */ +struct _pthread_cleanup_buffer +{ + void (*__routine) (void *); /* Function to call. */ + void *__arg; /* Its argument. */ + int __canceltype; /* Saved cancellation type. */ + struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */ +}; + +/* Cancellation */ +enum +{ + PTHREAD_CANCEL_ENABLE = 0x00, +#define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE + PTHREAD_CANCEL_DISABLE = 0x01 +#define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE +}; +enum +{ + PTHREAD_CANCEL_DEFERRED = 0x00, +#define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED + PTHREAD_CANCEL_ASYNCHRONOUS = 0x02 +#define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS +}; +#define PTHREAD_CANCELED ((void *) -19) + + +/* Single execution handling. */ +#define PTHREAD_ONCE_INIT 0 + + +#ifdef __USE_XOPEN2K +/* Value returned by 'pthread_barrier_wait' for one of the threads after + the required number of threads have called this function. + -1 is distinct from 0 and all errno constants */ +# define PTHREAD_BARRIER_SERIAL_THREAD -1 +#endif + +#ifdef __USE_MISC +# define PTHREAD_ONCE_KEY_NP (pthread_key_t)(-1) +#endif + + +__BEGIN_DECLS + +/* Create a new thread, starting with execution of START-ROUTINE + getting passed ARG. Creation attributed come from ATTR. The new + handle is stored in *NEWTHREAD. */ +extern int pthread_create (pthread_t *__restrict __newthread, + __const pthread_attr_t *__restrict __attr, + void *(*__start_routine) (void *), + void *__restrict __arg) __THROW __nonnull ((1, 3)); + +/* Terminate calling thread. + + The registered cleanup handlers are called via exception handling + so we cannot mark this function with __THROW.*/ +extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__)); + +/* Make calling thread wait for termination of the thread TH. The + exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN + is not NULL. + + This function is a cancellation point and therefore not marked with + __THROW. */ +extern int pthread_join (pthread_t __th, void **__thread_return); + +#ifdef __USE_GNU +/* Check whether thread TH has terminated. If yes return the status of + the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */ +extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW; + +/* Make calling thread wait for termination of the thread TH, but only + until TIMEOUT. The exit status of the thread is stored in + *THREAD_RETURN, if THREAD_RETURN is not NULL. + + This function is a cancellation point and therefore not marked with + __THROW. */ +extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return, + __const struct timespec *__abstime); +#endif + +/* Indicate that the thread TH is never to be joined with PTHREAD_JOIN. + The resources of TH will therefore be freed immediately when it + terminates, instead of waiting for another thread to perform PTHREAD_JOIN + on it. */ +extern int pthread_detach (pthread_t __th) __THROW; + + +/* Obtain the identifier of the current thread. */ +extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__)); + +/* Compare two thread identifiers. */ +extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __THROW; + + +/* Thread attribute handling. */ + +/* Initialize thread attribute *ATTR with default attributes + (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER, + no user-provided stack). */ +extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1)); + +/* Destroy thread attribute *ATTR. */ +extern int pthread_attr_destroy (pthread_attr_t *__attr) + __THROW __nonnull ((1)); + +/* Get detach state attribute. */ +extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr, + int *__detachstate) + __THROW __nonnull ((1, 2)); + +/* Set detach state attribute. */ +extern int pthread_attr_setdetachstate (pthread_attr_t *__attr, + int __detachstate) + __THROW __nonnull ((1)); + + +/* Get the size of the guard area created for stack overflow protection. */ +extern int pthread_attr_getguardsize (__const pthread_attr_t *__attr, + size_t *__guardsize) + __THROW __nonnull ((1, 2)); + +/* Set the size of the guard area created for stack overflow protection. */ +extern int pthread_attr_setguardsize (pthread_attr_t *__attr, + size_t __guardsize) + __THROW __nonnull ((1)); + + +/* Return in *PARAM the scheduling parameters of *ATTR. */ +extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict + __attr, + struct sched_param *__restrict __param) + __THROW __nonnull ((1, 2)); + +/* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */ +extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr, + __const struct sched_param *__restrict + __param) __THROW __nonnull ((1, 2)); + +/* Return in *POLICY the scheduling policy of *ATTR. */ +extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict + __attr, int *__restrict __policy) + __THROW __nonnull ((1, 2)); + +/* Set scheduling policy in *ATTR according to POLICY. */ +extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy) + __THROW __nonnull ((1)); + +/* Return in *INHERIT the scheduling inheritance mode of *ATTR. */ +extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict + __attr, int *__restrict __inherit) + __THROW __nonnull ((1, 2)); + +/* Set scheduling inheritance mode in *ATTR according to INHERIT. */ +extern int pthread_attr_setinheritsched (pthread_attr_t *__attr, + int __inherit) + __THROW __nonnull ((1)); + + +/* Return in *SCOPE the scheduling contention scope of *ATTR. */ +extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr, + int *__restrict __scope) + __THROW __nonnull ((1, 2)); + +/* Set scheduling contention scope in *ATTR according to SCOPE. */ +extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope) + __THROW __nonnull ((1)); + +/* Return the previously set address for the stack. */ +extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict + __attr, void **__restrict __stackaddr) + __THROW __nonnull ((1, 2)) __attribute_deprecated__; + +/* Set the starting address of the stack of the thread to be created. + Depending on whether the stack grows up or down the value must either + be higher or lower than all the address in the memory block. The + minimal size of the block must be PTHREAD_STACK_MIN. */ +extern int pthread_attr_setstackaddr (pthread_attr_t *__attr, + void *__stackaddr) + __THROW __nonnull ((1)) __attribute_deprecated__; + +/* Return the currently used minimal stack size. */ +extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict + __attr, size_t *__restrict __stacksize) + __THROW __nonnull ((1, 2)); + +/* Add information about the minimum stack size needed for the thread + to be started. This size must never be less than PTHREAD_STACK_MIN + and must also not exceed the system limits. */ +extern int pthread_attr_setstacksize (pthread_attr_t *__attr, + size_t __stacksize) + __THROW __nonnull ((1)); + +#ifdef __USE_XOPEN2K +/* Return the previously set address for the stack. */ +extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr, + void **__restrict __stackaddr, + size_t *__restrict __stacksize) + __THROW __nonnull ((1, 2, 3)); + +/* The following two interfaces are intended to replace the last two. They + require setting the address as well as the size since only setting the + address will make the implementation on some architectures impossible. */ +extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, + size_t __stacksize) __THROW __nonnull ((1)); +#endif + +#ifdef __USE_GNU +/* Thread created with attribute ATTR will be limited to run only on + the processors represented in CPUSET. */ +extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr, + size_t __cpusetsize, + __const cpu_set_t *__cpuset) + __THROW __nonnull ((1, 3)); + +/* Get bit set in CPUSET representing the processors threads created with + ATTR can run on. */ +extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr, + size_t __cpusetsize, + cpu_set_t *__cpuset) + __THROW __nonnull ((1, 3)); + + +/* Initialize thread attribute *ATTR with attributes corresponding to the + already running thread TH. It shall be called on unitialized ATTR + and destroyed with pthread_attr_destroy when no longer needed. */ +extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) + __THROW __nonnull ((2)); +#endif + + +/* Functions for scheduling control. */ + +/* Set the scheduling parameters for TARGET_THREAD according to POLICY + and *PARAM. */ +extern int pthread_setschedparam (pthread_t __target_thread, int __policy, + __const struct sched_param *__param) + __THROW __nonnull ((3)); + +/* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */ +extern int pthread_getschedparam (pthread_t __target_thread, + int *__restrict __policy, + struct sched_param *__restrict __param) + __THROW __nonnull ((2, 3)); + +/* Set the scheduling priority for TARGET_THREAD. */ +extern int pthread_setschedprio (pthread_t __target_thread, int __prio) + __THROW; + + +#ifdef __USE_UNIX98 +/* Determine level of concurrency. */ +extern int pthread_getconcurrency (void) __THROW; + +/* Set new concurrency level to LEVEL. */ +extern int pthread_setconcurrency (int __level) __THROW; +#endif + +#ifdef __USE_GNU +/* Yield the processor to another thread or process. + This function is similar to the POSIX `sched_yield' function but + might be differently implemented in the case of a m-on-n thread + implementation. */ +extern int pthread_yield (void) __THROW; + + +/* Limit specified thread TH to run only on the processors represented + in CPUSET. */ +extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize, + __const cpu_set_t *__cpuset) + __THROW __nonnull ((3)); + +/* Get bit set in CPUSET representing the processors TH can run on. */ +extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize, + cpu_set_t *__cpuset) + __THROW __nonnull ((3)); +#endif + + +/* Functions for handling initialization. */ + +/* Guarantee that the initialization function INIT_ROUTINE will be called + only once, even if pthread_once is executed several times with the + same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or + extern variable initialized to PTHREAD_ONCE_INIT. + + The initialization functions might throw exception which is why + this function is not marked with __THROW. */ +extern int pthread_once (pthread_once_t *__once_control, + void (*__init_routine) (void)) __nonnull ((1, 2)); + + +/* Functions for handling cancellation. + + Note that these functions are explicitly not marked to not throw an + exception in C++ code. If cancellation is implemented by unwinding + this is necessary to have the compiler generate the unwind information. */ + +/* Set cancelability state of current thread to STATE, returning old + state in *OLDSTATE if OLDSTATE is not NULL. */ +extern int pthread_setcancelstate (int __state, int *__oldstate); + +/* Set cancellation state of current thread to TYPE, returning the old + type in *OLDTYPE if OLDTYPE is not NULL. */ +extern int pthread_setcanceltype (int __type, int *__oldtype); + +/* Cancel THREAD immediately or at the next possibility. */ +extern int pthread_cancel (pthread_t __th); + +/* Test for pending cancellation for the current thread and terminate + the thread as per pthread_exit(PTHREAD_CANCELED) if it has been + cancelled. */ +extern void pthread_testcancel (void); + + +/* Cancellation handling with integration into exception handling. */ + +typedef struct +{ + struct + { + __jmp_buf __cancel_jmp_buf; + int __mask_was_saved; + } __cancel_jmp_buf[1]; + void *__pad[4]; +} __pthread_unwind_buf_t __attribute__ ((__aligned__)); + +/* No special attributes by default. */ +#ifndef __cleanup_fct_attribute +# define __cleanup_fct_attribute +#endif + + +/* Structure to hold the cleanup handler information. */ +struct __pthread_cleanup_frame +{ + void (*__cancel_routine) (void *); + void *__cancel_arg; + int __do_it; + int __cancel_type; +}; + +#if defined __GNUC__ && defined __EXCEPTIONS +# ifdef __cplusplus +/* Class to handle cancellation handler invocation. */ +class __pthread_cleanup_class +{ + void (*__cancel_routine) (void *); + void *__cancel_arg; + int __do_it; + int __cancel_type; + + public: + __pthread_cleanup_class (void (*__fct) (void *), void *__arg) + : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { } + ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); } + void __setdoit (int __newval) { __do_it = __newval; } + void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, + &__cancel_type); } + void __restore () const { pthread_setcanceltype (__cancel_type, 0); } +}; + +/* Install a cleanup handler: ROUTINE will be called with arguments ARG + when the thread is canceled or calls pthread_exit. ROUTINE will also + be called with arguments ARG when the matching pthread_cleanup_pop + is executed with non-zero EXECUTE argument. + + pthread_cleanup_push and pthread_cleanup_pop are macros and must always + be used in matching pairs at the same nesting level of braces. */ +# define pthread_cleanup_push(routine, arg) \ + do { \ + __pthread_cleanup_class __clframe (routine, arg) + +/* Remove a cleanup handler installed by the matching pthread_cleanup_push. + If EXECUTE is non-zero, the handler function is called. */ +# define pthread_cleanup_pop(execute) \ + __clframe.__setdoit (execute); \ + } while (0) + +# ifdef __USE_GNU +/* Install a cleanup handler as pthread_cleanup_push does, but also + saves the current cancellation type and sets it to deferred + cancellation. */ +# define pthread_cleanup_push_defer_np(routine, arg) \ + do { \ + __pthread_cleanup_class __clframe (routine, arg); \ + __clframe.__defer () + +/* Remove a cleanup handler as pthread_cleanup_pop does, but also + restores the cancellation type that was in effect when the matching + pthread_cleanup_push_defer was called. */ +# define pthread_cleanup_pop_restore_np(execute) \ + __clframe.__restore (); \ + __clframe.__setdoit (execute); \ + } while (0) +# endif +# else +/* Function called to call the cleanup handler. As an extern inline + function the compiler is free to decide inlining the change when + needed or fall back on the copy which must exist somewhere + else. */ +__extern_inline void +__pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) +{ + if (__frame->__do_it) + __frame->__cancel_routine (__frame->__cancel_arg); +} + +/* Install a cleanup handler: ROUTINE will be called with arguments ARG + when the thread is canceled or calls pthread_exit. ROUTINE will also + be called with arguments ARG when the matching pthread_cleanup_pop + is executed with non-zero EXECUTE argument. + + pthread_cleanup_push and pthread_cleanup_pop are macros and must always + be used in matching pairs at the same nesting level of braces. */ +# define pthread_cleanup_push(routine, arg) \ + do { \ + struct __pthread_cleanup_frame __clframe \ + __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ + = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ + .__do_it = 1 }; + +/* Remove a cleanup handler installed by the matching pthread_cleanup_push. + If EXECUTE is non-zero, the handler function is called. */ +# define pthread_cleanup_pop(execute) \ + __clframe.__do_it = (execute); \ + } while (0) + +# ifdef __USE_GNU +/* Install a cleanup handler as pthread_cleanup_push does, but also + saves the current cancellation type and sets it to deferred + cancellation. */ +# define pthread_cleanup_push_defer_np(routine, arg) \ + do { \ + struct __pthread_cleanup_frame __clframe \ + __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ + = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ + .__do_it = 1 }; \ + (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \ + &__clframe.__cancel_type) + +/* Remove a cleanup handler as pthread_cleanup_pop does, but also + restores the cancellation type that was in effect when the matching + pthread_cleanup_push_defer was called. */ +# define pthread_cleanup_pop_restore_np(execute) \ + (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \ + __clframe.__do_it = (execute); \ + } while (0) +# endif +# endif +#else +/* Install a cleanup handler: ROUTINE will be called with arguments ARG + when the thread is canceled or calls pthread_exit. ROUTINE will also + be called with arguments ARG when the matching pthread_cleanup_pop + is executed with non-zero EXECUTE argument. + + pthread_cleanup_push and pthread_cleanup_pop are macros and must always + be used in matching pairs at the same nesting level of braces. */ +# define pthread_cleanup_push(routine, arg) \ + do { \ + __pthread_unwind_buf_t __cancel_buf; \ + void (*__cancel_routine) (void *) = (routine); \ + void *__cancel_arg = (arg); \ + int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \ + __cancel_buf.__cancel_jmp_buf, 0); \ + if (__builtin_expect (not_first_call, 0)) \ + { \ + __cancel_routine (__cancel_arg); \ + __pthread_unwind_next (&__cancel_buf); \ + /* NOTREACHED */ \ + } \ + \ + __pthread_register_cancel (&__cancel_buf); \ + do { +extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) + __cleanup_fct_attribute; + +/* Remove a cleanup handler installed by the matching pthread_cleanup_push. + If EXECUTE is non-zero, the handler function is called. */ +# define pthread_cleanup_pop(execute) \ + } while (0); \ + __pthread_unregister_cancel (&__cancel_buf); \ + if (execute) \ + __cancel_routine (__cancel_arg); \ + } while (0) +extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) + __cleanup_fct_attribute; + +# ifdef __USE_GNU +/* Install a cleanup handler as pthread_cleanup_push does, but also + saves the current cancellation type and sets it to deferred + cancellation. */ +# define pthread_cleanup_push_defer_np(routine, arg) \ + do { \ + __pthread_unwind_buf_t __cancel_buf; \ + void (*__cancel_routine) (void *) = (routine); \ + void *__cancel_arg = (arg); \ + int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) \ + __cancel_buf.__cancel_jmp_buf, 0); \ + if (__builtin_expect (not_first_call, 0)) \ + { \ + __cancel_routine (__cancel_arg); \ + __pthread_unwind_next (&__cancel_buf); \ + /* NOTREACHED */ \ + } \ + \ + __pthread_register_cancel_defer (&__cancel_buf); \ + do { +extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf) + __cleanup_fct_attribute; + +/* Remove a cleanup handler as pthread_cleanup_pop does, but also + restores the cancellation type that was in effect when the matching + pthread_cleanup_push_defer was called. */ +# define pthread_cleanup_pop_restore_np(execute) \ + } while (0); \ + __pthread_unregister_cancel_restore (&__cancel_buf); \ + if (execute) \ + __cancel_routine (__cancel_arg); \ + } while (0) +extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf) + __cleanup_fct_attribute; +# endif + +/* Internal interface to initiate cleanup. */ +extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) + __cleanup_fct_attribute __attribute__ ((__noreturn__)) +# ifndef SHARED + __attribute__ ((__weak__)) +# endif + ; +#endif + +/* Function used in the macros. */ +struct __jmp_buf_tag; +extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW; + + +/* Mutex handling. */ + +/* Initialize a mutex. */ +extern int pthread_mutex_init (pthread_mutex_t *__mutex, + __const pthread_mutexattr_t *__mutexattr) + __THROW __nonnull ((1)); + +/* Destroy a mutex. */ +extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) + __THROW __nonnull ((1)); + +/* Try locking a mutex. */ +extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) + __THROW __nonnull ((1)); + +/* Lock a mutex. */ +extern int pthread_mutex_lock (pthread_mutex_t *__mutex) + __THROW __nonnull ((1)); + +#ifdef __USE_XOPEN2K +/* Wait until lock becomes available, or specified time passes. */ +extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, + __const struct timespec *__restrict + __abstime) __THROW __nonnull ((1, 2)); +#endif +extern int pthread_mutex_reltimedlock_np (pthread_mutex_t *__restrict __mutex, + __const struct timespec *__restrict + __reltime) __THROW __nonnull ((1, 2)); + +/* Unlock a mutex. */ +extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) + __THROW __nonnull ((1)); + + +#ifdef __USE_UNIX98 +/* Get the priority ceiling of MUTEX. */ +extern int pthread_mutex_getprioceiling (__const pthread_mutex_t * + __restrict __mutex, + int *__restrict __prioceiling) + __THROW __nonnull ((1, 2)); + +/* Set the priority ceiling of MUTEX to PRIOCEILING, return old + priority ceiling value in *OLD_CEILING. */ +extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex, + int __prioceiling, + int *__restrict __old_ceiling) + __THROW __nonnull ((1, 3)); +#endif + + +#ifdef __USE_GNU +/* Declare the state protected by MUTEX as consistent. */ +extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex) + __THROW __nonnull ((1)); +#endif + + +/* Functions for handling mutex attributes. */ + +/* Initialize mutex attribute object ATTR with default attributes + (kind is PTHREAD_MUTEX_TIMED_NP). */ +extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) + __THROW __nonnull ((1)); + +/* Destroy mutex attribute object ATTR. */ +extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) + __THROW __nonnull ((1)); + +/* Get the process-shared flag of the mutex attribute ATTR. */ +extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t * + __restrict __attr, + int *__restrict __pshared) + __THROW __nonnull ((1, 2)); + +/* Set the process-shared flag of the mutex attribute ATTR. */ +extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr, + int __pshared) + __THROW __nonnull ((1)); + +#ifdef __USE_UNIX98 +/* Return in *KIND the mutex kind attribute in *ATTR. */ +extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict + __attr, int *__restrict __kind) + __THROW __nonnull ((1, 2)); + +/* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL, + PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or + PTHREAD_MUTEX_DEFAULT). */ +extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) + __THROW __nonnull ((1)); + +/* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */ +extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t * + __restrict __attr, + int *__restrict __protocol) + __THROW __nonnull ((1, 2)); + +/* Set the mutex protocol attribute in *ATTR to PROTOCOL (either + PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */ +extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, + int __protocol) + __THROW __nonnull ((1)); + +/* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */ +extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t * + __restrict __attr, + int *__restrict __prioceiling) + __THROW __nonnull ((1, 2)); + +/* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */ +extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr, + int __prioceiling) + __THROW __nonnull ((1)); +#endif + +#ifdef __USE_GNU +/* Get the robustness flag of the mutex attribute ATTR. */ +extern int pthread_mutexattr_getrobust_np (__const pthread_mutexattr_t *__attr, + int *__robustness) + __THROW __nonnull ((1, 2)); + +/* Set the robustness flag of the mutex attribute ATTR. */ +extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr, + int __robustness) + __THROW __nonnull ((1)); +#endif + + +#if defined __USE_UNIX98 || defined __USE_XOPEN2K +/* Functions for handling read-write locks. */ + +/* Initialize read-write lock RWLOCK using attributes ATTR, or use + the default values if later is NULL. */ +extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, + __const pthread_rwlockattr_t *__restrict + __attr) __THROW __nonnull ((1)); + +/* Destroy read-write lock RWLOCK. */ +extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) + __THROW __nonnull ((1)); + +/* Acquire read lock for RWLOCK. */ +extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) + __THROW __nonnull ((1)); + +/* Try to acquire read lock for RWLOCK. */ +extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) + __THROW __nonnull ((1)); + +# ifdef __USE_XOPEN2K +/* Try to acquire read lock for RWLOCK or return after specfied time. */ +extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, + __const struct timespec *__restrict + __abstime) __THROW __nonnull ((1, 2)); +# endif + +/* Acquire write lock for RWLOCK. */ +extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) + __THROW __nonnull ((1)); + +/* Try to acquire write lock for RWLOCK. */ +extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) + __THROW __nonnull ((1)); + +# ifdef __USE_XOPEN2K +/* Try to acquire write lock for RWLOCK or return after specfied time. */ +extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, + __const struct timespec *__restrict + __abstime) __THROW __nonnull ((1, 2)); +# endif + +/* Unlock RWLOCK. */ +extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) + __THROW __nonnull ((1)); + + +/* Functions for handling read-write lock attributes. */ + +/* Initialize attribute object ATTR with default values. */ +extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) + __THROW __nonnull ((1)); + +/* Destroy attribute object ATTR. */ +extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) + __THROW __nonnull ((1)); + +/* Return current setting of process-shared attribute of ATTR in PSHARED. */ +extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t * + __restrict __attr, + int *__restrict __pshared) + __THROW __nonnull ((1, 2)); + +/* Set process-shared attribute of ATTR to PSHARED. */ +extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr, + int __pshared) + __THROW __nonnull ((1)); + +/* Return current setting of reader/writer preference. */ +extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t * + __restrict __attr, + int *__restrict __pref) + __THROW __nonnull ((1, 2)); + +/* Set reader/write preference. */ +extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, + int __pref) __THROW __nonnull ((1)); +#endif + + +/* Functions for handling conditional variables. */ + +/* Initialize condition variable COND using attributes ATTR, or use + the default values if later is NULL. */ +extern int pthread_cond_init (pthread_cond_t *__restrict __cond, + __const pthread_condattr_t *__restrict + __cond_attr) __THROW __nonnull ((1)); + +/* Destroy condition variable COND. */ +extern int pthread_cond_destroy (pthread_cond_t *__cond) + __THROW __nonnull ((1)); + +/* Wake up one thread waiting for condition variable COND. */ +extern int pthread_cond_signal (pthread_cond_t *__cond) + __THROW __nonnull ((1)); + +/* Wake up all threads waiting for condition variables COND. */ +extern int pthread_cond_broadcast (pthread_cond_t *__cond) + __THROW __nonnull ((1)); + +/* Wait for condition variable COND to be signaled or broadcast. + MUTEX is assumed to be locked before. + + This function is a cancellation point and therefore not marked with + __THROW. */ +extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex) + __nonnull ((1, 2)); + +/* Wait for condition variable COND to be signaled or broadcast until + ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an + absolute time specification; zero is the beginning of the epoch + (00:00:00 GMT, January 1, 1970). + + This function is a cancellation point and therefore not marked with + __THROW. */ +extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex, + __const struct timespec *__restrict + __abstime) __nonnull ((1, 2, 3)); + +extern int pthread_cond_reltimedwait_np (pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex, + __const struct timespec *__restrict + __reltime) __nonnull ((1, 2, 3)); + +/* Functions for handling condition variable attributes. */ + +/* Initialize condition variable attribute ATTR. */ +extern int pthread_condattr_init (pthread_condattr_t *__attr) + __THROW __nonnull ((1)); + +/* Destroy condition variable attribute ATTR. */ +extern int pthread_condattr_destroy (pthread_condattr_t *__attr) + __THROW __nonnull ((1)); + +/* Get the process-shared flag of the condition variable attribute ATTR. */ +extern int pthread_condattr_getpshared (__const pthread_condattr_t * + __restrict __attr, + int *__restrict __pshared) + __THROW __nonnull ((1, 2)); + +/* Set the process-shared flag of the condition variable attribute ATTR. */ +extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, + int __pshared) __THROW __nonnull ((1)); + +#ifdef __USE_XOPEN2K +/* Get the clock selected for the conditon variable attribute ATTR. */ +extern int pthread_condattr_getclock (__const pthread_condattr_t * + __restrict __attr, + __clockid_t *__restrict __clock_id) + __THROW __nonnull ((1, 2)); + +/* Set the clock selected for the conditon variable attribute ATTR. */ +extern int pthread_condattr_setclock (pthread_condattr_t *__attr, + __clockid_t __clock_id) + __THROW __nonnull ((1)); +#endif + + +#ifdef __USE_XOPEN2K +/* Functions to handle spinlocks. */ + +/* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can + be shared between different processes. */ +extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) + __THROW __nonnull ((1)); + +/* Destroy the spinlock LOCK. */ +extern int pthread_spin_destroy (pthread_spinlock_t *__lock) + __THROW __nonnull ((1)); + +/* Wait until spinlock LOCK is retrieved. */ +extern int pthread_spin_lock (pthread_spinlock_t *__lock) + __THROW __nonnull ((1)); + +/* Try to lock spinlock LOCK. */ +extern int pthread_spin_trylock (pthread_spinlock_t *__lock) + __THROW __nonnull ((1)); + +/* Release spinlock LOCK. */ +extern int pthread_spin_unlock (pthread_spinlock_t *__lock) + __THROW __nonnull ((1)); + + +/* Functions to handle barriers. */ + +/* Initialize BARRIER with the attributes in ATTR. The barrier is + opened when COUNT waiters arrived. */ +extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier, + __const pthread_barrierattr_t *__restrict + __attr, unsigned int __count) + __THROW __nonnull ((1)); + +/* Destroy a previously dynamically initialized barrier BARRIER. */ +extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) + __THROW __nonnull ((1)); + +/* Wait on barrier BARRIER. */ +extern int pthread_barrier_wait (pthread_barrier_t *__barrier) + __THROW __nonnull ((1)); + + +/* Initialize barrier attribute ATTR. */ +extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) + __THROW __nonnull ((1)); + +/* Destroy previously dynamically initialized barrier attribute ATTR. */ +extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) + __THROW __nonnull ((1)); + +/* Get the process-shared flag of the barrier attribute ATTR. */ +extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t * + __restrict __attr, + int *__restrict __pshared) + __THROW __nonnull ((1, 2)); + +/* Set the process-shared flag of the barrier attribute ATTR. */ +extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, + int __pshared) + __THROW __nonnull ((1)); +#endif + + +/* Functions for handling thread-specific data. */ + +/* Create a key value identifying a location in the thread-specific + data area. Each thread maintains a distinct thread-specific data + area. DESTR_FUNCTION, if non-NULL, is called with the value + associated to that key when the key is destroyed. + DESTR_FUNCTION is not called if the value associated is NULL when + the key is destroyed. */ +extern int pthread_key_create (pthread_key_t *__key, + void (*__destr_function) (void *)) + __THROW __nonnull ((1)); + +/* Destroy KEY. */ +extern int pthread_key_delete (pthread_key_t __key) __THROW; + +/* Return current value of the thread-specific data slot identified by KEY. */ +extern void *pthread_getspecific (pthread_key_t __key) __THROW; + +/* Store POINTER in the thread-specific data slot identified by KEY. */ +extern int pthread_setspecific (pthread_key_t __key, + __const void *__pointer) __THROW ; + + +#ifdef __USE_XOPEN2K +/* Get ID of CPU-time clock for thread THREAD_ID. */ +extern int pthread_getcpuclockid (pthread_t __thread_id, + __clockid_t *__clock_id) + __THROW __nonnull ((2)); +#endif + + +/* Install handlers to be called when a new process is created with FORK. + The PREPARE handler is called in the parent process just before performing + FORK. The PARENT handler is called in the parent process just after FORK. + The CHILD handler is called in the child process. Each of the three + handlers can be NULL, meaning that no handler needs to be called at that + point. + PTHREAD_ATFORK can be called several times, in which case the PREPARE + handlers are called in LIFO order (last added with PTHREAD_ATFORK, + first called before FORK), and the PARENT and CHILD handlers are called + in FIFO (first added, first called). */ + +extern int pthread_atfork (void (*__prepare) (void), + void (*__parent) (void), + void (*__child) (void)) __THROW; + + +#ifdef __USE_EXTERN_INLINES +/* Optimizations. */ +__extern_inline int +__NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2)) +{ + return __thread1 == __thread2; +} +#endif + +__END_DECLS + +#endif /* pthread.h */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreadP.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreadP.h new file mode 100644 index 0000000000..8b7e210615 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreadP.h @@ -0,0 +1,225 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _OPENSOLARIS_PTHREADP_H +#define _OPENSOLARIS_PTHREADP_H + +/* rwlock macros. */ +#define _RWLOCK_WR_LOCK 0x80000000 +#define _RWLOCK_RD_MASK 0x7FFFFFFF +#define _RWLOCK_RD_MAX 0x7FFFFFFF + +#include <nptl/pthreadP.h> +#include <sys/synch.h> + +/* Flags in mutex attr. */ +#undef PTHREAD_MUTEXATTR_PROTOCOL_SHIFT +#define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT 0 +#undef PTHREAD_MUTEXATTR_PROTOCOL_MASK +#define PTHREAD_MUTEXATTR_PROTOCOL_MASK \ + (PTHREAD_PRIO_INHERIT | PTHREAD_PRIO_PROTECT) +#undef PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT +#define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT 12 +#undef PTHREAD_MUTEXATTR_PRIO_CEILING_MASK +#define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK 0x0ffff000 +#undef PTHREAD_MUTEXATTR_FLAG_ROBUST +#define PTHREAD_MUTEXATTR_FLAG_ROBUST LOCK_ROBUST +#undef PTHREAD_MUTEXATTR_FLAG_PSHARED +#define PTHREAD_MUTEXATTR_FLAG_PSHARED LOCK_SHARED +#undef PTHREAD_MUTEXATTR_FLAG_BITS +#define PTHREAD_MUTEXATTR_FLAG_BITS \ + (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \ + | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) + +#define PTHREAD_RWLOCK_TYPE_MASK 0x00000006 +#define PTHREAD_RWLOCK_TYPE_SHIFT 1 +#undef PTHREAD_RWLOCK_PREFER_READER_P +#define PTHREAD_RWLOCK_PREFER_READER_P(rwlock) \ + (((rwlock->type >> PTHREAD_RWLOCK_TYPE_SHIFT) & \ + PTHREAD_RWLOCK_TYPE_MASK) != PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP) + +#define MUTEX_IS_OWNER(mutex) \ + (mutex->mutex_lockbyte == LOCKBYTE_SET && \ + (((mutex)->mutex_type & LOCK_SHARED) == 0 || \ + (mutex)->mutex_ownerpid == THREAD_GETMEM (THREAD_SELF, pid)) && \ + ((mutex)->mutex_owner == THREAD_GETMEM (THREAD_SELF, tid))) + +#define MUTEX_NOT_OWNER(mutex) (! MUTEX_IS_OWNER (mutex)) + +#include <time.h> + +#define PAST_TIMESPEC(tv) ((tv) && (tv)->tv_sec < 0) +#define INVALID_TIMESPEC(tv) ((tv) && ((tv)->tv_nsec < 0 || \ + (tv)->tv_nsec >= 1000000000)) +#define COPY_TIMESPEC(tv) \ + struct timespec *__##tv = NULL, _##tv; \ + if (tv) \ + { \ + _##tv = *tv; \ + __##tv = &_##tv; \ + } + +#include <sys/types.h> +#include <sys/syscall.h> +#include <signal.h> +#include <unistd.h> +#include <errno.h> +#include <inline-syscall.h> +#include <synchP.h> +#include <synch.h> +#include <schedP.h> + +/* These are the result of the macro expansion of INTERNAL_SYSCALL. */ + +/* XXX: These are really gross and should die. */ + +static inline int __internal_kill_1 (int *errval, int sig) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_kill, sig); + return ret.sys_rval1; +} + +static inline int __internal_tdetach_1 (int *errval, pthread_t tid) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_lwp_detach, tid); + return ret.sys_rval1; +} + +static inline pthread_t __internal_set_tid_address_1 (int *errval, pthread_t *tid) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_lwp_self); + return *tid = ret.sys_rval1; +} + +static inline int __internal_rt_sigprocmask_4 (int *errval, int how, + const sigset_t *set, sigset_t *oldset, int setsize) +{ + int saved_errno = errno; + int result = sigprocmask (how, set, oldset); + if (result != 0) + *errval = errno; + __set_errno (saved_errno); + return result; +} + +static inline int __internal_write_3 (int *errval, int fd, const void *buf, + size_t count) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_write, fd, buf, count); + return ret.sys_rval1; +} + +static inline int __internal_tkill_2 (int *errval, pthread_t tid, int sig) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_lwp_kill, tid, sig); + return ret.sys_rval1; +} + +static inline int __internal_pause_1 (int *errval, int unused) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_pause); + return ret.sys_rval1; +} + +static inline int __internal_nanosleep_2 (int *errval, + const struct timespec *req, struct timespec *rem) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_nanosleep, req, rem); + return ret.sys_rval1; +} + +static inline int __internal_sched_get_priority_min_1 (int *errval, int policy) +{ + int saved_errno = errno; + int result = sched_get_priority_min (policy); + if (result != 0) + *errval = errno; + __set_errno (saved_errno); + return result; +} + +static inline int __internal_sched_get_priority_max_1 (int *errval, int policy) +{ + int saved_errno = errno; + int result = sched_get_priority_max (policy); + if (result != 0) + *errval = errno; + __set_errno (saved_errno); + return result; +} + +static inline int __internal_munmap_2 (int *errval, void *start, size_t length) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_munmap, start, length); + return ret.sys_rval1; +} + +static inline int __internal_close_1 (int *errval, int fd) +{ + sysret_t ret; + *errval = __systemcall (&ret, SYS_close, fd); + return ret.sys_rval1; +} + +/* These are used by the "real" associated functions. */ + +static inline int __pthread_setschedparam_internal (pthread_t threadid, + int policy, const struct sched_param *param) +{ + return __sched_setscheduler_id (P_LWPID, threadid, policy, + param->__sched_priority); +} + +static inline int __pthread_setschedprio_internal (pthread_t threadid, + int prio) +{ + return __sched_setparam_id (P_LWPID, threadid, prio); +} + +static inline int __pthread_getschedparam_internal (pthread_t threadid, + int *policy, struct sched_param *param) +{ + return __sched_getscheduler_id (P_LWPID, threadid, policy, + ¶m->__sched_priority); +} + +static inline int __cond_has_waiters (cond_t *cond) +{ + return cond->cond_waiters_kernel; +} + +/* These functions are used to implement the "real" associated functions. */ +extern int __cond_reltimedwait_internal (cond_t *cond, mutex_t *mutex, + struct timespec *reltime, int cancel); +extern int __mutex_reltimedlock (mutex_t *mutex, + const struct timespec *reltime); +extern int __mutex_timedlock (mutex_t *mutex, const struct timespec *abstime); +extern int __rw_timedrdlock (rwlock_t *rwlock, struct timespec *abstime); +extern int __rw_timedwrlock (rwlock_t *rwlock, struct timespec *abstime); +extern int __sema_timedwait (sema_t *sem, struct timespec *abstime); + +#endif /* _OPENSOLARIS_PTHREADP_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_attr_getaffinity.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_attr_getaffinity.c new file mode 100644 index 0000000000..13fce36aca --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_attr_getaffinity.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2003, 2004, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +__pthread_attr_getaffinity_new (const pthread_attr_t *attr, size_t cpusetsize, + cpu_set_t *cpuset) +{ + return ENOSYS; +} +weak_alias (__pthread_attr_getaffinity_new, pthread_attr_getaffinity_np) + +stub_warning (pthread_attr_getaffinity_np) +#include <stub-tag.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_attr_setaffinity.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_attr_setaffinity.c new file mode 100644 index 0000000000..7479a0b616 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_attr_setaffinity.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2003, 2004, 2006, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +__pthread_attr_setaffinity_new (pthread_attr_t *attr, size_t cpusetsize, + const cpu_set_t *cpuset) +{ + return ENOSYS; +} +weak_alias (__pthread_attr_setaffinity_new, pthread_attr_setaffinity_np); + +stub_warning (pthread_attr_setaffinity_np) +#include <stub-tag.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_destroy.c new file mode 100644 index 0000000000..6ef6bdeb49 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_destroy.c @@ -0,0 +1,51 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <stdio.h> + + +int +pthread_barrier_destroy (barrier) + pthread_barrier_t *barrier; +{ + struct pthread_barrier *ibarrier = (struct pthread_barrier *) barrier; + + int errval = __pthread_mutex_lock (&ibarrier->mutex); + if (errval != 0) + return EINVAL; + + /* Make sure barrier is not exiting. */ + while (errval == 0 && (ibarrier->flag & BARRIER_EXITING)) + { + errval = __cond_reltimedwait_internal ((cond_t *)&ibarrier->cond, + (mutex_t *)&ibarrier->mutex, NULL, 0); + if (errval == EINTR) + errval = 0; + } + + if (__builtin_expect (ibarrier->left != ibarrier->init_count, 0)) + errval = EBUSY; + + (void)__pthread_mutex_unlock (&ibarrier->mutex); + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_init.c new file mode 100644 index 0000000000..2169f32309 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_init.c @@ -0,0 +1,69 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <string.h> +#include <sys/synch.h> +#include <synchP.h> + + +static const struct pthread_barrierattr default_attr = + { + .pshared = PTHREAD_PROCESS_PRIVATE + }; + + +int +pthread_barrier_init (barrier, attr, count) + pthread_barrier_t *barrier; + const pthread_barrierattr_t *attr; + unsigned int count; +{ + struct pthread_barrier *ibarrier; + + if (__builtin_expect (count == 0, 0)) + return EINVAL; + + const struct pthread_barrierattr *iattr + = (attr != NULL + ? iattr = (struct pthread_barrierattr *) attr + : &default_attr); + + if (iattr->pshared != PTHREAD_PROCESS_PRIVATE + && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0)) + /* Invalid attribute. */ + return EINVAL; + + ibarrier = (struct pthread_barrier *) barrier; + + /* Initialize the individual fields. */ + memset (ibarrier, 0, sizeof(struct pthread_barrier)); + ibarrier->mutex.mutex_type = iattr->pshared; + ibarrier->mutex.mutex_flag = LOCK_INITED; + ibarrier->mutex.mutex_magic = MUTEX_MAGIC; + ibarrier->cond.cond_type = iattr->pshared; + ibarrier->cond.cond_magic = COND_MAGIC; + ibarrier->left = count; + ibarrier->init_count = count; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_wait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_wait.c new file mode 100644 index 0000000000..58a4565599 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_barrier_wait.c @@ -0,0 +1,92 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <stdio.h> +#include <not-cancel.h> + + +/* Wait on barrier. */ +int +pthread_barrier_wait (barrier) + pthread_barrier_t *barrier; +{ + struct pthread_barrier *ibarrier = (struct pthread_barrier *) barrier; + + int errval = __pthread_mutex_lock (&ibarrier->mutex); + if (errval != 0) + return errval; + + /* Make sure barrier is not exiting. */ + while (ibarrier->flag & BARRIER_EXITING) + { + errval = __cond_reltimedwait_internal ((cond_t *)&ibarrier->cond, + (mutex_t *)&ibarrier->mutex, NULL, 0); + if (errval != EINTR && errval != 0) + { + (void)__pthread_mutex_unlock (&ibarrier->mutex); + return errval; + } + } + + /* A thread entered the barrier. */ + --ibarrier->left; + + if (ibarrier->left == 0) + { + /* Increment the event counter to avoid invalid wake-ups and tell the + current waiters that it is their turn. Also reset the barrier. */ + ++ibarrier->curr_event; + + ibarrier->flag |= BARRIER_EXITING; + + /* Wake other threads. */ + (void)pthread_cond_broadcast (&ibarrier->cond); + errval = PTHREAD_BARRIER_SERIAL_THREAD; + } + else + { + /* Wait until the current barrier event is done. */ + int curr_event = ibarrier->curr_event; + do + { + errval = __cond_reltimedwait_internal ((cond_t *)&ibarrier->cond, + (mutex_t *)&ibarrier->mutex, NULL, 0); + if (errval != EINTR && errval != 0) + { + (void)__pthread_mutex_unlock (&ibarrier->mutex); + return errval; + } + } + while (curr_event == ibarrier->curr_event); + } + + /* If we are the last thread notify barrier waiters. */ + if (++ibarrier->left == ibarrier->init_count) + { + ibarrier->flag &= ~BARRIER_EXITING; + (void)pthread_cond_broadcast (&ibarrier->cond); + } + + (void)__pthread_mutex_unlock (&ibarrier->mutex); + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_broadcast.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_broadcast.c new file mode 100644 index 0000000000..62ffe0905a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_broadcast.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <shlib-compat.h> + + +int +__pthread_cond_broadcast (cond) + pthread_cond_t *cond; +{ + return cond_broadcast ((cond_t *)cond); +} + +versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast, + GLIBC_2_3_2); diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_destroy.c new file mode 100644 index 0000000000..00bd75e8d0 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_destroy.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <shlib-compat.h> +#include <errno.h> +#include "pthreadP.h" +#include <string.h> + + +int +__pthread_cond_destroy (cond) + pthread_cond_t *cond; +{ + // TODO: make sure we're done with cond (EBUSY) + + cond->cond_magic = -1; + return 0; +} +versioned_symbol (libpthread, __pthread_cond_destroy, + pthread_cond_destroy, GLIBC_2_3_2); diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_init.c new file mode 100644 index 0000000000..ef13cf0fde --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_init.c @@ -0,0 +1,55 @@ +/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + + +#include <shlib-compat.h> +#include <pthreadP.h> +#include <string.h> +#include <sys/synch.h> +#include <synchP.h> + +static const struct pthread_condattr default_attr = + { + .value = 0 + }; + + +int +__pthread_cond_init (cond, cond_attr) + pthread_cond_t *cond; + const pthread_condattr_t *cond_attr; +{ + const struct pthread_condattr *icond_attr; + + icond_attr = (struct pthread_condattr *) cond_attr ?: &default_attr; + + memset (cond, 0, sizeof(pthread_cond_t)); + cond->cond_type = (icond_attr->value & 1) ? + PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE; + cond->cond_magic = COND_MAGIC; + cond->cond_clockid = (((icond_attr->value) >> 1) + & ((1 << COND_NWAITERS_SHIFT) - 1)); + + return 0; +} +versioned_symbol (libpthread, __pthread_cond_init, + pthread_cond_init, GLIBC_2_3_2); diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_reltimedwait_np.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_reltimedwait_np.c new file mode 100644 index 0000000000..0cdb3927b8 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_reltimedwait_np.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int +pthread_cond_reltimedwait_np (cond, mutex, reltime) + pthread_cond_t *cond; + pthread_mutex_t *mutex; + const struct timespec *reltime; +{ + COPY_TIMESPEC (reltime) + int errval = cond_reltimedwait ((cond_t *)cond, (mutex_t *)mutex, __reltime); + if (errval == ETIME) + return ETIMEDOUT; + else if (errval == EINTR) + return 0; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_signal.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_signal.c new file mode 100644 index 0000000000..d5731d8484 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_signal.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <shlib-compat.h> + + +int +__pthread_cond_signal (cond) + pthread_cond_t *cond; +{ + return cond_signal ((cond_t *)cond); +} + +versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal, + GLIBC_2_3_2); diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_timedwait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_timedwait.c new file mode 100644 index 0000000000..3836d6f1f8 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_timedwait.c @@ -0,0 +1,48 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <shlib-compat.h> +#include <abstime-to-reltime.h> + +int +__pthread_cond_timedwait (cond, mutex, abstime) + pthread_cond_t *cond; + pthread_mutex_t *mutex; + const struct timespec *abstime; +{ + /* Reject invalid timeouts. */ + if (INVALID_TIMESPEC (abstime)) + return EINVAL; + + struct timespec _reltime; + struct timespec *reltime = abstime_to_reltime (abstime, &_reltime); + int errval = cond_reltimedwait ((cond_t *)cond, (mutex_t *)mutex, reltime); + if (errval == ETIME) + return ETIMEDOUT; + else if (errval == EINTR) + return 0; + return errval; +} + +versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait, + GLIBC_2_3_2); diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_wait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_wait.c new file mode 100644 index 0000000000..9cd3cf267b --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_cond_wait.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <shlib-compat.h> + + +int +__pthread_cond_wait (cond, mutex) + pthread_cond_t *cond; + pthread_mutex_t *mutex; +{ + int errval = cond_reltimedwait ((cond_t *)cond, (mutex_t *)mutex, NULL); + if (errval == ETIME) + return ETIMEDOUT; + else if (errval == EINTR) + return 0; + return errval; +} + +versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait, + GLIBC_2_3_2); diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_getaffinity.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_getaffinity.c new file mode 100644 index 0000000000..eaec56f7c9 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_getaffinity.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2003, 2004, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +__pthread_getaffinity_new (pthread_t th, size_t cpusetsize, cpu_set_t *cpuset) +{ + return ENOSYS; +} +strong_alias (__pthread_getaffinity_new, __pthread_getaffinity_np) +weak_alias (__pthread_getaffinity_new, pthread_getaffinity_np) + +stub_warning (pthread_getaffinity_np) +#include <stub-tag.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_getcpuclockid.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_getcpuclockid.c new file mode 100644 index 0000000000..8601890742 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_getcpuclockid.c @@ -0,0 +1,59 @@ +/* Copyright (C) 2000, 2001, 2002, 2003, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <sys/time.h> +#include <tls.h> + + +int +pthread_getcpuclockid (threadid, clockid) + pthread_t threadid; + clockid_t *clockid; +{ + struct pthread *pd = (struct pthread *) __find_in_stack_list (threadid); + + /* Make sure the descriptor is valid. */ + if (INVALID_TD_P (pd)) + /* Not a valid thread handle. */ + return ESRCH; + +#ifdef CLOCK_THREAD_CPUTIME_ID + /* We need to store the thread ID in the CLOCKID variable together + with a number identifying the clock. We reserve the low 3 bits + for the clock ID and the rest for the thread ID. This is + problematic if the thread ID is too large. But 29 bits should be + fine. + + If some day more clock IDs are needed the ID part can be + enlarged. The IDs are entirely internal. */ + if (pd->tid >= 1 << (8 * sizeof (*clockid) - CLOCK_IDFIELD_SIZE)) + return ERANGE; + + /* Store the number. */ + *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE); + + return 0; +#else + /* We don't have a timer for that. */ + return ENOENT; +#endif +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_kill.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_kill.c new file mode 100644 index 0000000000..05dfa6dade --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_kill.c @@ -0,0 +1,58 @@ +/* Copyright (C) 2002, 2003, 2004, 2006, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <signal.h> +#include <pthreadP.h> +#include <tls.h> +#include <sysdep.h> +#include <kernel-features.h> + + +int +__pthread_kill (threadid, signo) + pthread_t threadid; + int signo; +{ +#ifndef PTHREAD_T_IS_TID + struct pthread *pd = (struct pthread *) threadid; +#else + struct pthread *pd = __find_in_stack_list (threadid); +#endif + + /* Make sure the descriptor is valid. */ + if (INVALID_TD_P (pd)) + /* Not a valid thread handle. */ + return ESRCH; + + /* Disallow sending the signal we use for cancellation, timers, for + for the setxid implementation. */ + if (signo == SIGCANCEL || signo == SIGTIMER) + return EINVAL; + + /* We have a special syscall to do the work. */ + INTERNAL_SYSCALL_DECL (err); + int val = INTERNAL_SYSCALL (tkill, err, 2, threadid, signo); + + return (INTERNAL_SYSCALL_ERROR_P (val, err) + ? INTERNAL_SYSCALL_ERRNO (val, err) : 0); +} +strong_alias (__pthread_kill, pthread_kill) +weak_alias (__pthread_kill, _lwp_kill) +weak_alias (__pthread_kill, thr_kill) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_consistent.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_consistent.c new file mode 100644 index 0000000000..351ffbb789 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_consistent.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2005. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int +pthread_mutex_consistent_np (mutex) + pthread_mutex_t *mutex; +{ + return mutex_consistent ((mutex_t *)mutex); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_destroy.c new file mode 100644 index 0000000000..b5e33a2536 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_destroy.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2002, 2003, 2005, 2006, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <string.h> +#include <pthreadP.h> +#include <synchP.h> + + +int +__pthread_mutex_destroy (mutex) + pthread_mutex_t *mutex; +{ + if (mutex->mutex_lockbyte != LOCKBYTE_UNSET || + mutex->mutex_cond_waiters > 0) + return EBUSY; + + if (mutex->mutex_type & LOCK_ROBUST) + memset (mutex, 0, sizeof(mutex_t)); + else + mutex->mutex_magic = -1; + + return 0; +} +strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy) +INTDEF(__pthread_mutex_destroy) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_getprioceiling.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_getprioceiling.c new file mode 100644 index 0000000000..072d1eefef --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_getprioceiling.c @@ -0,0 +1,37 @@ +/* Get current priority ceiling of pthread_mutex_t. + Copyright (C) 2006, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2006. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +pthread_mutex_getprioceiling (mutex, prioceiling) + const pthread_mutex_t *mutex; + int *prioceiling; +{ + if ((mutex->mutex_type & LOCK_PRIO_PROTECT) == 0) + return EINVAL; + + *prioceiling = mutex->mutex_ceiling; + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_init.c new file mode 100644 index 0000000000..d7dafa7491 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_init.c @@ -0,0 +1,52 @@ +/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <assert.h> +#include <errno.h> +#include <string.h> +#include <pthreadP.h> +#include <sys/synch.h> +#include <synchP.h> + +static const struct pthread_mutexattr default_attr = + { + /* Default is a normal mutex, not shared between processes. */ + .mutexkind = PTHREAD_MUTEX_NORMAL + }; + + +int +__pthread_mutex_init (mutex, mutexattr) + pthread_mutex_t *mutex; + const pthread_mutexattr_t *mutexattr; +{ + const struct pthread_mutexattr *imutexattr; + + imutexattr = (const struct pthread_mutexattr *) mutexattr ?: &default_attr; + + int ceiling = (imutexattr->mutexkind & PTHREAD_MUTEXATTR_PRIO_CEILING_MASK) + >> PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT; + + return mutex_init ((mutex_t *)mutex, imutexattr->mutexkind, (void *)ceiling); +} +strong_alias (__pthread_mutex_init, pthread_mutex_init) +INTDEF(__pthread_mutex_init) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_lock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_lock.c new file mode 100644 index 0000000000..849b81d6bc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_lock.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + + +int +__pthread_mutex_lock (mutex) + pthread_mutex_t *mutex; +{ + int errval = __mutex_timedlock ((mutex_t *)mutex, NULL); + if (errval == ETIME) + return ETIMEDOUT; + return errval; +} +#ifndef __pthread_mutex_lock +strong_alias (__pthread_mutex_lock, pthread_mutex_lock) +strong_alias (__pthread_mutex_lock, __pthread_mutex_lock_internal) +#endif diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_reltimedlock_np.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_reltimedlock_np.c new file mode 100644 index 0000000000..7d94d2166f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_reltimedlock_np.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int +pthread_mutex_reltimedlock_np (mutex, reltime) + pthread_mutex_t *mutex; + const struct timespec *reltime; +{ + int errval = __mutex_reltimedlock ((mutex_t *)mutex, reltime); + if (errval == ETIME) + return ETIMEDOUT; + else if (errval == EINTR) + return 0; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_setprioceiling.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_setprioceiling.c new file mode 100644 index 0000000000..601c22da52 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_setprioceiling.c @@ -0,0 +1,35 @@ +/* Set current priority ceiling of pthread_mutex_t. + Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2006. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +pthread_mutex_setprioceiling (mutex, prioceiling, old_ceiling) + pthread_mutex_t *mutex; + int prioceiling; + int *old_ceiling; +{ + // TODO + return ENOSYS; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_timedlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_timedlock.c new file mode 100644 index 0000000000..afcfd8d2ff --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_timedlock.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2002,2003,2004,2005,2006,2007,2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int +pthread_mutex_timedlock (mutex, abstime) + pthread_mutex_t *mutex; + const struct timespec *abstime; +{ + int errval = __mutex_timedlock ((mutex_t *)mutex, abstime); + if (errval == ETIME) + return ETIMEDOUT; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_trylock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_trylock.c new file mode 100644 index 0000000000..8213127625 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_trylock.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int +__pthread_mutex_trylock (mutex) + pthread_mutex_t *mutex; +{ + return mutex_trylock ((mutex_t *)mutex); +} +strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_unlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_unlock.c new file mode 100644 index 0000000000..4d0fe0780f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutex_unlock.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +int +__pthread_mutex_unlock (mutex) + pthread_mutex_t *mutex; +{ + return mutex_unlock ((mutex_t *)mutex); +} +strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock) +strong_alias (__pthread_mutex_unlock, __pthread_mutex_unlock_internal) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutexattr_settype.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutexattr_settype.c new file mode 100644 index 0000000000..5027976825 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_mutexattr_settype.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2002, 2005, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +__pthread_mutexattr_settype (attr, kind) + pthread_mutexattr_t *attr; + int kind; +{ + struct pthread_mutexattr *iattr; + + if (kind != PTHREAD_MUTEX_NORMAL && kind != PTHREAD_MUTEX_ERRORCHECK && + kind !=PTHREAD_MUTEX_RECURSIVE) + return EINVAL; + + iattr = (struct pthread_mutexattr *) attr; + + iattr->mutexkind = (iattr->mutexkind & PTHREAD_MUTEXATTR_FLAG_BITS) | kind; + + return 0; +} +weak_alias (__pthread_mutexattr_settype, pthread_mutexattr_setkind_np) +strong_alias (__pthread_mutexattr_settype, pthread_mutexattr_settype) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_once.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_once.c new file mode 100644 index 0000000000..0f462452b6 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_once.c @@ -0,0 +1,70 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include "pthreadP.h" +#include <lowlevellock.h> +#include <not-cancel.h> + +unsigned long int __fork_generation attribute_hidden; + +static pthread_mutex_t once_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + +static void +clear_once_control (void *arg) +{ + pthread_once_t *once_control = (pthread_once_t *) arg; + + *once_control = 0; + (void)__pthread_mutex_unlock (&once_lock); +} + +/* XXX: This code breaks with fork - but so does sun's libc. */ + +int +__pthread_once (once_control, init_routine) + pthread_once_t *once_control; + void (*init_routine) (void); +{ + if (*once_control == PTHREAD_ONCE_INIT) + { + (void)__pthread_mutex_lock (&once_lock); + + if (*once_control == PTHREAD_ONCE_INIT) + { + /* This thread is the first here. Do the initialization. + Register a cleanup handler so that in case the thread gets + interrupted the initialization can be restarted. */ + pthread_cleanup_push (clear_once_control, once_control); + + init_routine (); + + pthread_cleanup_pop (0); + + *once_control = !PTHREAD_ONCE_INIT; + } + + __pthread_mutex_unlock (&once_lock); + } + + return 0; +} +weak_alias (__pthread_once, pthread_once) +strong_alias (__pthread_once, __pthread_once_internal) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_destroy.c new file mode 100644 index 0000000000..47b6e775a2 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_destroy.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2002, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include "pthreadP.h" +#include <string.h> + + +int +__pthread_rwlock_destroy (rwlock) + pthread_rwlock_t *rwlock; +{ + /* XXX: The base implemention does nothing so we do nothing too. */ +#if 0 + if (rwlock->readers != 0) + return EBUSY; + + rwlock->type = -1; +#endif + + return 0; +} +strong_alias (__pthread_rwlock_destroy, pthread_rwlock_destroy) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_init.c new file mode 100644 index 0000000000..9e11314291 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_init.c @@ -0,0 +1,58 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include "pthreadP.h" +#include <string.h> +#include <sys/synch.h> +#include <synchP.h> + + +static const struct pthread_rwlockattr default_attr = + { + .lockkind = PTHREAD_RWLOCK_DEFAULT_NP, + .pshared = PTHREAD_PROCESS_PRIVATE + }; + + +int +__pthread_rwlock_init (rwlock, attr) + pthread_rwlock_t *rwlock; + const pthread_rwlockattr_t *attr; +{ + const struct pthread_rwlockattr *iattr; + + iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_attr; + + memset (rwlock, 0, sizeof(pthread_rwlock_t)); + rwlock->type = iattr->pshared | + (iattr->lockkind << PTHREAD_RWLOCK_TYPE_SHIFT); + rwlock->magic = RWL_MAGIC; + rwlock->mutex.mutex_type = iattr->pshared; + rwlock->mutex.mutex_flag = LOCK_INITED; + rwlock->mutex.mutex_magic = MUTEX_MAGIC; + rwlock->readercv.cond_type = iattr->pshared; + rwlock->readercv.cond_magic = COND_MAGIC; + rwlock->writercv.cond_type = iattr->pshared; + rwlock->writercv.cond_magic = COND_MAGIC; + + return 0; +} +strong_alias (__pthread_rwlock_init, pthread_rwlock_init) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_rdlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_rdlock.c new file mode 100644 index 0000000000..00fe4c1f8c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_rdlock.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sysdep.h> +#include <pthread.h> +#include <pthreadP.h> +#include <stddef.h> + + +/* Acquire read lock for RWLOCK. */ +int +__pthread_rwlock_rdlock (rwlock) + pthread_rwlock_t *rwlock; +{ + int errval = __rw_timedrdlock ((rwlock_t *)rwlock, NULL); + if (errval == ETIME) + return ETIMEDOUT; + return errval; +} + +weak_alias (__pthread_rwlock_rdlock, pthread_rwlock_rdlock) +strong_alias (__pthread_rwlock_rdlock, __pthread_rwlock_rdlock_internal) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_timedrdlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_timedrdlock.c new file mode 100644 index 0000000000..8aad3e4e60 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_timedrdlock.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +/* Try to acquire read lock for RWLOCK or return after specfied time. */ +int +pthread_rwlock_timedrdlock (rwlock, abstime) + pthread_rwlock_t *rwlock; + const struct timespec *abstime; +{ + COPY_TIMESPEC (abstime) + int errval = __rw_timedrdlock ((rwlock_t *)rwlock, __abstime); + if (errval == ETIME) + return ETIMEDOUT; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_timedwrlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_timedwrlock.c new file mode 100644 index 0000000000..79632365d1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_timedwrlock.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +/* Try to acquire write lock for RWLOCK or return after specfied time. */ +int +pthread_rwlock_timedwrlock (rwlock, abstime) + pthread_rwlock_t *rwlock; + const struct timespec *abstime; +{ + COPY_TIMESPEC (abstime) + int errval = __rw_timedwrlock ((rwlock_t *)rwlock, __abstime); + if (errval == ETIME) + return ETIMEDOUT; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_tryrdlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_tryrdlock.c new file mode 100644 index 0000000000..2d6589d73e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_tryrdlock.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int +__pthread_rwlock_tryrdlock (rwlock) + pthread_rwlock_t *rwlock; +{ + return rw_tryrdlock ((rwlock_t *)rwlock); +} +strong_alias (__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_trywrlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_trywrlock.c new file mode 100644 index 0000000000..9de84fbaf7 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_trywrlock.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2002, 2003, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int +__pthread_rwlock_trywrlock (rwlock) + pthread_rwlock_t *rwlock; +{ + return rw_trywrlock ((rwlock_t *)rwlock); +} +strong_alias (__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_unlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_unlock.c new file mode 100644 index 0000000000..e9cfe935a7 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_unlock.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +/* Unlock RWLOCK. */ +int +__pthread_rwlock_unlock (pthread_rwlock_t *rwlock) +{ + int errval = rw_unlock ((rwlock_t *)rwlock); + if (errval == EBUSY) + return EPERM; + return errval; +} + +weak_alias (__pthread_rwlock_unlock, pthread_rwlock_unlock) +strong_alias (__pthread_rwlock_unlock, __pthread_rwlock_unlock_internal) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_wrlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_wrlock.c new file mode 100644 index 0000000000..5d75d68ee0 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_rwlock_wrlock.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sysdep.h> +#include <pthread.h> +#include <pthreadP.h> +#include <stddef.h> +#include <stdio.h> + + +/* Acquire write lock for RWLOCK. */ +int +__pthread_rwlock_wrlock (rwlock) + pthread_rwlock_t *rwlock; +{ + int errval = __rw_timedwrlock ((rwlock_t *)rwlock, NULL); + if (errval == ETIME) + return ETIMEDOUT; + return errval; +} + +weak_alias (__pthread_rwlock_wrlock, pthread_rwlock_wrlock) +strong_alias (__pthread_rwlock_wrlock, __pthread_rwlock_wrlock_internal) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_self.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_self.c new file mode 100644 index 0000000000..b14ad209a8 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_self.c @@ -0,0 +1,2 @@ +#include <nptl/pthread_self.c> +weak_alias (__pthread_self, _lwp_self) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_setaffinity.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_setaffinity.c new file mode 100644 index 0000000000..cb5d0760aa --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_setaffinity.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> + + +int +__pthread_setaffinity_new (pthread_t th, size_t cpusetsize, + const cpu_set_t *cpuset) +{ + return ENOSYS; +} +weak_alias (__pthread_setaffinity_new, pthread_setaffinity_np) + +stub_warning (pthread_setaffinity_np) +#include <stub-tag.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_setschedprio.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_setschedprio.c new file mode 100644 index 0000000000..2a69a0aa9f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_setschedprio.c @@ -0,0 +1,2 @@ +#include <nptl/pthread_setschedprio.c> +weak_alias (pthread_setschedprio, thr_setprio) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_sigmask.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_sigmask.c new file mode 100644 index 0000000000..9380697184 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_sigmask.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <signal.h> +#include <pthreadP.h> +#include <sysdep.h> + + +int +pthread_sigmask (how, newmask, oldmask) + int how; + const sigset_t *newmask; + sigset_t *oldmask; +{ + sigset_t local_newmask; + + if (how != SIG_BLOCK && how != SIG_SETMASK && how != SIG_UNBLOCK) + return EINVAL; + + /* The only thing we have to make sure here is that SIGCANCEL is + not blocked. */ + if (newmask != NULL + && __builtin_expect (__sigismember (newmask, SIGCANCEL), 0)) + { + local_newmask = *newmask; + __sigdelset (&local_newmask, SIGCANCEL); + newmask = &local_newmask; + } + + return sigprocmask (how, newmask, oldmask) == -1 ? errno : 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_timedjoin.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_timedjoin.c new file mode 100644 index 0000000000..5789a365ef --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_timedjoin.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2002, 2003, 2005, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stdlib.h> +#include <atomic.h> +#include "pthreadP.h" + + +int +pthread_timedjoin_np (threadid, thread_return, abstime) + pthread_t threadid; + void **thread_return; + const struct timespec *abstime; +{ + return ENOSYS; +} + +stub_warning (pthread_timedjoin_np) +#include <stub-tag.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_yield.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_yield.c new file mode 100644 index 0000000000..18e566bc4c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthread_yield.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/pthread_yield.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreaddef.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreaddef.h new file mode 100644 index 0000000000..990c97f89b --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/pthreaddef.h @@ -0,0 +1,93 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* Get the arch-specific version. */ +#include_next <pthreaddef.h> + +/* Register atfork handlers to protect signal_lock. */ +extern void sigaction_atfork (void); + +/* We need to tell the kernel about the allocated stack. */ +#define PLATFORM_THREAD_START \ + { \ + pd->stack.ss_sp = pd->stackblock; \ + pd->stack.ss_sp = pd->stackblock_size; \ + pd->stack.ss_flags = 0; \ + setustack (&pd->stack); \ + } + +#ifndef __stack_t_defined +# define __need_stack_t +# include <bits/sigstack.h> +#endif + +#define PLATFORM_PTHREAD_INIT \ + sigaction_atfork (); \ + THREAD_SETMEM (pd, main_thread, 1); \ + stack_t *_stack; \ + if (getustack (&_stack) == 0 && _stack) \ + { \ + pd->stackblock = _stack->ss_sp; \ + pd->stackblock_size = _stack->ss_size; \ + } + +/* Additional descr fields. */ +# define PLATFORM_DESCR_FIELDS \ + int main_thread; \ + stack_t stack; + +/* stackblock/stackblock_size should always be filled. */ +#define GET_MAIN_STACK_INFO(stackaddr, stacksize) ENOSYS + +/* Use tid as pthread_t (instead of descr). */ +#define PTHREAD_T_IS_TID + +/* Use pthread scheduler functions in tpp. */ +#define TPP_PTHREAD_SCHED + +/* pthread_ is unsigned. */ +#define FREE_P(descr) ((descr)->tid == (pthread_t)-1) + +/* The first thread has a large (10M) stack so use the arch defaults. */ +#define PTHREAD_USE_ARCH_STACK_DEFAULT_SIZE + +/* It is known that the first lwpid is 1. */ +#define FIRST_THREAD_TID 1 + +/* We need to be passed the stacksize. */ +#define NEED_STACK_SIZE + +/* __exit_thread_inline is the same for all architectures. */ +#include <inline-syscall.h> + +DECLARE_INLINE_SYSCALL (void, lwp_exit, void); + +#undef __exit_thread_inline +#define __exit_thread_inline(val) \ + INLINE_SYSCALL (lwp_exit, 0); + +/* We don't have /dev/shm on solaris, so we use /tmp/.dev_shm. */ +#define STATIC_DEV_SHM "/tmp/.glibc_dev_shm" +#define STATIC_DEV_SHM_PREFIX STATIC_DEV_SHM "/sem." + +/* Pthread structs are opaque so don't assume any struct internals. */ +#define OPAQUE_STRUCTS + +/* Need to let the kernel know about detaching threads. */ +#define NEED_TDETACH diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/ptw-llseek.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/ptw-llseek.c new file mode 100644 index 0000000000..70b786d12e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/ptw-llseek.c @@ -0,0 +1 @@ +// TODO diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/register-atfork.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/register-atfork.c new file mode 100644 index 0000000000..50331dd362 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/register-atfork.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/register-atfork.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_rdlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_rdlock.c new file mode 100644 index 0000000000..2f8a6587cf --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_rdlock.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int rw_rdlock (rwlock) + rwlock_t *rwlock; +{ + int errval = __rw_timedrdlock (rwlock, NULL); + if (errval == EDEADLK) + return EBUSY; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_timedrdlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_timedrdlock.c new file mode 100644 index 0000000000..1fd5356f12 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_timedrdlock.c @@ -0,0 +1,79 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> +#include <abstime-to-reltime.h> + + +int __rw_timedrdlock (rwlock, abstime) + rwlock_t *rwlock; + struct timespec *abstime; +{ + /* Reject invalid timeouts. */ + if (INVALID_TIMESPEC (abstime)) + return EINVAL; + + struct timespec _reltime; + struct timespec *reltime = abstime_to_reltime (abstime, &_reltime); + if (reltime && reltime->tv_sec < 0) + return ETIME; + + int errval = mutex_lock (&rwlock->mutex); + if (errval != 0) + return errval; + + /* Check for deadlock. */ + if (__builtin_expect (rwlock->owner == (uintptr_t)THREAD_SELF, 0) || + ((rwlock->type & LOCK_SHARED) && __builtin_expect ( + rwlock->ownerpid == THREAD_GETMEM (THREAD_SELF, pid), 0))) + { + (void)mutex_unlock (&rwlock->mutex); + return EDEADLK; + } + + /* Wait until we can acquire the read lock. */ + while ((rwlock->readers & _RWLOCK_WR_LOCK) || + (__cond_has_waiters (&rwlock->writercv) && + !PTHREAD_RWLOCK_PREFER_READER_P (rwlock))) + { + /* Wait for writer to wake us up. */ + errval = __cond_reltimedwait_internal ((cond_t *)&rwlock->readercv, + (mutex_t *)&rwlock->mutex, reltime, 0); + if (errval != 0 && errval != EINTR) + { + (void)mutex_unlock (&rwlock->mutex); + return errval; + } + } + + /* Increment readers (note that no other bits are set). */ + if (rwlock->readers == _RWLOCK_RD_MAX) + { + /* XXX: Solaris mutexes have no overflow check and don't know about + EAGAIN; in practice overflow will not occur so we don't care. */ + (void)mutex_unlock (&rwlock->mutex); + return EAGAIN; + } + ++rwlock->readers; + + (void)mutex_unlock (&rwlock->mutex); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_timedwrlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_timedwrlock.c new file mode 100644 index 0000000000..86a3fb9168 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_timedwrlock.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> +#include <abstime-to-reltime.h> + + +int __rw_timedwrlock (rwlock, abstime) + rwlock_t *rwlock; + struct timespec *abstime; +{ + /* Reject invalid timeouts. */ + if (INVALID_TIMESPEC (abstime)) + return EINVAL; + + struct timespec _reltime; + struct timespec *reltime = abstime_to_reltime (abstime, &_reltime); + if (reltime && reltime->tv_sec < 0) + return ETIME; + + int errval = mutex_lock (&rwlock->mutex); + if (errval != 0) + return errval; + + /* Check for deadlock. */ + if (__builtin_expect (rwlock->owner == (uintptr_t)THREAD_SELF, 0) || + ((rwlock->type & LOCK_SHARED) && __builtin_expect ( + rwlock->ownerpid == THREAD_GETMEM (THREAD_SELF, pid), 0))) + { + (void)mutex_unlock (&rwlock->mutex); + return EDEADLK; + } + + /* Wait until we can acquire the write lock. */ + while (rwlock->readers & (_RWLOCK_RD_MASK | _RWLOCK_WR_LOCK)) + { + errval = __cond_reltimedwait_internal ((cond_t *)&rwlock->writercv, + (mutex_t *)&rwlock->mutex, reltime, 0); + if (errval != 0 && errval != EINTR) + { + (void)mutex_unlock (&rwlock->mutex); + return errval; + } + } + + /* Set the write lock. */ + rwlock->readers = _RWLOCK_WR_LOCK; + rwlock->owner = (uintptr_t)THREAD_SELF; + if (rwlock->type & LOCK_SHARED) + rwlock->ownerpid = THREAD_GETMEM (THREAD_SELF, pid); + + (void)mutex_unlock (&rwlock->mutex); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_tryrdlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_tryrdlock.c new file mode 100644 index 0000000000..e5b8bf5390 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_tryrdlock.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int rw_tryrdlock (rwlock) + rwlock_t *rwlock; +{ + int errval = mutex_trylock (&rwlock->mutex); + if (errval != 0) + return errval; + + if ((rwlock->readers & _RWLOCK_WR_LOCK) || + (__cond_has_waiters (&rwlock->writercv) && + !PTHREAD_RWLOCK_PREFER_READER_P (rwlock))) + { + (void)mutex_unlock (&rwlock->mutex); + return EBUSY; + } + + /* Increment readers (note that no other bits are set). */ + if (rwlock->readers == _RWLOCK_RD_MAX) + { + (void)mutex_unlock (&rwlock->mutex); + return EAGAIN; + } + rwlock->readers++; + + (void)mutex_unlock (&rwlock->mutex); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_trywrlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_trywrlock.c new file mode 100644 index 0000000000..ccf68a45c3 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_trywrlock.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int rw_trywrlock (rwlock) + rwlock_t *rwlock; +{ + int errval = mutex_trylock (&rwlock->mutex); + if (errval != 0) + return errval; + + if (rwlock->readers) + { + (void)mutex_unlock (&rwlock->mutex); + return EBUSY; + } + + /* Set write lock. */ + rwlock->readers = _RWLOCK_WR_LOCK; + rwlock->owner = (uintptr_t)THREAD_SELF; + if (rwlock->type & LOCK_SHARED) + rwlock->ownerpid = THREAD_GETMEM (THREAD_SELF, pid); + + (void)mutex_unlock (&rwlock->mutex); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_unlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_unlock.c new file mode 100644 index 0000000000..7c90c38049 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_unlock.c @@ -0,0 +1,66 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int rw_unlock (rwlock) + rwlock_t *rwlock; +{ + int errval = mutex_lock (&rwlock->mutex); + if (errval != 0) + return errval; + + if (rwlock->readers & _RWLOCK_WR_LOCK) + { + /* Writer unlock. */ + if (__builtin_expect (rwlock->owner != (uintptr_t)THREAD_SELF, 0) || + ((rwlock->type & LOCK_SHARED) && __builtin_expect ( + rwlock->ownerpid != THREAD_GETMEM (THREAD_SELF, pid), 0))) + { + (void)mutex_unlock (&rwlock->mutex); + return EBUSY; + } + rwlock->owner = rwlock->ownerpid = 0; + rwlock->readers &= ~_RWLOCK_WR_LOCK; + } + else + { + /* Reader unlock. */ + if ((rwlock->readers & _RWLOCK_RD_MASK) == 0) + { + (void)mutex_unlock (&rwlock->mutex); + return EBUSY; + } + rwlock->readers = (rwlock->readers & _RWLOCK_WR_LOCK) | + ((rwlock->readers & _RWLOCK_RD_MASK) - 1); + } + + /* Wake up a writer (if possible) or all readers. */ + if ((rwlock->readers & _RWLOCK_RD_MASK) == 0 && + __cond_has_waiters (&rwlock->writercv)) + errval = cond_signal (&rwlock->writercv); + else if (__cond_has_waiters (&rwlock->readercv)) + errval = cond_broadcast (&rwlock->readercv); + + (void)mutex_unlock (&rwlock->mutex); + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_wrlock.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_wrlock.c new file mode 100644 index 0000000000..5760c8a8e3 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rw_wrlock.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthreadP.h> +#include <synch.h> + + +int rw_wrlock (rwlock) + rwlock_t *rwlock; +{ + int errval = __rw_timedwrlock (rwlock, NULL); + if (errval == EDEADLK) + return EBUSY; + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rwlock_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rwlock_destroy.c new file mode 100644 index 0000000000..5f6b680700 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rwlock_destroy.c @@ -0,0 +1,31 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <string.h> +#include <synch.h> + + +int rwlock_destroy (rwlock) + rwlock_t *rwlock; +{ + memset (rwlock, 0, sizeof(rwlock_t)); + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rwlock_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rwlock_init.c new file mode 100644 index 0000000000..caaf010041 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/rwlock_init.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <string.h> +#include <synch.h> +#include <synchP.h> + + +int rwlock_init (rwlock, type, arg) + rwlock_t *rwlock; + int type; + void * arg; +{ + if (type != LOCK_NORMAL && type != LOCK_SHARED) + return EINVAL; + + memset (rwlock, 0, sizeof(rwlock_t)); + rwlock->type = type; + rwlock->magic = RWL_MAGIC; + rwlock->mutex.mutex_type = type; + rwlock->mutex.mutex_flag = LOCK_INITED; + rwlock->mutex.mutex_magic = MUTEX_MAGIC; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_destroy.c new file mode 100644 index 0000000000..2bc533c469 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_destroy.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2002, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <semaphore.h> +#include "semaphoreP.h" + + +int +__new_sem_destroy (sem) + sem_t *sem; +{ + memset (sem, 0, sizeof(sem_t)); + return 0; +} +weak_alias (__new_sem_destroy, sem_destroy) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_getvalue.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_getvalue.c new file mode 100644 index 0000000000..aedcfac94a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_getvalue.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <semaphore.h> +#include "semaphoreP.h" + + +int +__new_sem_getvalue (sem, sval) + sem_t *sem; + int *sval; +{ + /* XXX Check for valid SEM parameter. */ + + *sval = sem->count; + + return 0; +} +weak_alias (__new_sem_getvalue, sem_getvalue) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_init.c new file mode 100644 index 0000000000..bdd4b26bdc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_init.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <semaphore.h> +#include "semaphoreP.h" +#include <sys/synch.h> +#include <synchP.h> + + +int +__new_sem_init (sem, pshared, value) + sem_t *sem; + int pshared; + unsigned int value; +{ + int type = pshared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE; + int errval = sema_init ((sema_t *)sem, value, type, NULL); + if (errval != 0) + { + __set_errno (errval); + return -1; + } + + return 0; +} +weak_alias (__new_sem_init, sem_init) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_post.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_post.c new file mode 100644 index 0000000000..3d0118639b --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_post.c @@ -0,0 +1,44 @@ +/* sem_post -- post to a POSIX semaphore. OpenSolaris version. + Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sysdep.h> +#include <semaphore.h> +#include <inline-syscall.h> + +DECLARE_INLINE_SYSCALL (int, lwp_sema_post, sem_t *sp); + + +int +__new_sem_post (sem_t *sem) +{ + int errval = INLINE_SYSCALL (lwp_sema_post, 1, sem); + if (errval == EOVERFLOW) + errval = 0; + if (errval != 0) + { + __set_errno (errval); + return -1; + } + return 0; +} +weak_alias (__new_sem_post, sem_post) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_timedwait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_timedwait.c new file mode 100644 index 0000000000..9a18a00433 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_timedwait.c @@ -0,0 +1,45 @@ +/* sem_timedwait -- wait on a semaphore. OpenSolaris version. + Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sysdep.h> +#include <semaphore.h> + +#include <pthreadP.h> +#include <inline-syscall.h> +#include <abstime-to-reltime.h> + + +int +sem_timedwait (sem_t *sem, const struct timespec *abstime) +{ + COPY_TIMESPEC (abstime) + int errval = __sema_timedwait ((sema_t *)sem, __abstime); + if (errval == ETIME) + errval = ETIMEDOUT; + if (errval != 0) + { + __set_errno (errval); + return -1; + } + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_trywait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_trywait.c new file mode 100644 index 0000000000..09ab7bc51d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_trywait.c @@ -0,0 +1,44 @@ +/* sem_trywait -- wait on a semaphore. OpenSolaris version. + Copyright (C) 2003, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sysdep.h> +#include <semaphore.h> +#include <inline-syscall.h> + +DECLARE_INLINE_SYSCALL (int, lwp_sema_trywait, sem_t *sp); + + +int +__new_sem_trywait (sem_t *sem) +{ + int errval = INLINE_SYSCALL (lwp_sema_trywait, 1, sem); + if (errval == EBUSY) + errval = EAGAIN; + if (errval != 0) + { + __set_errno (errval); + return -1; + } + return 0; +} +weak_alias (__new_sem_trywait, sem_trywait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_wait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_wait.c new file mode 100644 index 0000000000..8d99cd14e1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sem_wait.c @@ -0,0 +1,43 @@ +/* sem_wait -- wait on a semaphore. OpenSolaris version. + Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003. + OpenSolaris bits contributed by David Bartley + <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sysdep.h> +#include <semaphore.h> + +#include <pthreadP.h> + + +int +__new_sem_wait (sem_t *sem) +{ + int errval = __sema_timedwait ((sema_t *)sem, NULL); + if (errval == ETIME) + errval = ETIMEDOUT; + if (errval != 0) + { + __set_errno (errval); + return -1; + } + return 0; +} +weak_alias (__new_sem_wait, sem_wait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_destroy.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_destroy.c new file mode 100644 index 0000000000..ae39edc1b7 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_destroy.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + + +int sema_destroy (sem) + sema_t *sem; +{ + memset (sem, 0, sizeof(sema_t)); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_init.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_init.c new file mode 100644 index 0000000000..24b8b20a1c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_init.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + + +int sema_init (sem, count, type, arg) + sema_t *sem; + unsigned int count; + int type; + void *arg; +{ + /* Parameter sanity check. */ + if (__builtin_expect (count > SEM_VALUE_MAX, 0)) + return EINVAL; + + memset (sem, 0, sizeof(sema_t)); + sem->count = count; + sem->type = type; + sem->magic = SEMA_MAGIC; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_post.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_post.c new file mode 100644 index 0000000000..b782ba80a2 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_post.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +DECLARE_INLINE_SYSCALL (int, lwp_sema_post, sema_t *sp); + + +int sema_post (sem) + sema_t *sem; +{ + return INLINE_SYSCALL (lwp_sema_post, 1, sem); +} + +weak_alias (sema_post, _lwp_sema_post) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_timedwait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_timedwait.c new file mode 100644 index 0000000000..24843319a1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_timedwait.c @@ -0,0 +1,51 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> +#include <abstime-to-reltime.h> + +DECLARE_INLINE_SYSCALL (int, lwp_sema_timedwait, sema_t *sp, + struct timespec *tsp, int check_park); + + +int __sema_timedwait (sem, abstime) + sema_t *sem; + struct timespec *abstime; +{ + /* Reject invalid timeouts. */ +/* TODO: if we can acquire the semaphore we should never check abstime */ + if (INVALID_TIMESPEC (abstime)) + return EINVAL; + + struct timespec _reltime; + struct timespec *reltime = abstime_to_reltime (abstime, &_reltime); + if (reltime && reltime->tv_sec < 0) + return ETIME; + + /* Enable asynchronous cancellation. Required by the standard. */ + int oldtype = __pthread_enable_asynccancel (); + + int errval = INLINE_SYSCALL (lwp_sema_timedwait, 3, sem, reltime, 1); + + /* Disable asynchronous cancellation. */ + __pthread_disable_asynccancel (oldtype); + + return errval; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_trywait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_trywait.c new file mode 100644 index 0000000000..5f0f8bfc86 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_trywait.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + +DECLARE_INLINE_SYSCALL (int, lwp_sema_trywait, sema_t *sp); + + +int sema_trywait (sem) + sema_t *sem; +{ + return INLINE_SYSCALL (lwp_sema_trywait, 1, sem); +} + +weak_alias (sema_trywait, _lwp_sema_trywait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_wait.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_wait.c new file mode 100644 index 0000000000..1a90df5ff1 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sema_wait.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <synch.h> + + +int sema_wait (sem) + sema_t *sem; +{ + return __sema_timedwait (sem, NULL); +} + +weak_alias (sema_wait, _lwp_sema_wait) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigaction.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigaction.c new file mode 100644 index 0000000000..69f2f1f962 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigaction.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _NPTL_SIGACTION +# define _NPTL_SIGACTION +# include <sigaction.c> +#else + +#include_next <sigaction.c> +#include <bits/libc-lock.h> +#include <fork.h> + +static void sigaction_atfork_prepare (void) +{ + __libc_lock_lock (signal_lock); +} + +static void sigaction_atfork_parent (void) +{ + __libc_lock_unlock (signal_lock); +} + +static void sigaction_atfork_child (void) +{ + __libc_lock_unlock (signal_lock); +} + +void sigaction_atfork (void) +{ + __register_atfork (sigaction_atfork_prepare, sigaction_atfork_parent, + sigaction_atfork_child, NULL); +} + +#endif /* _NPTL_SIGACTION */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigfillset.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigfillset.c new file mode 100644 index 0000000000..7cd7c2d057 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigfillset.c @@ -0,0 +1 @@ +#include <signal/sigfillset.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigprocmask.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigprocmask.c new file mode 100644 index 0000000000..0a0fec2810 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigprocmask.c @@ -0,0 +1,6 @@ +#ifndef __SIGPROCMASK_C +#define __SIGPROCMASK_C +#include <sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigprocmask.c> +#else +#include_next <sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sigprocmask.c> +#endif /* __SIGPROCMASK_C */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/smp.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/smp.h new file mode 100644 index 0000000000..61c9f1135d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/smp.h @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/smp.h> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/synch.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/synch.h new file mode 100644 index 0000000000..b7fddbb208 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/synch.h @@ -0,0 +1,99 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYNCH_H +#define _SYNCH_H + +#include <sys/synch.h> +#include <features.h> + +typedef lwp_mutex_t mutex_t; +typedef lwp_cond_t cond_t; +typedef lwp_rwlock_t rwlock_t; +typedef lwp_sema_t sema_t; + +#define SEMA_HELD(x) _sema_held (x) +#define RW_READ_HELD(x) _rw_read_held (x) +#define RW_WRITE_HELD(x) _rw_write_held (x) +#define RW_LOCK_HELD(x) (RW_READ_HELD (x) || RW_WRITE_HELD (x)) +#define MUTEX_HELD(x) _mutex_held (x) + +__BEGIN_DECLS + +/* syscalls */ + +int _lwp_mutex_lock (lwp_mutex_t *); +int _lwp_mutex_unlock (lwp_mutex_t *); +int _lwp_mutex_trylock (lwp_mutex_t *); +int _lwp_cond_wait (lwp_cond_t *, lwp_mutex_t *); +int _lwp_cond_timedwait (lwp_cond_t *, lwp_mutex_t *, struct timespec *); +int _lwp_cond_reltimedwait (lwp_cond_t *, lwp_mutex_t *, struct timespec *); +int _lwp_cond_signal (lwp_cond_t *); +int _lwp_cond_broadcast (lwp_cond_t *); +int _lwp_sema_init (lwp_sema_t *, int); +int _lwp_sema_wait (lwp_sema_t *); +int _lwp_sema_trywait (lwp_sema_t *); +int _lwp_sema_post (lwp_sema_t *); + +/* condition variables */ + +int cond_init (cond_t *, int, void *); +int cond_destroy (cond_t *); +int cond_wait (cond_t *, mutex_t *); +int cond_timedwait (cond_t *, mutex_t *, struct timespec *); +int cond_reltimedwait (cond_t *, mutex_t *, struct timespec *); +int cond_signal (cond_t *); +int cond_broadcast (cond_t *); + +/* mutexes */ + +extern int mutex_init (mutex_t *, int, void *); +extern int mutex_destroy (mutex_t *); +extern int mutex_consistent (mutex_t *); +extern int mutex_lock (mutex_t *); +extern int mutex_trylock (mutex_t *); +extern int mutex_unlock (mutex_t *); +extern int _mutex_held (mutex_t *); + +/* reader/writer locks */ + +extern int rwlock_init (rwlock_t *, int, void *); +extern int rwlock_destroy (rwlock_t *); +extern int rw_rdlock (rwlock_t *); +extern int rw_wrlock (rwlock_t *); +extern int rw_unlock (rwlock_t *); +extern int rw_tryrdlock (rwlock_t *); +extern int rw_trywrlock (rwlock_t *); +extern int _rw_read_held (rwlock_t *); +extern int _rw_write_held (rwlock_t *); + +/* semaphores */ + +extern int sema_init (sema_t *, unsigned int, int, void *); +extern int sema_destroy (sema_t *); +extern int sema_wait (sema_t *); +extern int sema_timedwait (sema_t *, struct timespec *); +extern int sema_reltimedwait (sema_t *, const struct timespec *); +extern int sema_post (sema_t *); +extern int sema_trywait (sema_t *); +extern int _sema_held (sema_t *); + +__END_DECLS + +#endif /* _SYNCH_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/lwp.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/lwp.h new file mode 100644 index 0000000000..c43ab75d08 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/lwp.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_LWP_H +#define _SYS_LWP_H + +#include <sys/types.h> +#include <features.h> +#define __need_timespec +#include <time.h> + +struct lwpinfo +{ + struct timespec lwp_utime; + struct timespec lwp_stime; + long lwpinfo_pad[64]; +}; + +#define LWP_DAEMON 0x00000020 +#define LWP_DETACHED 0x00000040 +#define LWP_SUSPENDED 0x00000080 + +#define _LWP_FSBASE 0 +#define _LWP_GSBASE 1 + +#define _LWP_SETPRIVATE 0 +#define _LWP_GETPRIVATE 1 + +__BEGIN_DECLS + +int _lwp_kill (lwpid_t, int); +int _lwp_info (struct lwpinfo *); +lwpid_t _lwp_self (void); +int _lwp_suspend (lwpid_t); +int _lwp_continue (lwpid_t); + +__END_DECLS + +#endif /* _SYS_LWP_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/synch.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/synch.h new file mode 100644 index 0000000000..7c8aba9b21 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/sys/synch.h @@ -0,0 +1,88 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_SYNCH_H +#define _SYS_SYNCH_H + +#define __need_synch_bits +#include <bits/synch.h> + +/* general *_type values */ +#define USYNC_THREAD 0x00 +#define USYNC_PROCESS 0x01 + +/* mutex_type values */ +#define LOCK_NORMAL USYNC_THREAD +#define LOCK_SHARED USYNC_PROCESS +#define LOCK_ERRORCHECK 0x02 +#define LOCK_RECURSIVE 0x04 +#define LOCK_PRIO_INHERIT 0x10 +#define LOCK_PRIO_PROTECT 0x20 +#define LOCK_ROBUST 0x40 + +/* deprecated */ +#define USYNC_PROCESS_ROBUST 0x08 + +/* mutex_flag values */ +#define LOCK_OWNERDEAD 0x01 +#define LOCK_NOTRECOVERABLE 0x02 +#define LOCK_INITED 0x04 +#define LOCK_UNMAPPED 0x08 + +#define MUTEX_MAGIC 0x4d58 /* "MX" */ +#define SEMA_MAGIC 0x534d /* "SM" */ +#define COND_MAGIC 0x4356 /* "CV" */ +#define RWL_MAGIC 0x5257 /* "RW" */ + +/* mutex initializers */ +#define DEFAULTMUTEX \ + {{0, 0, 0, {USYNC_THREAD}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define SHAREDMUTEX \ + {{0, 0, 0, {USYNC_PROCESS}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define RECURSIVEMUTEX \ + {{0, 0, 0, {USYNC_THREAD|LOCK_RECURSIVE}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define ERRORCHECKMUTEX \ + {{0, 0, 0, {USYNC_THREAD|LOCK_ERRORCHECK}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define RECURSIVE_ERRORCHECKMUTEX \ + {{0, 0, 0, {USYNC_THREAD|LOCK_RECURSIVE|LOCK_ERRORCHECK}, \ + MUTEX_MAGIC}, {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} + +/* condition variable initializers */ +#define DEFAULTCV \ + {{{0, 0, 0, 0}, USYNC_THREAD, COND_MAGIC}, 0} +#define SHAREDCV \ + {{{0, 0, 0, 0}, USYNC_PROCESS, COND_MAGIC}, 0} + +/* semaphore initializers */ +#define DEFAULTSEMA \ + {0, USYNC_THREAD, SEMA_MAGIC, {0, 0, 0}, {0, 0}} +#define SHAREDSEMA \ + {0, USYNC_PROCESS, SEMA_MAGIC, {0, 0, 0}, {0, 0}} + +/* reader/writer lock initializers */ +#define DEFAULTRWLOCK \ + {0, USYNC_THREAD, RWL_MAGIC, DEFAULTMUTEX, DEFAULTCV, DEFAULTCV} +#define SHAREDRWLOCK \ + {0, USYNC_PROCESS, RWL_MAGIC, SHAREDMUTEX, SHAREDCV, SHAREDCV} + +#endif /* _SYS_SYNCH_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/syscalls.list b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/syscalls.list new file mode 100644 index 0000000000..d95d8bcc24 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/syscalls.list @@ -0,0 +1,35 @@ +# File name Caller Syscall name Args Strong name Weak names + +# +# implement these in helper files +# + +sys_lwp_self - lwp_self Ei: __syscall_lwp_self +sys_lwp_create - lwp_create Vi:pip __syscall_lwp_create +sys_lwp_wait - lwp_wait Vi:ip __syscall_lwp_wait +sys_lwp_exit - lwp_exit Ei: __syscall_lwp_exit +sys_lwp_suspend - lwp_suspend RVi:i __syscall_lwp_suspend +sys_lwp_continue - lwp_continue Vi:i __syscall_lwp_continue +sys_lwp_kill - lwp_kill Vi:ii __syscall_lwp_kill + +sys_lwp_park - lwp_park:lwp_park Vi:pi __syscall_lwp_park +sys_lwp_unpark - lwp_park:lwp_unpark Vi:pi __syscall_lwp_unpark +sys_lwp_unpark_all - lwp_park:lwp_unpark_all Vi:pi __syscall_lwp_unpark_all +sys_lwp_unpark_cancel - lwp_park:lwp_unpark Vi:i __syscall_lwp_unpark_cancel +sys_lwp_detach - lwp_detach i:i __syscall_lwp_detach + +sys_lwp_mutex_wakeup - lwp_mutex_wakeup Vi:pi __syscall_lwp_mutex_wakeup +sys_lwp_mutex_timedlock - lwp_mutex_timedlock RVi:pi __syscall_lwp_mutex_timedlock +sys_lwp_mutex_unlock - lwp_mutex_unlock Vi:p __syscall_lwp_mutex_unlock +sys_lwp_mutex_trylock - lwp_mutex_trylock Vi:p __syscall_lwp_mutex_trylock +sys_lwp_mutex_register - lwp_mutex_register Vi:p __syscall_lwp_mutex_register + +sys_lwp_cond_wait - lwp_cond_wait Vi:pppi __syscall_lwp_cond_wait +sys_lwp_cond_signal - lwp_cond_signal Vi:p __syscall_lwp_cond_signal +sys_lwp_cond_broadcast - lwp_cond_broadcast Vi:p __syscall_lwp_cond_broadcast + +sys_lwp_sema_post - lwp_sema_post Vi:p __syscall_lwp_sema_post +sys_lwp_sema_trywait - lwp_sema_trywait Vi:p __syscall_lwp_sema_trywait +sys_lwp_sema_timedwait - lwp_sema_timedwait Vi:ppi __syscall_lwp_sema_timedwait + +_lwp_info - lwp_info Vi:p _lwp_info diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_continue.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_continue.c new file mode 100644 index 0000000000..199070be7e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_continue.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <inline-syscall.h> + +DECLARE_INLINE_SYSCALL (int, lwp_continue, thread_t lwpid); + + +int thr_continue (thread_t target_thread) +{ + /* XXX: Currently we don't bother ensuring that the target_thread doesn't + hold any of our locks. */ + + return INLINE_SYSCALL (lwp_continue, 1, target_thread); +} + +weak_alias (thr_continue, _lwp_continue) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_create.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_create.c new file mode 100644 index 0000000000..a56b07476d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_create.c @@ -0,0 +1,53 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> + +int thr_create (void *stack_address, size_t stack_size, + void * (*start_routine)(void *), void *arg, + long flags, thread_t *new_thread) +{ + if(flags & ~(THR_BOUND | THR_DETACHED | THR_NEW_LWP | THR_SUSPENDED | + THR_DAEMON)) + { + return EINVAL; + } + + struct pthread_attr iattr; + memset (&iattr, 0, sizeof(struct pthread_attr)); + iattr.guardsize = __getpagesize (); + iattr.stackaddr = stack_address; + iattr.stacksize = stack_size; + iattr.flags = ATTR_FLAG_THR_CREATE | + (stack_size ? ATTR_FLAG_STACKADDR : 0) | + ((flags & THR_DETACHED) ? ATTR_FLAG_DETACHSTATE : 0) | + ((flags & THR_SUSPENDED) ? ATTR_FLAG_SUSPENDED : 0) | + ((flags & THR_DAEMON) ? ATTR_FLAG_DAEMON : 0); + + pthread_t thread; + int res = pthread_create (&thread, (pthread_attr_t *)&iattr, + start_routine, arg); + if (res == 0 && new_thread) + *new_thread = (thread_t)thread; + return res; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_exit.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_exit.c new file mode 100644 index 0000000000..9a1641e006 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_exit.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <errno.h> + +void thr_exit(void *status) +{ + return pthread_exit (status); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getconcurrency.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getconcurrency.c new file mode 100644 index 0000000000..e9ad591779 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getconcurrency.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_getconcurrency (void) +{ + return pthread_getconcurrency (); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getprio.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getprio.c new file mode 100644 index 0000000000..ef361f601a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getprio.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_getprio (target_thread, priority) + thread_t target_thread; + int *priority; +{ + int policy; + struct sched_param param; + int res = pthread_getschedparam (target_thread, &policy, ¶m); + if (res != 0) + return res; + *priority = param.sched_priority; + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getspecific.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getspecific.c new file mode 100644 index 0000000000..f341fe74a5 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_getspecific.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + +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, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <errno.h> + +int thr_getspecific (key, valuep) + thread_key_t key; + void **valuep; +{ + /* We need to check that key is valid. */ + if (key >= PTHREAD_KEYS_MAX) + return EINVAL; + uintptr_t seq = __pthread_keys[key].seq; + if (KEY_UNUSED (seq) || KEY_USABLE (seq)) + return EINVAL; + + *valuep = __pthread_getspecific (key); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_join.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_join.c new file mode 100644 index 0000000000..88907526ec --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_join.c @@ -0,0 +1,73 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <errno.h> +#include <assert.h> +#include <inline-syscall.h> + +DECLARE_INLINE_SYSCALL (int, lwp_wait, thread_t lwpid, thread_t *departed); + +int thr_join (thread_t thread, thread_t *departed, void **status) +{ + if (thread == 0) + { + /* Wait for any thread to terminate. */ + thread_t _departed; + int errval = INLINE_SYSCALL (lwp_wait, 2, 0, &_departed); + if(errval != 0) + return errval; + + /* Check if this is a thread we know about. */ + struct pthread *pd = __find_in_stack_list (_departed); + if (pd == NULL) + { + if (departed) + *departed = _departed; + if (status) + *status = 0; + return 0; + } + + /* We mark the thread as terminated and as joined. */ + pd->tid = -1; + + /* Store the return value if the caller is interested. */ + if (status != NULL) + *status = pd->result; + + /* Free the TCB. */ + __free_tcb (pd); + + /* Return the thread_t we waited on if the caller is interested. */ + if (departed) + *departed = (thread_t)thread; + + return 0; + } + else + { + /* Normal wait. */ + int errval = pthread_join (thread, status); + if (errval == 0 && departed) + *departed = thread; + return errval; + } +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_keycreate.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_keycreate.c new file mode 100644 index 0000000000..9d1047428e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_keycreate.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + +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, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_keycreate (keyp, destructor) + thread_key_t *keyp; + void (*destructor)(void *); +{ + return pthread_key_create (keyp, destructor); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_keycreate_once.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_keycreate_once.c new file mode 100644 index 0000000000..eb4db71206 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_keycreate_once.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + +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, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + +int thr_keycreate_once (keyp, destructor) + thread_key_t *keyp; + void (*destructor)(void *); +{ + int errval = 0; + + if (*keyp) + { + errval = __pthread_mutex_lock (&mutex); + if (errval == 0) + { + if (*keyp) + errval = pthread_key_create (keyp, destructor); + + __pthread_mutex_unlock (&mutex); + } + } + + return errval; +} + +weak_alias (thr_keycreate_once, pthread_key_create_once_np) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_main.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_main.c new file mode 100644 index 0000000000..483cdb3e2c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_main.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_main (void) +{ + return THREAD_GETMEM (THREAD_SELF, main_thread); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_min_stack.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_min_stack.c new file mode 100644 index 0000000000..ca567b2d31 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_min_stack.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +size_t thr_min_stack (void) +{ + return PTHREAD_STACK_MIN; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_self.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_self.c new file mode 100644 index 0000000000..5d79ba6b6f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_self.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <errno.h> +#include <inline-syscall.h> + +thread_t thr_self (void) +{ + return pthread_self (); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setconcurrency.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setconcurrency.c new file mode 100644 index 0000000000..8374d67ccf --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setconcurrency.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_setconcurrency (new_level) + int new_level; +{ + return pthread_setconcurrency (new_level); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setprio.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setprio.c new file mode 100644 index 0000000000..8e29cb0a03 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setprio.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_setprio (target_thread, priority) + thread_t target_thread; + int priority; +{ + return pthread_setschedprio (target_thread, priority); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setspecific.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setspecific.c new file mode 100644 index 0000000000..9c99a7b10f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_setspecific.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. +This file is part of the GNU C Library. +Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + +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, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <errno.h> + +int thr_setspecific (key, value) + thread_key_t key; + void *value; +{ + /* We need to check that key is valid. */ + if (key >= PTHREAD_KEYS_MAX) + return EINVAL; + uintptr_t seq = __pthread_keys[key].seq; + if (KEY_UNUSED (seq) || KEY_USABLE (seq)) + return EINVAL; + + __pthread_setspecific (key, value); + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_sigsetmask.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_sigsetmask.c new file mode 100644 index 0000000000..c19dfe7987 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_sigsetmask.c @@ -0,0 +1,29 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> + +int thr_sigsetmask (how, set, oset) + int how; + const sigset_t *set; + sigset_t *oset; +{ + return pthread_sigmask (how, set, oset); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_stksegment.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_stksegment.c new file mode 100644 index 0000000000..a6bc28626c --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_stksegment.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <sys/ucontext.h> +#include <sys/syscall.h> +#include <string.h> +#include <stdio.h> + +int thr_stksegment (stk) + stack_t *stk; +{ + struct pthread *self = THREAD_SELF; + stk->ss_size = THREAD_GETMEM (self, stackblock_size); + // TODO: handle stacks that grow up + stk->ss_sp = THREAD_GETMEM (self, stackblock) + stk->ss_size; + stk->ss_flags = 0; + + return 0; +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_suspend.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_suspend.c new file mode 100644 index 0000000000..d47307c698 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_suspend.c @@ -0,0 +1,35 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <inline-syscall.h> + +DECLARE_INLINE_SYSCALL (int, lwp_suspend, thread_t lwpid); + + +int thr_suspend (thread_t target_thread) +{ + /* XXX: Currently we don't bother ensuring that the target_thread doesn't + hold any of our locks. */ + + return INLINE_SYSCALL (lwp_suspend, 1, target_thread); +} + +weak_alias (thr_suspend, _lwp_suspend) diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_yield.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_yield.c new file mode 100644 index 0000000000..12bd960cd3 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thr_yield.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthreadP.h> +#include <thread.h> +#include <sched.h> + +void thr_yield (void) +{ + sched_yield (); +} diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thread.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thread.h new file mode 100644 index 0000000000..355967bb1a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/thread.h @@ -0,0 +1,85 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _THREAD_H +#define _THREAD_H + +#include <signal.h> +#include <synch.h> + +typedef unsigned int thread_t; +typedef unsigned int thread_key_t; + +#define THR_BOUND 0x00000001 /* PTHREAD_SCOPE_SYSTEM; unused */ +#define THR_NEW_LWP 0x00000002 /* unused */ +#define THR_DETACHED 0x00000040 /* PTHREAD_CREATE_DETACHED */ +#define THR_SUSPENDED 0x00000080 +#define THR_DAEMON 0x00000100 + +#define THR_ONCE_KEY (thread_key_t)(-1) + +#define TRS_VALID 0 +#define TRS_NONVOLATILE 1 +#define TRS_LWPID 2 +#define TRS_INVALID 3 + +__BEGIN_DECLS + +extern int thr_create (void *, size_t, void * (*)(void *), void *, long, + thread_t *); + +extern int thr_join (thread_t, thread_t *, void **); + +extern int thr_setconcurrency (int); + +extern int thr_getconcurrency (void); + +extern void thr_exit (void *); + +extern thread_t thr_self (void); + +extern int thr_main (void); + +extern int thr_kill (thread_t, int); + +extern int thr_suspend (thread_t); + +extern int thr_continue (thread_t); + +extern void thr_yield (void); + +extern int thr_setprio (thread_t, int); + +extern int thr_getprio (thread_t, int *); + +extern int thr_keycreate (thread_key_t *, void(*)(void *)); + +extern int thr_keycreate_once (thread_key_t *, void(*)(void *)); + +extern int thr_setspecific (thread_key_t, void *); + +extern int thr_getspecific (thread_key_t, void **); + +extern int thr_sigsetmask (int how, const sigset_t *set, sigset_t *oset); + +extern int thr_stksegment (stack_t *stk); + +__END_DECLS + +#endif /* _THREAD_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/unregister-atfork.c b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/unregister-atfork.c new file mode 100644 index 0000000000..696dda03ea --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/unregister-atfork.c @@ -0,0 +1 @@ +#include <nptl/sysdeps/unix/sysv/linux/unregister-atfork.c> diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86/synchP.h b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86/synchP.h new file mode 100644 index 0000000000..38d76a473a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86/synchP.h @@ -0,0 +1,58 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008. + + 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYNCH_PRIV_H +#define _SYNCH_PRIV_H + +/* mutex helper macros */ +#define mutex_type flags.mbcp_type_un.mtype_rcount.count_type1 +#define mutex_magic flags.magic +#define mutex_flag flags.flag1 +#define mutex_ceiling flags.ceiling +#define mutex_real_ceiling flags.flag2 /* Non-standard; see NOTES.opensolaris */ +#define mutex_rcount flags.mbcp_type_un.mtype_rcount.count_type2 +#define mutex_owner data.data32.owner +#define mutex_lockword32 lock.lock32.lockword +#define mutex_lockword64 lock.owner64 +#define mutex_lockbyte lock.lock64.pad[7] +#define mutex_waiters lock.lock64.pad[6] +#define mutex_cond_waiters data.data32.cond_waiters +#define mutex_ownerpid lock.lock32.ownerpid +#define RECURSION_MAX 255 /* UCHAR_MAX */ +#define LOCKBYTE_SET 0x01 +#define LOCKBYTE_UNSET 0x00 +#define LOCKWORD32_SET_NO_WAITERS 0x01000000 +#define LOCKWORD32_UNSET_NO_WAITERS 0x00000000 +#define LOCKWORD64_SET_NO_WAITERS 0x0100000000000000 +#define LOCKWORD64_UNSET_NO_WAITERS 0x0000000000000000 +#define MUTEX_OWNERPID_SHIFT 0 + +/* condition variable helper macros */ +#define cond_type flags.type +#define cond_magic flags.magic +#define cond_clockid flags.flag[1] +#define cond_waiters_user flags.flag[2] +#define cond_waiters_kernel flags.flag[3] + +/* semaphore helper macros */ +#define sema_count count +#define sema_type type +#define sema_waiters flags[7] + +#endif /* _SYNCH_PRIV_H */ diff --git a/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86_64/Implies b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86_64/Implies new file mode 100644 index 0000000000..b4e16c658e --- /dev/null +++ b/nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86_64/Implies @@ -0,0 +1 @@ +nptl/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/x86 |
