2 #include "pthread_impl.h"
5 union sigval sigev_value;
16 static void dummy_1(pthread_t self)
19 weak_alias(dummy_1, __pthread_tsd_run_dtors);
21 static void cleanup_fromsig(void *p)
23 pthread_t self = __pthread_self();
26 __pthread_tsd_run_dtors(self);
30 void __sigtimer_handler(pthread_t self)
33 void (*notify)(union sigval) = (void (*)(union sigval))self->start;
34 union sigval val = { .sival_ptr = self->start_arg };
36 if (setjmp(jb)) return;
37 pthread_cleanup_push(cleanup_fromsig, jb);
39 pthread_cleanup_pop(0);
42 static void *start(void *arg)
44 pthread_t self = __pthread_self();
45 struct start_args *args = arg;
47 /* Reuse no-longer-needed thread structure fields to avoid
48 * needing the timer address in the signal handler. */
49 self->start = (void *(*)(void *))args->sev->sigev_notify_function;
50 self->start_arg = args->sev->sigev_value.sival_ptr;
51 self->result = (void *)-1;
53 pthread_barrier_wait(&args->b);
54 __wait(&self->delete_timer, 0, 0, 1);
55 __syscall(SYS_timer_delete, self->result);
59 int timer_create(clockid_t clk, struct sigevent *evp, timer_t *res)
64 struct start_args args;
65 struct ksigevent ksev, *ksevp=0;
68 switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) {
72 ksev.sigev_value = evp->sigev_value;
73 ksev.sigev_signo = evp->sigev_signo;
74 ksev.sigev_notify = evp->sigev_notify;
78 if (syscall(SYS_timer_create, clk, ksevp, &timerid) < 0)
80 *res = (void *)timerid;
83 if (evp->sigev_notify_attributes)
84 attr = *evp->sigev_notify_attributes;
86 pthread_attr_init(&attr);
87 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
88 pthread_barrier_init(&args.b, 0, 2);
90 r = pthread_create(&td, &attr, start, &args);
95 ksev.sigev_value.sival_ptr = 0;
96 ksev.sigev_signo = SIGCANCEL;
97 ksev.sigev_notify = 4; /* SIGEV_THREAD_ID */
98 ksev.sigev_tid = td->tid;
99 r = syscall(SYS_timer_create, clk, &ksev, &timerid);
100 pthread_barrier_wait(&args.b);
105 td->result = (void *)timerid;