[Glibc-bsd-commits] r4567 - trunk/glibc-ports/kfreebsd/fbtl
Petr Salinger
ps-guest at alioth.debian.org
Mon Jul 8 12:42:46 UTC 2013
Author: ps-guest
Date: 2013-06-22 08:31:32 +0000 (Sat, 22 Jun 2013)
New Revision: 4567
Added:
trunk/glibc-ports/kfreebsd/fbtl/aio_misc.h
trunk/glibc-ports/kfreebsd/fbtl/allocrtsig.c
trunk/glibc-ports/kfreebsd/fbtl/jmp-unwind.c
trunk/glibc-ports/kfreebsd/fbtl/libc-lowlevellock.c
trunk/glibc-ports/kfreebsd/fbtl/lowlevellock.c
trunk/glibc-ports/kfreebsd/fbtl/lowlevelrwlock.sym
Log:
merge some bits from linux nptl
Added: trunk/glibc-ports/kfreebsd/fbtl/aio_misc.h
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/aio_misc.h (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/aio_misc.h 2013-06-22 08:31:32 UTC (rev 4567)
@@ -0,0 +1,65 @@
+/* Copyright (C) 2004-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub at redhat.com>, 2004.
+
+ 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, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _AIO_MISC_H
+# include_next <aio_misc.h>
+# include <limits.h>
+# include <pthread.h>
+# include <signal.h>
+# include <sysdep.h>
+
+# define aio_start_notify_thread __aio_start_notify_thread
+# define aio_create_helper_thread __aio_create_helper_thread
+
+extern inline void
+__aio_start_notify_thread (void)
+{
+ sigset_t ss;
+ sigemptyset (&ss);
+ INLINE_SYSCALL (sigprocmask, err, 3, SIG_SETMASK, &ss, NULL);
+}
+
+extern inline int
+__aio_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_get_minstack (&attr));
+
+ /* 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);
+ INLINE_SYSCALL (sigprocmask, err, 3, SIG_SETMASK, &ss, &oss;
+
+ int ret = pthread_create (threadp, &attr, tf, arg);
+
+ /* Restore the signal mask. */
+ INLINE_SYSCALL (sigprocmask, err, 3, SIG_SETMASK, &oss, NULL);
+
+ (void) pthread_attr_destroy (&attr);
+ return ret;
+}
+#endif
Added: trunk/glibc-ports/kfreebsd/fbtl/allocrtsig.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/allocrtsig.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/allocrtsig.c 2013-06-22 08:31:32 UTC (rev 4567)
@@ -0,0 +1,55 @@
+/* Copyright (C) 2002-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at 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, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <signal.h>
+
+
+static int current_rtmin = __SIGRTMIN + 2;
+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)
Added: trunk/glibc-ports/kfreebsd/fbtl/jmp-unwind.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/jmp-unwind.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/jmp-unwind.c 2013-06-22 08:31:32 UTC (rev 4567)
@@ -0,0 +1,38 @@
+/* Clean up stack frames unwound by longjmp. Linux version.
+ Copyright (C) 1995-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <setjmp.h>
+#include <stddef.h>
+#include <pthreadP.h>
+
+extern void __pthread_cleanup_upto (__jmp_buf env, char *targetframe);
+#pragma weak __pthread_cleanup_upto
+
+
+void
+_longjmp_unwind (jmp_buf env, int val)
+{
+#ifdef SHARED
+ if (__libc_pthread_functions_init)
+ PTHFCT_CALL (ptr___pthread_cleanup_upto, (env->__jmpbuf,
+ CURRENT_STACK_FRAME));
+#else
+ if (__pthread_cleanup_upto != NULL)
+ __pthread_cleanup_upto (env->__jmpbuf, CURRENT_STACK_FRAME);
+#endif
+}
Added: trunk/glibc-ports/kfreebsd/fbtl/libc-lowlevellock.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/libc-lowlevellock.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/libc-lowlevellock.c 2013-06-22 08:31:32 UTC (rev 4567)
@@ -0,0 +1,20 @@
+/* Copyright (C) 2003-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus at au.ibm.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, see
+ <http://www.gnu.org/licenses/>. */
+
+/* No difference to lowlevellock.c, except we lose a couple of functions. */
+#include <lowlevellock.c>
Added: trunk/glibc-ports/kfreebsd/fbtl/lowlevellock.c
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/lowlevellock.c (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/lowlevellock.c 2013-06-22 08:31:32 UTC (rev 4567)
@@ -0,0 +1,124 @@
+/* low level locking for pthread library. Generic futex-using version.
+ Copyright (C) 2003-2013 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Paul Mackerras <paulus at au.ibm.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, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <sysdep.h>
+#include <lowlevellock.h>
+#include <sys/time.h>
+#include <atomic.h>
+
+void
+__lll_lock_wait_private (int *futex)
+{
+ if (*futex == 2)
+ lll_futex_wait (futex, 2, LLL_PRIVATE);
+
+ while (atomic_exchange_acq (futex, 2) != 0)
+ lll_futex_wait (futex, 2, LLL_PRIVATE);
+}
+
+
+/* These functions don't get included in libc.so */
+#ifdef IS_IN_libpthread
+void
+__lll_lock_wait (int *futex, int private)
+{
+ if (*futex == 2)
+ lll_futex_wait (futex, 2, private);
+
+ while (atomic_exchange_acq (futex, 2) != 0)
+ lll_futex_wait (futex, 2, private);
+}
+
+
+int
+__lll_timedlock_wait (int *futex, const struct timespec *abstime, int private)
+{
+ /* Reject invalid timeouts. */
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ /* Try locking. */
+ while (atomic_exchange_acq (futex, 2) != 0)
+ {
+ struct timeval tv;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ struct timespec rt;
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait. */
+ lll_futex_timed_wait (futex, 2, &rt, private);
+ }
+
+ return 0;
+}
+
+
+int
+__lll_timedwait_tid (int *tidp, const struct timespec *abstime)
+{
+ int tid;
+
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return EINVAL;
+
+ /* Repeat until thread terminated. */
+ while ((tid = *tidp) != 0)
+ {
+ struct timeval tv;
+ struct timespec rt;
+
+ /* Get the current time. */
+ (void) __gettimeofday (&tv, NULL);
+
+ /* Compute relative timeout. */
+ rt.tv_sec = abstime->tv_sec - tv.tv_sec;
+ rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+ if (rt.tv_nsec < 0)
+ {
+ rt.tv_nsec += 1000000000;
+ --rt.tv_sec;
+ }
+
+ /* Already timed out? */
+ if (rt.tv_sec < 0)
+ return ETIMEDOUT;
+
+ /* Wait until thread terminates. The kernel so far does not use
+ the private futex operations for this. */
+ if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT)
+ return ETIMEDOUT;
+ }
+
+ return 0;
+}
+#endif
Added: trunk/glibc-ports/kfreebsd/fbtl/lowlevelrwlock.sym
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/lowlevelrwlock.sym (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/lowlevelrwlock.sym 2013-06-22 08:31:32 UTC (rev 4567)
@@ -0,0 +1,16 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <bits/pthreadtypes.h>
+#include <bits/wordsize.h>
+
+--
+
+MUTEX offsetof (pthread_rwlock_t, __data.__lock)
+NR_READERS offsetof (pthread_rwlock_t, __data.__nr_readers)
+READERS_WAKEUP offsetof (pthread_rwlock_t, __data.__readers_wakeup)
+WRITERS_WAKEUP offsetof (pthread_rwlock_t, __data.__writer_wakeup)
+READERS_QUEUED offsetof (pthread_rwlock_t, __data.__nr_readers_queued)
+WRITERS_QUEUED offsetof (pthread_rwlock_t, __data.__nr_writers_queued)
+FLAGS offsetof (pthread_rwlock_t, __data.__flags)
+WRITER offsetof (pthread_rwlock_t, __data.__writer)
+PSHARED offsetof (pthread_rwlock_t, __data.__shared)
More information about the Glibc-bsd-commits
mailing list