about summary refs log tree commit diff
path: root/linuxthreads/sysdeps/pthread/timer_gettime.c
diff options
context:
space:
mode:
Diffstat (limited to 'linuxthreads/sysdeps/pthread/timer_gettime.c')
-rw-r--r--linuxthreads/sysdeps/pthread/timer_gettime.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/linuxthreads/sysdeps/pthread/timer_gettime.c b/linuxthreads/sysdeps/pthread/timer_gettime.c
index 43b07598b7..dbee9d915e 100644
--- a/linuxthreads/sysdeps/pthread/timer_gettime.c
+++ b/linuxthreads/sysdeps/pthread/timer_gettime.c
@@ -31,25 +31,30 @@ timer_gettime (timerid, value)
      struct itimerspec *value;
 {
   struct timer_node *timer;
-  struct timespec now;
-  int retval = -1;
+  struct timespec now, expiry;
+  int retval = -1, armed = 0, valid;
+  clock_t clock = 0;
 
   pthread_mutex_lock (&__timer_mutex);
 
   timer = timer_id2ptr (timerid);
-  if (timer == NULL && !timer->inuse)
-    /* Invalid timer ID or the timer is not in use.  */
-    errno = EINVAL;
-  else
-    {
-      value->it_interval = timer->value.it_interval;
+  valid = timer_valid (timer);
+
+  if (valid) {
+    armed = timer->armed;
+    expiry = timer->expirytime;
+    clock = timer->clock;
+    value->it_interval = timer->value.it_interval;
+  }
+
+  pthread_mutex_unlock (&__timer_mutex);
 
-      if (timer->armed)
+  if (valid)
+    {
+      if (armed)
 	{
-	  pthread_mutex_unlock (&__timer_mutex);
-	  clock_gettime (timer->clock, &now);
-	  pthread_mutex_lock (&__timer_mutex);
-	  timespec_sub (&value->it_value, &timer->expirytime, &now);
+	  clock_gettime (clock, &now);
+	  timespec_sub (&value->it_value, &expiry, &now);
 	}
       else
 	{
@@ -59,8 +64,8 @@ timer_gettime (timerid, value)
 
       retval = 0;
     }
-
-  pthread_mutex_lock (&__timer_mutex);
+  else
+    __set_errno (EINVAL);
 
   return retval;
 }