revert to deleting kernel-level timer from cancellation handler
authorRich Felker <dalias@aerifal.cx>
Sun, 3 Apr 2011 16:08:34 +0000 (12:08 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 3 Apr 2011 16:08:34 +0000 (12:08 -0400)
this is necessary in order to avoid breaking timer_getoverrun in the
last run of the timer event handler, if it has not yet finished.

src/time/timer_create.c
src/time/timer_delete.c

index f02abb86a7a323f3ed74a1826d9171b3650fd0c4..5d362c7ed7e626cce1dde6c37df383894789ebd0 100644 (file)
@@ -24,6 +24,12 @@ void __sigtimer_handler(pthread_t self)
        pthread_setcancelstate(st, 0);
 }
 
+static void cleanup(void *p)
+{
+       pthread_t self = p;
+       __syscall(SYS_timer_delete, self->result);
+}
+
 static void *start(void *arg)
 {
        pthread_t self = __pthread_self();
@@ -35,10 +41,12 @@ static void *start(void *arg)
        self->start_arg = args->sev->sigev_value.sival_ptr;
        self->result = (void *)-1;
 
+       pthread_cleanup_push(cleanup, self);
        pthread_barrier_wait(&args->b);
        pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
        /* Loop on async-signal-safe cancellation point */
        for (;;) sleep(1);
+       pthread_cleanup_pop(0);
        return 0;
 }
 
index 437de2e06a32926cdb71ef3709f420f23eb83146..7c82b1831524248f3fe6dbd0320ba94545372dee 100644 (file)
@@ -3,11 +3,7 @@
 
 int timer_delete(timer_t t)
 {
-       pthread_t td = 0;
-       int r;
-       if ((uintptr_t)t & 1) t = (void *)((unsigned long)t / 2);
-       else td = t, t = td->result;
-       r = __syscall(SYS_timer_delete, (long)t);
-       if (td) pthread_cancel(td);
-       return r;
+       if ((uintptr_t)t & 1)
+               return __syscall(SYS_timer_delete, ((unsigned long)t / 2));
+       return pthread_cancel(t);
 }