2 * timer_create.c - create a per-process timer.
11 #include <sys/syscall.h>
13 #include "kernel-posix-timers.h"
15 #ifdef __NR_timer_create
17 #define __NR___syscall_timer_create __NR_timer_create
18 static __inline__
_syscall3(int, __syscall_timer_create
, clockid_t
, clock_id
,
19 struct sigevent
*, evp
, kernel_timer_t
*, ktimerid
);
21 /* Create a per-process timer */
22 int timer_create(clockid_t clock_id
, struct sigevent
*evp
, timer_t
* timerid
)
25 kernel_timer_t ktimerid
;
26 struct sigevent default_evp
;
31 * The kernel has to pass up the timer ID which is a userlevel object.
32 * Therefore we cannot leave it up to the kernel to determine it.
34 default_evp
.sigev_notify
= SIGEV_SIGNAL
;
35 default_evp
.sigev_signo
= SIGALRM
;
39 /* Notification via a thread is not supported yet */
40 if (__builtin_expect(evp
->sigev_notify
== SIGEV_THREAD
, 1))
44 * We avoid allocating too much memory by basically using
45 * struct timer as a derived class with the first two elements
46 * being in the superclass. We only need these two elements here.
48 newp
= malloc(offsetof(struct timer
, thrfunc
));
50 return -1; /* No memory */
51 default_evp
.sigev_value
.sival_ptr
= newp
;
53 retval
= __syscall_timer_create(clock_id
, evp
, &ktimerid
);
55 newp
->sigev_notify
= evp
->sigev_notify
;
56 newp
->ktimerid
= ktimerid
;
58 *timerid
= (timer_t
) newp
;
60 /* Cannot allocate the timer, fail */