2 * timer_create.c - create a per-process timer.
10 #include <sys/syscall.h>
12 #include "kernel-posix-timers.h"
14 #ifdef __NR_timer_create
17 # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
20 #define __NR___syscall_timer_create __NR_timer_create
21 static __inline__ _syscall3(int, __syscall_timer_create, clockid_t, clock_id,
22 struct sigevent *, evp, kernel_timer_t *, ktimerid);
24 /* Create a per-process timer */
25 int timer_create(clockid_t clock_id, struct sigevent *evp, timer_t * timerid)
28 kernel_timer_t ktimerid;
29 struct sigevent default_evp;
34 * The kernel has to pass up the timer ID which is a userlevel object.
35 * Therefore we cannot leave it up to the kernel to determine it.
37 default_evp.sigev_notify = SIGEV_SIGNAL;
38 default_evp.sigev_signo = SIGALRM;
42 /* Notification via a thread is not supported yet */
43 if (__builtin_expect(evp->sigev_notify == SIGEV_THREAD, 1))
47 * We avoid allocating too much memory by basically using
48 * struct timer as a derived class with the first two elements
49 * being in the superclass. We only need these two elements here.
51 newp = malloc(offsetof(struct timer, thrfunc));
53 return -1; /* No memory */
54 default_evp.sigev_value.sival_ptr = newp;
56 retval = __syscall_timer_create(clock_id, evp, &ktimerid);
58 newp->sigev_notify = evp->sigev_notify;
59 newp->ktimerid = ktimerid;
61 *timerid = (timer_t) newp;
63 /* Cannot allocate the timer, fail */