[Glibc-bsd-commits] r4637 - trunk/glibc-ports/kfreebsd/fbtl

Petr Salinger ps-guest at alioth.debian.org
Mon Jul 8 12:47:59 UTC 2013


Author: ps-guest
Date: 2013-06-28 13:58:30 +0000 (Fri, 28 Jun 2013)
New Revision: 4637

Added:
   trunk/glibc-ports/kfreebsd/fbtl/kernel-posix-timers.h
   trunk/glibc-ports/kfreebsd/fbtl/timer_create.c
   trunk/glibc-ports/kfreebsd/fbtl/timer_delete.c
   trunk/glibc-ports/kfreebsd/fbtl/timer_getoverr.c
   trunk/glibc-ports/kfreebsd/fbtl/timer_gettime.c
   trunk/glibc-ports/kfreebsd/fbtl/timer_routines.c
   trunk/glibc-ports/kfreebsd/fbtl/timer_settime.c
Log:
svn copy linuxthreads/*timer* fbtl/



Copied: trunk/glibc-ports/kfreebsd/fbtl/kernel-posix-timers.h (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/kernel-posix-timers.h)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/kernel-posix-timers.h	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/kernel-posix-timers.h	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,126 @@
+/* Copyright (C) 2003, 2007, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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>
+#include <sys/types.h>
+#include <sys/_types.h>
+
+/* The signal used for asynchronous cancelation.  */
+#define SIGCANCEL	(PTHREAD_SIGBASE + 1)
+
+/* Signal needed for the kernel-supported POSIX timer implementation.
+   We can reuse the cancellation signal since we can distinguish
+   cancellation from timer expirations.  */
+#define SIGTIMER	SIGCANCEL
+
+/* Nonzero if the system calls are not available.  */
+extern int __no_posix_timers attribute_hidden;
+
+/* Callback to start helper thread.  */
+extern void __start_helper_thread (void) attribute_hidden;
+
+/* Control variable for helper thread creation.  */
+extern pthread_once_t __helper_once attribute_hidden;
+
+/* TID of the helper thread.  */
+extern __lwpid_t __helper_tid attribute_hidden;
+
+/* List of active SIGEV_THREAD timers.  */
+extern struct timer *__active_timer_sigev_thread attribute_hidden;
+/* Lock for the __active_timer_sigev_thread.  */
+extern pthread_mutex_t __active_timer_sigev_thread_lock 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;
+
+  /* Next element in list of active SIGEV_THREAD timers.  */
+  struct timer *next;
+};
+
+extern struct timer *__all_timers[TIMER_MAX];
+
+static inline struct timer *
+__kfreebsd_timer_alloc ()
+{
+  unsigned int i;
+  struct timer *timer = malloc (sizeof (struct timer));
+
+  /* Find a free slot (and reserve it atomically).  */
+  for (i = 0; i < TIMER_MAX; i++)
+    if (atomic_compare_and_exchange_val_acq (&__all_timers[i],
+					     timer, NULL) == NULL)
+      return timer;
+
+  errno = EAGAIN;
+  return NULL;
+}
+
+static inline struct timer *
+__kfreebsd_timer_id2ptr (timer_t id)
+{
+  void *ret = NULL;
+
+  if (id >= 0 && id < TIMER_MAX)
+    ret = __all_timers[id];
+
+  if (! ret)
+    errno = EINVAL;
+
+  return ret;
+}
+
+static inline timer_t
+__kfreebsd_timer_ptr2id (struct timer *ptr)
+{
+  unsigned int i;
+  for (i = 0; i < TIMER_MAX; i++)
+    if (__all_timers[i] == ptr)
+      return i;
+
+  return -1;
+}
+
+void static inline
+__kfreebsd_timer_free (struct timer *ptr)
+{
+  __all_timers[__kfreebsd_timer_ptr2id (ptr)] = NULL;
+  free (ptr);
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/timer_create.c (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/timer_create.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/timer_create.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/timer_create.c	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,165 @@
+/* Copyright (C) 2003,2004, 2007, 2009, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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 "kernel-posix-timers.h"
+#include "kernel-posix-cpu-timers.h"
+
+
+int
+timer_create (clock_id, evp, timerid)
+     clockid_t clock_id;
+     struct sigevent *evp;
+     timer_t *timerid;
+{
+    {
+      /* 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))
+	{
+	  struct sigevent local_evp;
+
+	  struct timer *newp = __kfreebsd_timer_alloc ();
+
+	  if (newp == NULL)
+	    /* No more memory.  */
+	    return -1;
+
+	  if (evp == NULL)
+	    {
+	      /* The kernel has to pass up the timer ID which is a
+		 userlevel object.  Therefore we cannot leave it up to
+		 the kernel to determine it.  */
+	      local_evp.sigev_notify = SIGEV_SIGNAL;
+	      local_evp.sigev_signo = SIGALRM;
+	      local_evp.sigev_value.sival_int = __kfreebsd_timer_ptr2id (newp);
+
+	      evp = &local_evp;
+	    }
+
+	  kernel_timer_t ktimerid;
+	  int retval = INLINE_SYSCALL (ktimer_create, 3, clock_id, evp,
+				       &ktimerid);
+
+	    {
+
+	      if (retval != -1)
+		{
+		  newp->sigev_notify = (evp != NULL
+					? evp->sigev_notify : SIGEV_SIGNAL);
+		  newp->ktimerid = ktimerid;
+
+		  *timerid = __kfreebsd_timer_ptr2id (newp);
+		}
+	      else
+		{
+		  /* Cannot allocate the timer, fail.  */
+		  __kfreebsd_timer_free (newp);
+		  retval = -1;
+		}
+
+	      return retval;
+	    }
+	}
+      else
+	{
+	    {
+	      /* Create the helper thread.  */
+	      pthread_once (&__helper_once, __start_helper_thread);
+	      if (__helper_tid == 0)
+		{
+		  /* No resources to start the helper thread.  */
+		  __set_errno (EAGAIN);
+		  return -1;
+		}
+
+	      struct timer *newp;
+	      newp = __kfreebsd_timer_alloc ();
+	      if (newp == NULL)
+		return -1;
+
+	      /* Copy the thread parameters the user provided.  */
+	      newp->sival = evp->sigev_value;
+	      newp->thrfunc = evp->sigev_notify_function;
+	      newp->sigev_notify = SIGEV_THREAD;
+
+	      /* 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)
+		{
+		  pthread_attr_t *nattr;
+		  pthread_attr_t *oattr;
+
+		  nattr = (pthread_attr_t *) &newp->attr;
+		  oattr = (pthread_attr_t *) evp->sigev_notify_attributes;
+
+		  nattr->__schedparam = oattr->__schedparam;
+		  nattr->__schedpolicy = oattr->__schedpolicy;
+		  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);
+
+	      /* Create the event structure for the kernel timer.  */
+	      struct sigevent sev =
+		{ .sigev_value.sival_ptr = newp,
+		  .sigev_signo = SIGTIMER,
+		  .sigev_notify = SIGEV_THREAD_ID,
+		  .sigev_notify_thread_id = __helper_tid,
+		};
+
+	      /* Create the timer.  */
+	      int res;
+	      res = INLINE_SYSCALL (ktimer_create, 3,
+				      clock_id, &sev, &newp->ktimerid);
+	      if (res != -1)
+		{
+		  /* Add to the queue of active timers with thread
+		     delivery.  */
+		  pthread_mutex_lock (&__active_timer_sigev_thread_lock);
+		  newp->next = __active_timer_sigev_thread;
+		  __active_timer_sigev_thread = newp;
+		  pthread_mutex_unlock (&__active_timer_sigev_thread_lock);
+
+		  *timerid = __kfreebsd_timer_ptr2id (newp);
+		  return 0;
+		}
+
+	      /* Free the resources.  */
+	      __kfreebsd_timer_free (newp);
+
+	      return -1;
+	    }
+	}
+    }
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/timer_delete.c (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/timer_delete.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/timer_delete.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/timer_delete.c	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,71 @@
+/* Copyright (C) 2003, 2007, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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"
+
+
+int
+timer_delete (timerid)
+     timer_t timerid;
+{
+      struct timer *kt = __kfreebsd_timer_id2ptr (timerid);
+      if (! kt)
+	return -1;
+
+      /* Delete the kernel timer object.  */
+      int res = INLINE_SYSCALL (ktimer_delete, 1, kt->ktimerid);
+
+      if (res == 0)
+	{
+	  if (kt->sigev_notify == SIGEV_THREAD)
+	    {
+	      /* Remove the timer from the list.  */
+	      pthread_mutex_lock (&__active_timer_sigev_thread_lock);
+	      if (__active_timer_sigev_thread == kt)
+		__active_timer_sigev_thread = kt->next;
+	      else
+		{
+		  struct timer *prevp = __active_timer_sigev_thread;
+		  while (prevp->next != NULL)
+		    if (prevp->next == kt)
+		      {
+			prevp->next = kt->next;
+			break;
+		      }
+		    else
+		      prevp = prevp->next;
+		}
+	      pthread_mutex_unlock (&__active_timer_sigev_thread_lock);
+	    }
+
+	  /* Free the memory.  */
+	  (void) __kfreebsd_timer_free (kt);
+
+	  return 0;
+	}
+
+      /* The kernel timer is not known or something else bad happened.
+	 Return the error.  */
+	  return -1;
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/timer_getoverr.c (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/timer_getoverr.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/timer_getoverr.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/timer_getoverr.c	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,37 @@
+/* Copyright (C) 2003, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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"
+
+
+int
+timer_getoverrun (timerid)
+     timer_t timerid;
+{
+      struct timer *kt = __kfreebsd_timer_id2ptr (timerid);
+      if (! kt)
+	return -1;
+
+      /* Get the information from the kernel.  */
+      return INLINE_SYSCALL (ktimer_getoverrun, 1, kt->ktimerid);
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/timer_gettime.c (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/timer_gettime.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/timer_gettime.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/timer_gettime.c	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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"
+
+
+int
+timer_gettime (timerid, value)
+     timer_t timerid;
+     struct itimerspec *value;
+{
+      struct timer *kt = __kfreebsd_timer_id2ptr (timerid);
+      if (! kt)
+	return -1;
+
+      /* Delete the kernel timer object.  */
+      return INLINE_SYSCALL (ktimer_gettime, 2, kt->ktimerid, value);
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/timer_routines.c (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/timer_routines.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/timer_routines.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/timer_routines.c	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,208 @@
+/* Copyright (C) 2003, 2004, 2005, 2006, 2007, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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 <setjmp.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <sysdep.h>
+#include <sys/_types.h> /* __lwpid_t */
+#include <atomic.h>
+#include <kernel-features.h>
+#include <linuxthreads/internals.h>	/* LIBC_CANCEL_ASYNC */
+#include <semaphore.h>
+#include "kernel-posix-timers.h"
+
+/* NPTL/Linux simply casts "timer_t" to "struct timer *", but on
+   kFreeBSD timer_t may not be large enough to hold a pointer.
+   So we store the pointers here... (sigh) */
+struct timer *__all_timers[TIMER_MAX];
+
+/* List of active SIGEV_THREAD timers.  */
+struct timer *__active_timer_sigev_thread;
+/* Lock for the __active_timer_sigev_thread.  */
+pthread_mutex_t __active_timer_sigev_thread_lock = PTHREAD_MUTEX_INITIALIZER;
+
+
+struct thread_start_data
+{
+  void (*thrfunc) (sigval_t);
+  sigval_t sival;
+};
+
+/* TID of the helper thread.  */
+__lwpid_t __helper_tid attribute_hidden;
+sem_t __helper_tid_semaphore attribute_hidden;
+
+/* Helper thread to call the user-provided function.  */
+static void *
+timer_sigev_thread (void *arg)
+{
+  /* The parent thread has all signals blocked.  This is a bit
+     surprising for user code, although valid.  We unblock all
+     signals.  */
+  sigset_t ss;
+  sigemptyset (&ss);
+  sigprocmask (SIG_SETMASK, &ss, NULL);
+
+  struct thread_start_data *td = (struct thread_start_data *) arg;
+
+  void (*thrfunc) (sigval_t) = td->thrfunc;
+  sigval_t sival = td->sival;
+
+  /* The TD object was allocated in timer_helper_thread.  */
+  free (td);
+
+  /* Call the user-provided function.  */
+  thrfunc (sival);
+
+  return NULL;
+}
+
+
+/* Helper function to support starting threads for SIGEV_THREAD.  */
+static void *
+timer_helper_thread (void *arg)
+{
+  /* Wait for the SIGTIMER signal, allowing the setXid signal, and
+     none else.  */
+  sigset_t ss;
+  sigemptyset (&ss);
+  __sigaddset (&ss, SIGTIMER);
+
+  syscall (SYS_thr_self, &__helper_tid);
+  sem_post (&__helper_tid_semaphore);
+
+  /* Endless loop of waiting for signals.  The loop is only ended when
+     the thread is canceled.  */
+  while (1)
+    {
+      siginfo_t si;
+
+      /* sigwaitinfo cannot be used here, since it deletes
+	 SIGCANCEL == SIGTIMER from the set.  */
+
+      int oldtype = LIBC_CANCEL_ASYNC ();
+
+      /* XXX The size argument hopefully will have to be changed to the
+	 real size of the user-level sigset_t.  */
+      int result = sigtimedwait (&ss, &si, NULL);
+
+      LIBC_CANCEL_RESET (oldtype);
+
+      if (result > 0)
+	{
+	  if (si.si_code == SI_TIMER)
+	    {
+	      struct timer *tk = (struct timer *) si.si_value.sival_ptr;
+
+	      /* Check the timer is still used and will not go away
+		 while we are reading the values here.  */
+	      pthread_mutex_lock (&__active_timer_sigev_thread_lock);
+
+	      struct timer *runp = __active_timer_sigev_thread;
+	      while (runp != NULL)
+		if (runp == tk)
+		  break;
+		else
+		  runp = runp->next;
+
+	      if (runp != NULL)
+		{
+		  struct thread_start_data *td = malloc (sizeof (*td));
+
+		  /* There is not much we can do if the allocation fails.  */
+		  if (td != NULL)
+		    {
+		      /* This is the signal we are waiting for.  */
+		      td->thrfunc = tk->thrfunc;
+		      td->sival = tk->sival;
+
+		      pthread_t th;
+		      (void) pthread_create (&th, &tk->attr,
+					     timer_sigev_thread, td);
+		    }
+		}
+
+	      pthread_mutex_unlock (&__active_timer_sigev_thread_lock);
+	    }
+	  else if (si.si_code == SI_LWP
+		   /* Backward compatibility (see rev 211732 in -CURRENT).  */
+		   || si.si_code == SI_USER)
+	    /* The thread is canceled.  */
+	    pthread_exit (NULL);
+	}
+    }
+}
+
+
+/* Control variable for helper thread creation.  */
+pthread_once_t __helper_once attribute_hidden;
+
+
+/* Reset variables so that after a fork a new helper thread gets started.  */
+static void
+reset_helper_control (void)
+{
+  __helper_once = PTHREAD_ONCE_INIT;
+  __helper_tid = 0;
+  sem_destroy (&__helper_tid_semaphore);
+}
+
+
+void
+attribute_hidden
+__start_helper_thread (void)
+{
+  /* 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_setstacksize (&attr, PTHREAD_STACK_MIN);
+
+  /* Block all signals in the helper thread but SIGSETXID.  To do this
+     thoroughly we temporarily have to block all signals here.  The
+     helper can lose wakeups if SIGCANCEL is not blocked throughout,
+     but sigfillset omits it SIGSETXID.  So, we add SIGCANCEL back
+     explicitly here.  */
+  sigset_t ss;
+  sigset_t oss;
+  sigfillset (&ss);
+  __sigaddset (&ss, SIGCANCEL);
+  sigprocmask (SIG_SETMASK, &ss, &oss);
+
+  sem_init (&__helper_tid_semaphore, 0, 0);
+
+  /* Create the helper thread for this timer.  */
+  pthread_t th;
+  int res = pthread_create (&th, &attr, timer_helper_thread, NULL);
+  if (res == 0)
+    /* We managed to start the helper thread.  */
+    sem_wait (&__helper_tid_semaphore);
+
+  /* Restore the signal mask.  */
+  sigprocmask (SIG_SETMASK, &oss, NULL);
+
+  /* No need for the attribute anymore.  */
+  (void) pthread_attr_destroy (&attr);
+
+  /* We have to make sure that after fork()ing a new helper thread can
+     be created.  */
+  pthread_atfork (NULL, NULL, reset_helper_control);
+}

Copied: trunk/glibc-ports/kfreebsd/fbtl/timer_settime.c (from rev 4619, trunk/glibc-ports/kfreebsd/linuxthreads/timer_settime.c)
===================================================================
--- trunk/glibc-ports/kfreebsd/fbtl/timer_settime.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/fbtl/timer_settime.c	2013-06-28 13:58:30 UTC (rev 4637)
@@ -0,0 +1,42 @@
+/* Copyright (C) 2003, 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper at 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"
+
+int
+timer_settime (timerid, flags, value, ovalue)
+     timer_t timerid;
+     int flags;
+     const struct itimerspec *value;
+     struct itimerspec *ovalue;
+{
+      struct timer *kt = __kfreebsd_timer_id2ptr (timerid);
+      if (! kt)
+	return -1;
+
+      /* Set the kernel timer object.  */
+      return INLINE_SYSCALL (ktimer_settime, 4, kt->ktimerid, flags,
+				value, ovalue);
+
+}




More information about the Glibc-bsd-commits mailing list