2 #include "pthread_impl.h"
5 union sigval sigev_value;
16 void __sigtimer_handler(pthread_t self)
19 void (*notify)(union sigval) = (void (*)(union sigval))self->start;
20 union sigval val = { .sival_ptr = self->start_arg };
22 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &st);
24 pthread_setcancelstate(st, 0);
27 static void *start(void *arg)
29 pthread_t self = __pthread_self();
30 struct start_args *args = arg;
32 /* Reuse no-longer-needed thread structure fields to avoid
33 * needing the timer address in the signal handler. */
34 self->start = (void *(*)(void *))args->sev->sigev_notify_function;
35 self->start_arg = args->sev->sigev_value.sival_ptr;
36 self->result = (void *)-1;
38 pthread_barrier_wait(&args->b);
39 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
40 /* Loop on async-signal-safe cancellation point */
45 int timer_create(clockid_t clk, struct sigevent *evp, timer_t *res)
47 struct sigevent sev = {
48 .sigev_notify = SIGEV_SIGNAL,
49 .sigev_signo = SIGALRM
54 struct start_args args;
56 struct ksigevent ksev;
61 switch (sev.sigev_notify) {
64 ksev.sigev_value = evp ? sev.sigev_value
65 : (union sigval){.sival_ptr=t};
66 ksev.sigev_signo = sev.sigev_signo;
67 ksev.sigev_notify = sev.sigev_notify;
69 if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0)
71 *res = (void *)(2*timerid+1);
74 if (sev.sigev_notify_attributes)
75 attr = *sev.sigev_notify_attributes;
77 pthread_attr_init(&attr);
78 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
79 pthread_barrier_init(&args.b, 0, 2);
81 r = pthread_create(&td, &attr, start, &args);
86 ksev.sigev_value.sival_ptr = 0;
87 ksev.sigev_signo = SIGCANCEL;
88 ksev.sigev_notify = 4; /* SIGEV_THREAD_ID */
89 ksev.sigev_tid = td->tid;
90 r = syscall(SYS_timer_create, clk, &ksev, &timerid);
91 pthread_barrier_wait(&args.b);
96 td->result = (void *)timerid;