This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] timer fixes


Hi!

timer_gettime should never return non-zeri it_value for expired timer,
but current userland emulation happily returns negative times.
Also, periodic SIGEV_NONE needs to be handled for timer_settime and
timer_gettime.  I think it is easiest to handle it like SIGEV_SIGNAL,
people don't use SIGEV_NONE timers that much anyway.
Lastly, thread_attr_compare was comparing just a small subset of attributes
instead of all of them, which lead to the guardsize failures of tst-timer4.

2004-04-17  Jakub Jelinek  <jakub@redhat.com>

nptl/
	* sysdeps/pthread/timer_gettime.c (timer_gettime): For expired timer
	return it_value { 0, 0 }.
	* sysdeps/pthread/timer_create.c (timer_create): Handle SIGEV_NONE
	like SIGEV_SIGNAL.
	* sysdeps/pthread/timer_routines.c (thread_expire_timer): Remove
	assertion for SIGEV_NONE.
	(thread_attr_compare): Compare all attributes, not just a partial
	subset.
linuxthreads/
	* sysdeps/pthread/timer_gettime.c (timer_gettime): For expired timer
	return it_value { 0, 0 }.
	* sysdeps/pthread/timer_create.c (timer_create): Handle SIGEV_NONE
	like SIGEV_SIGNAL.
	* sysdeps/pthread/timer_routines.c (thread_expire_timer): Remove
	assertion for SIGEV_NONE.
	(thread_attr_compare): Compare all attributes, not just a partial
	subset.

--- libc/nptl/sysdeps/pthread/timer_gettime.c.jj	2002-11-26 23:50:32.000000000 +0100
+++ libc/nptl/sysdeps/pthread/timer_gettime.c	2004-04-17 21:36:03.067458418 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
 
@@ -54,7 +54,13 @@ timer_gettime (timerid, value)
       if (armed)
 	{
 	  clock_gettime (clock, &now);
-	  timespec_sub (&value->it_value, &expiry, &now);
+	  if (timespec_compare (&now, &expiry) < 0)
+	    timespec_sub (&value->it_value, &expiry, &now);
+	  else
+	    {
+	      value->it_value.tv_sec = 0;
+	      value->it_value.tv_nsec = 0;
+	    }
 	}
       else
 	{
--- libc/nptl/sysdeps/pthread/timer_create.c.jj	2003-07-29 11:30:53.000000000 +0200
+++ libc/nptl/sysdeps/pthread/timer_create.c	2004-04-17 21:35:32.216987225 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
 
@@ -91,9 +91,6 @@ timer_create (clock_id, evp, timerid)
   switch (__builtin_expect (newtimer->event.sigev_notify, SIGEV_SIGNAL))
     {
     case SIGEV_NONE:
-      /* This is a strange choice!  */
-      break;
-
     case SIGEV_SIGNAL:
       /* We have a global thread for delivering timed signals.
 	 If it is not running, try to start it up.  */
--- libc/nptl/sysdeps/pthread/timer_routines.c.jj	2003-07-29 11:30:53.000000000 +0200
+++ libc/nptl/sysdeps/pthread/timer_routines.c	2004-04-17 21:38:31.504856504 +0200
@@ -1,5 +1,5 @@
 /* Helper code for POSIX timer implementation on NPTL.
-   Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
 
@@ -319,7 +319,6 @@ thread_expire_timer (struct thread_node 
   switch (__builtin_expect (timer->event.sigev_notify, SIGEV_SIGNAL))
     {
     case SIGEV_NONE:
-      assert (! "timer_create should never have created such a timer");
       break;
 
     case SIGEV_SIGNAL:
@@ -522,7 +521,15 @@ thread_attr_compare (const pthread_attr_
   return (ileft->flags == iright->flags
 	  && ileft->schedpolicy == iright->schedpolicy
 	  && (ileft->schedparam.sched_priority
-	      == iright->schedparam.sched_priority));
+	      == iright->schedparam.sched_priority)
+	  && ileft->guardsize == iright->guardsize
+	  && ileft->stackaddr == iright->stackaddr
+	  && ileft->stacksize == iright->stacksize
+	  && ((ileft->cpuset == NULL && iright->cpuset == NULL)
+	      || (ileft->cpuset != NULL && iright->cpuset != NULL
+		  && ileft->cpusetsize == iright->cpusetsize
+		  && memcmp (ileft->cpuset, iright->cpuset,
+			     ileft->cpusetsize) == 0)));
 }
 
 
--- libc/linuxthreads/sysdeps/pthread/timer_gettime.c.jj	2002-08-27 00:39:43.000000000 +0200
+++ libc/linuxthreads/sysdeps/pthread/timer_gettime.c	2004-04-17 21:33:23.985967893 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
 
@@ -54,7 +54,13 @@ timer_gettime (timerid, value)
       if (armed)
 	{
 	  clock_gettime (clock, &now);
-	  timespec_sub (&value->it_value, &expiry, &now);
+	  if (timespec_compare (&now, &expiry) < 0)
+	    timespec_sub (&value->it_value, &expiry, &now);
+	  else
+	    {
+	      value->it_value.tv_sec = 0;
+	      value->it_value.tv_nsec = 0;
+	    }
 	}
       else
 	{
--- libc/linuxthreads/sysdeps/pthread/timer_create.c.jj	2003-07-30 12:00:21.000000000 +0200
+++ libc/linuxthreads/sysdeps/pthread/timer_create.c	2004-04-17 21:33:35.791852125 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
 
@@ -91,9 +91,6 @@ timer_create (clock_id, evp, timerid)
   switch (__builtin_expect (newtimer->event.sigev_notify, SIGEV_SIGNAL))
     {
     case SIGEV_NONE:
-      /* This is a strange choice!  */
-      break;
-
     case SIGEV_SIGNAL:
       /* We have a global thread for delivering timed signals.
 	 If it is not running, try to start it up.  */
--- libc/linuxthreads/sysdeps/pthread/timer_routines.c.jj	2004-04-17 20:28:39.122186062 +0200
+++ libc/linuxthreads/sysdeps/pthread/timer_routines.c	2004-04-17 21:33:48.426587815 +0200
@@ -1,5 +1,5 @@
 /* Helper code for POSIX timer implementation on LinuxThreads.
-   Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>.
 
@@ -318,7 +318,6 @@ thread_expire_timer (struct thread_node 
   switch (__builtin_expect (timer->event.sigev_notify, SIGEV_SIGNAL))
     {
     case SIGEV_NONE:
-      assert (! "timer_create should never have created such a timer");
       break;
 
     case SIGEV_SIGNAL:
@@ -517,10 +516,15 @@ thread_attr_compare (const pthread_attr_
 {
   return (left->__detachstate == right->__detachstate
 	  && left->__schedpolicy == right->__schedpolicy
+	  && left->__guardsize == right->__guardsize
 	  && (left->__schedparam.sched_priority
 	      == right->__schedparam.sched_priority)
 	  && left->__inheritsched == right->__inheritsched
-	  && left->__scope == right->__scope);
+	  && left->__scope == right->__scope
+	  && left->__stacksize == right->__stacksize
+	  && left->__stackaddr_set == right->__stackaddr_set
+	  && (left->__stackaddr_set
+	      || left->__stackaddr == right->__stackaddr));
 }
 
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]