about summary refs log tree commit diff
path: root/src/time/timer_create.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-09 02:23:33 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-09 02:23:33 -0400
commit82171d6ac0d84876cdc6dd6319b0790b42cdb47e (patch)
treedf557d7e26c757b333c3dc1e4a9338113d91446e /src/time/timer_create.c
parent2d1d62ed47452126bb632207dd64b0fdaf4c13ed (diff)
downloadmusl-82171d6ac0d84876cdc6dd6319b0790b42cdb47e.tar.gz
musl-82171d6ac0d84876cdc6dd6319b0790b42cdb47e.tar.xz
musl-82171d6ac0d84876cdc6dd6319b0790b42cdb47e.zip
greatly improve SIGEV_THREAD timers
calling pthread_exit from, or pthread_cancel on, the timer callback
thread will no longer destroy the timer.
Diffstat (limited to 'src/time/timer_create.c')
-rw-r--r--src/time/timer_create.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/time/timer_create.c b/src/time/timer_create.c
index a0ee845c..1b184f74 100644
--- a/src/time/timer_create.c
+++ b/src/time/timer_create.c
@@ -13,21 +13,24 @@ struct start_args {
 	struct sigevent *sev;
 };
 
+static void cleanup_fromsig(void *p)
+{
+	pthread_t self = __pthread_self();
+	self->cancel = 0;
+	self->cancelbuf = 0;
+	longjmp(p, 1);
+}
+
 void __sigtimer_handler(pthread_t self)
 {
-	int st;
+	jmp_buf jb;
 	void (*notify)(union sigval) = (void (*)(union sigval))self->start;
 	union sigval val = { .sival_ptr = self->start_arg };
 
-	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &st);
+	if (setjmp(jb)) return;
+	pthread_cleanup_push(cleanup_fromsig, jb);
 	notify(val);
-	pthread_setcancelstate(st, 0);
-}
-
-static void cleanup(void *p)
-{
-	pthread_t self = p;
-	__syscall(SYS_timer_delete, self->result);
+	pthread_cleanup_pop(0);
 }
 
 static void *start(void *arg)
@@ -41,12 +44,9 @@ 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(1000000000);
-	pthread_cleanup_pop(0);
+	__wait(&self->delete_timer, 0, 0, 1);
+	__syscall(SYS_timer_delete, self->result);
 	return 0;
 }