diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-03-25 20:41:26 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-03-25 20:41:26 +0000 |
commit | 09402f5bc1d87787c84dbf75d41777c87b1ce40e (patch) | |
tree | d5be40f068434405ba1554389d73460fea0a1a0a /nptl/sysdeps/unix | |
parent | 2a9ae45c3f89b4069e75c53f6dd32e8174b5cfd1 (diff) | |
download | glibc-09402f5bc1d87787c84dbf75d41777c87b1ce40e.tar glibc-09402f5bc1d87787c84dbf75d41777c87b1ce40e.tar.gz glibc-09402f5bc1d87787c84dbf75d41777c87b1ce40e.tar.bz2 glibc-09402f5bc1d87787c84dbf75d41777c87b1ce40e.zip |
Update.
2003-03-25 Ulrich Drepper <drepper@redhat.com>
* csu/tst-atomic.c: Adjust tests to what atomic_add_negative and
atomic_add_zero were supposed to do.
* include/atomic.h: Adjust atomic_add_negative and atomic_add_zero
to x86 behavior.
* sysdeps/generic/bits/typesizes.h (__TIMER_T_TYPE): Define as void*.
This matches the new timer implementation.
* sysdeps/unix/sysv/linux/bits/siginfo.h (struct siginfo): Adjust
timer info for what the kernel provides these days.
(struct sigevent): Add _tid field.
Define SIGEV_THREAD_ID.
* Versions.def (librt): Add GLIBC_2.3.3.
* abilist/libpthread.abilist: Update for nptl.
Diffstat (limited to 'nptl/sysdeps/unix')
35 files changed, 1039 insertions, 6 deletions
diff --git a/nptl/sysdeps/unix/sysv/linux/allocrtsig.c b/nptl/sysdeps/unix/sysv/linux/allocrtsig.c index e3622c6076..265416999a 100644 --- a/nptl/sysdeps/unix/sysv/linux/allocrtsig.c +++ b/nptl/sysdeps/unix/sysv/linux/allocrtsig.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -20,7 +20,7 @@ #include <signal.h> -static int current_rtmin = __SIGRTMIN + 1; +static int current_rtmin = __SIGRTMIN + 2; static int current_rtmax = __SIGRTMAX; diff --git a/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h b/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h index 90564cbfe2..7f44549599 100644 --- a/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h +++ b/nptl/sysdeps/unix/sysv/linux/bits/local_lim.h @@ -73,9 +73,6 @@ /* Minimum size for a thread. We are free to choose a reasonable value. */ #define PTHREAD_STACK_MIN 16384 -/* Maximum number of POSIX timers available. */ -#define TIMER_MAX 256 - /* Maximum number of timer expiration overruns. */ #define DELAYTIMER_MAX 2147483647 diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/Versions b/nptl/sysdeps/unix/sysv/linux/ia64/Versions new file mode 100644 index 0000000000..3b111ddb51 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/ia64/Versions @@ -0,0 +1,7 @@ +librt { + GLIBC_2.3.3 { + # Changed timer_t. + timer_create; timer_delete; timer_getoverrun; timer_gettime; + timer_settime; + } +} diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c b/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c new file mode 100644 index 0000000000..172223af3f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/ia64/timer_create.c @@ -0,0 +1 @@ +#include "../x86_64/timer_create.c" diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c b/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c new file mode 100644 index 0000000000..537516e0aa --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/ia64/timer_delete.c @@ -0,0 +1 @@ +#include "../x86_64/timer_delete.c" diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c b/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c new file mode 100644 index 0000000000..3f21a73c98 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/ia64/timer_getoverr.c @@ -0,0 +1 @@ +#include "../x86_64/timer_getoverr.c" diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c b/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c new file mode 100644 index 0000000000..a50143adc5 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/ia64/timer_gettime.c @@ -0,0 +1 @@ +#include "../x86_64/timer_gettime.c" diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c b/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c new file mode 100644 index 0000000000..37baeffacc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/ia64/timer_settime.c @@ -0,0 +1 @@ +#include "../x86_64/timer_settime.c" diff --git a/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h new file mode 100644 index 0000000000..6e7e029a2d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/kernel-posix-timers.h @@ -0,0 +1,62 @@ +/* Copyright (C) 2003 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; 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 <pthread.h> +#include <setjmp.h> +#include <signal.h> + + +/* Nonzero if the system calls are not available. */ +extern int __no_posix_timers attribute_hidden; + +/* Helper function to implement SIGEV_THREAD. */ +extern void *__timer_helper_thread (void *arg) attribute_hidden; + + +/* Type of timers in the kernel. */ +typedef int kernel_timer_t; + + +/* Internal representation of timer. */ +struct timer +{ + /* Notification mechanism. */ + int sigev_notify; + + /* Timer ID returned by the kernel. */ + kernel_timer_t ktimerid; + + /* All new elements must be added after ktimerid. And if the thrfunc + element is not the third element anymore the memory allocation in + timer_create needs to be changed. */ + + /* Parameters for the thread to be started for SIGEV_THREAD. */ + void (*thrfunc) (sigval_t); + sigval_t sival; + pthread_attr_t attr; + + /* Id of the helper thread. */ + pthread_t th; + + /* Barrier used for synchronization. */ + pthread_barrier_t bar; +}; + +/* This is the signal the kernel will send to the helper thread. */ +#define TIMER_SIG 40 /* some RT signal */ diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions new file mode 100644 index 0000000000..3b111ddb51 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/Versions @@ -0,0 +1,7 @@ +librt { + GLIBC_2.3.3 { + # Changed timer_t. + timer_create; timer_delete; timer_getoverrun; timer_gettime; + timer_settime; + } +} diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c new file mode 100644 index 0000000000..172223af3f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_create.c @@ -0,0 +1 @@ +#include "../x86_64/timer_create.c" diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c new file mode 100644 index 0000000000..537516e0aa --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_delete.c @@ -0,0 +1 @@ +#include "../x86_64/timer_delete.c" diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c new file mode 100644 index 0000000000..3f21a73c98 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_getoverr.c @@ -0,0 +1 @@ +#include "../x86_64/timer_getoverr.c" diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c new file mode 100644 index 0000000000..a50143adc5 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_gettime.c @@ -0,0 +1 @@ +#include "../x86_64/timer_gettime.c" diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c new file mode 100644 index 0000000000..37baeffacc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/timer_settime.c @@ -0,0 +1 @@ +#include "../x86_64/timer_settime.c" diff --git a/nptl/sysdeps/unix/sysv/linux/pthread_kill.c b/nptl/sysdeps/unix/sysv/linux/pthread_kill.c index a35a3f025b..8da195aa0a 100644 --- a/nptl/sysdeps/unix/sysv/linux/pthread_kill.c +++ b/nptl/sysdeps/unix/sysv/linux/pthread_kill.c @@ -37,7 +37,7 @@ __pthread_kill (threadid, signo) return ESRCH; /* Disallow sending the signal we use for cancellation. */ - if (signo == SIGCANCEL) + if (signo == SIGCANCEL || signo == SIGTIMER) return EINVAL; /* We have a special syscall to do the work. */ diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions new file mode 100644 index 0000000000..3b111ddb51 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/Versions @@ -0,0 +1,7 @@ +librt { + GLIBC_2.3.3 { + # Changed timer_t. + timer_create; timer_delete; timer_getoverrun; timer_gettime; + timer_settime; + } +} diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c new file mode 100644 index 0000000000..172223af3f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_create.c @@ -0,0 +1 @@ +#include "../x86_64/timer_create.c" diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c new file mode 100644 index 0000000000..537516e0aa --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_delete.c @@ -0,0 +1 @@ +#include "../x86_64/timer_delete.c" diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c new file mode 100644 index 0000000000..3f21a73c98 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_getoverr.c @@ -0,0 +1 @@ +#include "../x86_64/timer_getoverr.c" diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c new file mode 100644 index 0000000000..a50143adc5 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_gettime.c @@ -0,0 +1 @@ +#include "../x86_64/timer_gettime.c" diff --git a/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c new file mode 100644 index 0000000000..37baeffacc --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/s390/s390-64/timer_settime.c @@ -0,0 +1 @@ +#include "../x86_64/timer_settime.c" diff --git a/nptl/sysdeps/unix/sysv/linux/timer_create.c b/nptl/sysdeps/unix/sysv/linux/timer_create.c new file mode 100644 index 0000000000..637d925168 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/timer_create.c @@ -0,0 +1,235 @@ +/* Copyright (C) 2003 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; 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 <pthread.h> +#include <signal.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sysdep.h> +#include <kernel-features.h> +#include <internaltypes.h> +#include "kernel-posix-timers.h" + + +#ifdef __NR_timer_create +# ifndef __ASSUME_POSIX_TIMERS +# define timer_create static compat_timer_create +# include <nptl/sysdeps/pthread/timer_create.c> +# undef timer_create + +/* Nonzero if the system calls are not available. */ +int __no_posix_timers attribute_hidden; +# endif + +# ifdef timer_create_alias +# define timer_create timer_create_alias +# endif + + +int +timer_create (clock_id, evp, timerid) + clockid_t clock_id; + struct sigevent *evp; + timer_t *timerid; +{ +# undef timer_create +# ifndef __ASSUME_POSIX_TIMERS + if (__no_posix_timers >= 0) +# endif + { + /* If the user wants notification via a thread we need to handle + this special. */ + if (evp == NULL + || __builtin_expect (evp->sigev_notify != SIGEV_THREAD, 1)) + { + kernel_timer_t ktimerid; + int retval = INLINE_SYSCALL (timer_create, 3, clock_id, evp, + &ktimerid); + +# ifndef __ASSUME_POSIX_TIMERS + if (retval != -1 || errno != ENOSYS) +# endif + { +# ifndef __ASSUME_POSIX_TIMERS + __no_posix_timers = 1; +#endif + + if (retval != -1) + { + struct timer *newp; + + /* We avoid allocating too much memory by basically + using struct timer as a derived class with the + first two elements being in the superclass. We only + need these two elements here. */ + newp = (struct timer *) malloc (offsetof (struct timer, + thrfunc)); + if (newp != NULL) + { + newp->sigev_notify = (evp != NULL + ? evp->sigev_notify + : SIGEV_SIGNAL); + newp->ktimerid = ktimerid; + + *timerid = (timer_t) newp; + } + else + { + /* No memory. Free the kernel timer. */ + INTERNAL_SYSCALL_DECL (err); + (void) INTERNAL_SYSCALL (timer_delete, err, 1, ktimerid); + + retval = -1; + } + } + + return retval; + } + } + else + { +#ifndef __ASSUME_POSIX_TIMERS + /* Make sure we have the necessary kernel support. */ + if (__no_posix_timers == 0) + { + INTERNAL_SYSCALL_DECL (err); + struct timespec ts; + int res = INTERNAL_SYSCALL (clock_getres, err, 1, &ts); + __no_posix_timers = (INTERNAL_SYSCALL_ERROR_P (res, err) + ? -1 : 1); + } + + if (__no_posix_timers > 0) +#endif + { + sigset_t ss; + sigemptyset (&ss); + sigaddset (&ss, TIMER_SIG); + pthread_sigmask (SIG_BLOCK, &ss, NULL); + struct timer *newp; + + newp = (struct timer *) malloc (sizeof (struct timer)); + if (newp == NULL) + return -1; + + /* Copy the thread parameters the user provided. */ + newp->sival = evp->sigev_value; + newp->thrfunc = evp->sigev_notify_function; + + /* We cannot simply copy the thread attributes since the + implementation might keep internal information for + each instance. */ + (void) pthread_attr_init (&newp->attr); + if (evp->sigev_notify_attributes != NULL) + { + struct pthread_attr *nattr; + struct pthread_attr *oattr; + + nattr = (struct pthread_attr *) &newp->attr; + oattr = (struct pthread_attr *) evp->sigev_notify_attributes; + + nattr->schedparam = oattr->schedparam; + nattr->schedpolicy = oattr->schedpolicy; + nattr->flags = oattr->flags; + nattr->guardsize = oattr->guardsize; + nattr->stackaddr = oattr->stackaddr; + nattr->stacksize = oattr->stacksize; + } + + /* In any case set the detach flag. */ + (void) pthread_attr_setdetachstate (&newp->attr, + PTHREAD_CREATE_DETACHED); + + /* Set up the barrier for sychronization. */ + (void) pthread_barrier_init (&newp->bar, NULL, 2); + + /* The helper thread needs only very little resources + and should go away automatically when canceled. */ + pthread_attr_t attr; + (void) pthread_attr_init (&attr); + (void) pthread_attr_setdetachstate (&attr, + PTHREAD_CREATE_DETACHED); + (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); + + /* Create the helper thread for this timer. */ + int res = pthread_create (&newp->th, &attr, + __timer_helper_thread, newp); + if (res != 0) + goto err_out; + + /* No need for the attribute anymore. */ + (void) pthread_attr_destroy (&attr); + + /* Create the event structure for the kernel timer. */ + struct sigevent sev; + sev.sigev_value.sival_ptr = newp; + sev.sigev_signo = TIMER_SIG; + sev.sigev_notify = SIGEV_SIGNAL | SIGEV_THREAD_ID; + /* This is the thread ID of the helper thread. */ + sev._sigev_un._pad[0] = ((struct pthread *) newp->th)->tid; + + /* Wait until the helper thread is set up. */ + (void) pthread_barrier_wait (&newp->bar); + + /* No need for the barrier anymore. */ + (void) pthread_barrier_destroy (&newp->bar); + + /* Create the timer. */ + INTERNAL_SYSCALL_DECL (err); + res = INTERNAL_SYSCALL (timer_create, err, 3, clock_id, &sev, + &newp->ktimerid); + if (! INTERNAL_SYSCALL_ERROR_P (res, err)) + { + *timerid = (timer_t) newp; + return 0; + } + + /* Something went wrong. Kill the thread. */ + pthread_cancel (newp->th); + /* Free the resources. */ + res = INTERNAL_SYSCALL_ERRNO (res, err); + err_out: + free (newp); + __set_errno (res); + return -1; + } + } + +# ifndef __ASSUME_POSIX_TIMERS + /* When we come here the syscall does not exist. Make sure we + do not try to use it again. */ + __no_posix_timers = -1; +# endif + } + +# ifndef __ASSUME_POSIX_TIMERS + /* Compatibility code. */ + return compat_timer_create (clock_id, evp, timerid); +# endif +} +#else +# ifdef timer_create_alias +# define timer_create timer_create_alias +# endif +/* The new system calls are not available. Use the userlevel + implementation. */ +# include <nptl/sysdeps/pthread/timer_create.c> +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/timer_delete.c b/nptl/sysdeps/unix/sysv/linux/timer_delete.c new file mode 100644 index 0000000000..cf63364253 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/timer_delete.c @@ -0,0 +1,94 @@ +/* Copyright (C) 2003 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; 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 <stdlib.h> +#include <time.h> +#include <sysdep.h> +#include <kernel-features.h> +#include "kernel-posix-timers.h" + + +#ifdef __NR_timer_delete +# ifndef __ASSUME_POSIX_TIMERS +# define timer_delete static compat_timer_delete +# include <nptl/sysdeps/pthread/timer_delete.c> +# undef timer_delete +# endif + +# ifdef timer_delete_alias +# define timer_delete timer_delete_alias +# endif + + +int +timer_delete (timerid) + timer_t timerid; +{ +# undef timer_delete +# ifndef __ASSUME_POSIX_TIMERS + if (__no_posix_timers >= 0) +# endif + { + struct timer *kt = (struct timer *) timerid; + + /* Delete the kernel timer object. */ + int res = INLINE_SYSCALL (timer_delete, 1, kt->ktimerid); + + if (res == 0) + { +# ifndef __ASSUME_POSIX_TIMERS + /* We know the syscall support is available. */ + __no_posix_timers = 1; +# endif + + /* We have to get rid of the helper thread if we created one. */ + if (kt->sigev_notify == SIGEV_THREAD) + (void) pthread_cancel (kt->th); + + /* Free the memory. */ + (void) free (kt); + + return 0; + } + + /* The kernel timer is not known or something else bad happened. + Return the error. */ +# ifndef __ASSUME_POSIX_TIMERS + if (errno != ENOSYS) +# endif + return -1; + +# ifndef __ASSUME_POSIX_TIMERS + __no_posix_timers = -1; +# endif + } + +# ifndef __ASSUME_POSIX_TIMERS + return compat_timer_delete (timerid); +# endif +} +#else +# ifdef timer_delete_alias +# define timer_delete timer_delete_alias +# endif +/* The new system calls are not available. Use the userlevel + implementation. */ +# include <nptl/sysdeps/pthread/timer_delete.c> +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c b/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c new file mode 100644 index 0000000000..40b485f560 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/timer_getoverr.c @@ -0,0 +1,80 @@ +/* Copyright (C) 2003 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; 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 <time.h> +#include <sysdep.h> +#include <kernel-features.h> +#include "kernel-posix-timers.h" + + +#ifdef __NR_timer_getoverrun +# ifndef __ASSUME_POSIX_TIMERS +# define timer_getoverrun static compat_timer_getoverrun +# include <nptl/sysdeps/pthread/timer_getoverrun.c> +# undef timer_getoverrun +# endif + +# ifdef timer_getoverrun_alias +# define timer_getoverrun timer_getoverrun_alias +# endif + + +int +timer_getoverrun (timerid) + timer_t timerid; +{ +# undef timer_getoverrun +# ifndef __ASSUME_POSIX_TIMERS + if (__no_posix_timers == 0) +# endif + { + struct timer *kt = (struct timer *) timerid; + + /* Get the information from the kernel. */ + int res = INLINE_SYSCALL (timer_getoverrun, 1, kt->ktimerid); + +# ifndef __ASSUME_POSIX_TIMERS + if (res != -1 || errno != ENOSYS) + { + /* We know the syscall support is available. */ + __no_posix_timers = 1; +# endif + return res; +# ifndef __ASSUME_POSIX_TIMERS + } +# endif + +# ifndef __ASSUME_POSIX_TIMERS + __no_posix_timers = -1; +# endif + } + +# ifndef __ASSUME_POSIX_TIMERS + return compat_timer_getoverrun (timerid); +# endif +} +#else +# ifdef timer_getoverrun_alias +# define timer_getoverrun timer_getoverrun_alias +# endif +/* The new system calls are not available. Use the userlevel + implementation. */ +# include <nptl/sysdeps/pthread/timer_getoverr.c> +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/timer_gettime.c b/nptl/sysdeps/unix/sysv/linux/timer_gettime.c new file mode 100644 index 0000000000..6da15718ed --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/timer_gettime.c @@ -0,0 +1,82 @@ +/* Copyright (C) 2003 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; 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 <stdlib.h> +#include <time.h> +#include <sysdep.h> +#include <kernel-features.h> +#include "kernel-posix-timers.h" + + +#ifdef __NR_timer_gettime +# ifndef __ASSUME_POSIX_TIMERS +# define timer_gettime static compat_timer_gettime +# include <nptl/sysdeps/pthread/timer_gettime.c> +# undef timer_gettime +# endif + +# ifdef timer_gettime_alias +# define timer_gettime timer_gettime_alias +# endif + + +int +timer_gettime (timerid, value) + timer_t timerid; + struct itimerspec *value; +{ +# undef timer_gettime +# ifndef __ASSUME_POSIX_TIMERS + if (__no_posix_timers == 0) +# endif + { + struct timer *kt = (struct timer *) timerid; + + /* Delete the kernel timer object. */ + int res = INLINE_SYSCALL (timer_gettime, 2, kt->ktimerid, value); + +# ifndef __ASSUME_POSIX_TIMERS + if (res != -1 || errno != ENOSYS) + { + /* We know the syscall support is available. */ + __no_posix_timers = 1; +# endif + return res; +# ifndef __ASSUME_POSIX_TIMERS + } +# endif + +# ifndef __ASSUME_POSIX_TIMERS + __no_posix_timers = -1; +# endif + } + +# ifndef __ASSUME_POSIX_TIMERS + return compat_timer_gettime (timerid, value); +# endif +} +#else +# ifdef timer_gettime_alias +# define timer_gettime timer_gettime_alias +# endif +/* The new system calls are not available. Use the userlevel + implementation. */ +# include <nptl/sysdeps/pthread/timer_gettime.c> +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/timer_routines.c b/nptl/sysdeps/unix/sysv/linux/timer_routines.c new file mode 100644 index 0000000000..3f69aa64fd --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/timer_routines.c @@ -0,0 +1,81 @@ +/* Copyright (C) 2003 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; 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 <setjmp.h> +#include <signal.h> +#include <stdbool.h> +#include <sysdep.h> +#include <kernel-features.h> +#include "kernel-posix-timers.h" + + +#ifdef __NR_timer_create +/* Helper thread to call the user-provided function. */ +static void * +timer_sigev_thread (void *arg) +{ + struct timer *tk = (struct timer *) arg; + + /* Call the user-provided function. */ + tk->thrfunc (tk->sival); + + return NULL; +} + + +/* Helper function to support starting threads for SIGEV_THREAD. */ +void * +attribute_hidden +__timer_helper_thread (void *arg) +{ + /* Block all signals. */ + sigset_t ss; + + sigfillset (&ss); + (void) pthread_sigmask (SIG_BLOCK, &ss, NULL); + + struct timer *tk = (struct timer *) arg; + + /* Synchronize with the parent. */ + (void) pthread_barrier_wait (&tk->bar); + + /* We will only wait for the signal the kernel will send. */ + sigemptyset (&ss); + sigaddset (&ss, TIMER_SIG); + + /* Endless loop of waiting for signals. The loop is only ended when + the thread is canceled. */ + while (1) + { + siginfo_t si; + + if (sigwaitinfo (&ss, &si) > 0 && si.si_timerid == tk->ktimerid) + { + /* That the signal we are waiting for. */ + pthread_t th; + (void) pthread_create (&th, &tk->attr, timer_sigev_thread, arg); + } + } +} + +#endif + +#ifndef __ASSUME_POSIX_TIMERS +# include <nptl/sysdeps/pthread/timer_routines.c> +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/timer_settime.c b/nptl/sysdeps/unix/sysv/linux/timer_settime.c new file mode 100644 index 0000000000..7fc837cb5d --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/timer_settime.c @@ -0,0 +1,85 @@ +/* Copyright (C) 2003 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; 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 <stdlib.h> +#include <time.h> +#include <sysdep.h> +#include <kernel-features.h> +#include "kernel-posix-timers.h" + + +#ifdef __NR_timer_settime +# ifndef __ASSUME_POSIX_TIMERS +# define timer_settime static compat_timer_settime +# include <nptl/sysdeps/pthread/timer_settime.c> +# undef timer_settime +# endif + +# ifdef timer_settime_alias +# define timer_settime timer_settime_alias +# endif + + +int +timer_settime (timerid, flags, value, ovalue) + timer_t timerid; + int flags; + const struct itimerspec *value; + struct itimerspec *ovalue; +{ +# undef timer_settime +# ifndef __ASSUME_POSIX_TIMERS + if (__no_posix_timers == 0) +# endif + { + struct timer *kt = (struct timer *) timerid; + + /* Delete the kernel timer object. */ + int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags, + value, ovalue); + +# ifndef __ASSUME_POSIX_TIMERS + if (res != -1 || errno != ENOSYS) + { + /* We know the syscall support is available. */ + __no_posix_timers = 1; +# endif + return res; +# ifndef __ASSUME_POSIX_TIMERS + } +# endif + +# ifndef __ASSUME_POSIX_TIMERS + __no_posix_timers = 1; +# endif + } + +# ifndef __ASSUME_POSIX_TIMERS + return compat_timer_settime (timerid, flags, value, ovalue); +# endif +} +#else +# ifdef timer_settime_alias +# define timer_settime timer_settime_alias +# endif +/* The new system calls are not available. Use the userlevel + implementation. */ +# include <nptl/sysdeps/pthread/timer_settime.c> +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/Versions b/nptl/sysdeps/unix/sysv/linux/x86_64/Versions new file mode 100644 index 0000000000..3b111ddb51 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/Versions @@ -0,0 +1,7 @@ +librt { + GLIBC_2.3.3 { + # Changed timer_t. + timer_create; timer_delete; timer_getoverrun; timer_gettime; + timer_settime; + } +} diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h b/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h new file mode 100644 index 0000000000..02485daa50 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/compat-timer.h @@ -0,0 +1,46 @@ +/* Copyright (C) 2003 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; 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 <signal.h> +#include <time.h> +#include <sys/types.h> + +#define OLD_TIMER_MAX 256 + +extern timer_t __compat_timer_list[OLD_TIMER_MAX] attribute_hidden; + + +extern int __timer_create_new (clockid_t clock_id, struct sigevent *evp, + timer_t *timerid); +extern int __timer_delete_new (timer_t timerid); +extern int __timer_getoverrun_new (timer_t timerid); +extern int __timer_gettime_new (timer_t timerid, struct itimerspec *value); +extern int __timer_settime_new (timer_t timerid, int flags, + const struct itimerspec *value, + struct itimerspec *ovalue); + + +extern int __timer_create_old (clockid_t clock_id, struct sigevent *evp, + int *timerid); +extern int __timer_delete_old (int timerid); +extern int __timer_getoverrun_old (int timerid); +extern int __timer_gettime_old (int timerid, struct itimerspec *value); +extern int __timer_settime_old (int timerid, int flags, + const struct itimerspec *value, + struct itimerspec *ovalue); diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c new file mode 100644 index 0000000000..1849f72a48 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_create.c @@ -0,0 +1,66 @@ +/* Copyright (C) 2003 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; 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 <shlib-compat.h> +#include "compat-timer.h" +#include <atomic.h> + + +#define timer_create_alias __timer_create_new +#include "../timer_create.c" + +#undef timer_create +versioned_symbol (librt, __timer_create_new, timer_create, GLIBC_2_3_3); + + +#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3) +timer_t __compat_timer_list[OLD_TIMER_MAX] attribute_hidden; + + +int +__timer_create_old (clockid_t clock_id, struct sigevent *evp, int *timerid) +{ + timer_t newp; + + int res = __timer_create_new (clock_id, evp, &newp); + if (res == 0) + { + int i; + for (i = 0; i < OLD_TIMER_MAX; ++i) + if (__compat_timer_list[i] == NULL + && ! atomic_compare_and_exchange_bool_acq (&__compat_timer_list[i], + newp, NULL)) + { + *timerid = i; + break; + } + + if (__builtin_expect (i == OLD_TIMER_MAX, 0)) + { + /* No free slot. */ + (void) __timer_delete_new (newp); + __set_errno (EINVAL); + res = -1; + } + } + + return res; +} +compat_symbol (librt, __timer_create_old, timer_create, GLIBC_2_2); +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c new file mode 100644 index 0000000000..6e0d9d0334 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_delete.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2003 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; 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 <shlib-compat.h> +#include "compat-timer.h" + + +#define timer_delete_alias __timer_delete_new +#include "../timer_delete.c" + +#undef timer_delete +versioned_symbol (librt, __timer_delete_new, timer_delete, GLIBC_2_3_3); + + +#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3) +int +__timer_delete_old (int timerid) +{ + int res = __timer_delete_new (__compat_timer_list[timerid]); + + if (res == 0) + /* Successful timer deletion, now free the index. We only need to + store a word and that better be atomic. */ + __compat_timer_list[timerid] = NULL; + + return res; +} +compat_symbol (librt, __timer_delete_old, timer_delete, GLIBC_2_2); +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c new file mode 100644 index 0000000000..d75636c99a --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_getoverr.c @@ -0,0 +1,39 @@ +/* Copyright (C) 2003 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; 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 <shlib-compat.h> +#include "compat-timer.h" + + +#define timer_getoverrun_alias __timer_getoverrun_new +#include "../timer_getoverr.c" + +#undef timer_getoverrun +versioned_symbol (librt, __timer_getoverrun_new, timer_getoverrun, + GLIBC_2_3_3); + + +#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3) +int +__timer_getoverrun_old (int timerid) +{ + return __timer_getoverrun_new (__compat_timer_list[timerid]); +} +compat_symbol (librt, __timer_getoverrun_old, timer_getoverrun, GLIBC_2_2); +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c new file mode 100644 index 0000000000..1f1253af2f --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_gettime.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2003 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; 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 <shlib-compat.h> +#include "compat-timer.h" + + +#define timer_gettime_alias __timer_gettime_new +#include "../timer_gettime.c" + +#undef timer_gettime +versioned_symbol (librt, __timer_gettime_new, timer_gettime, GLIBC_2_3_3); + + +#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3) +int +__timer_gettime_old (int timerid, struct itimerspec *value) +{ + return __timer_gettime_new (__compat_timer_list[timerid], value); +} +compat_symbol (librt, __timer_gettime_old, timer_gettime, GLIBC_2_2); +#endif diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c new file mode 100644 index 0000000000..4c945ec514 --- /dev/null +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/timer_settime.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2003 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; 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 <shlib-compat.h> +#include "compat-timer.h" + + +#define timer_settime_alias __timer_settime_new +#include "../timer_settime.c" + +#undef timer_settime +versioned_symbol (librt, __timer_settime_new, timer_settime, GLIBC_2_3_3); + + +#if SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3) +int +__timer_settime_old (int timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue) +{ + return __timer_settime_new (__compat_timer_list[timerid], flags, + value, ovalue); +} +compat_symbol (librt, __timer_settime_old, timer_settime, GLIBC_2_2); +#endif |