vserver 1.9.5.x5
[linux-2.6.git] / include / linux / posix-timers.h
1 #ifndef _linux_POSIX_TIMERS_H
2 #define _linux_POSIX_TIMERS_H
3
4 #include <linux/spinlock.h>
5 #include <linux/list.h>
6
7 /* POSIX.1b interval timer structure. */
8 struct k_itimer {
9         struct list_head list;          /* free/ allocate list */
10         spinlock_t it_lock;
11         clockid_t it_clock;             /* which timer type */
12         timer_t it_id;                  /* timer id */
13         int it_overrun;                 /* overrun on pending signal  */
14         int it_overrun_last;            /* overrun on last delivered signal */
15         int it_requeue_pending;         /* waiting to requeue this timer */
16         int it_sigev_notify;            /* notify word of sigevent struct */
17         int it_sigev_signo;             /* signo word of sigevent struct */
18         sigval_t it_sigev_value;        /* value word of sigevent struct */
19         unsigned long it_incr;          /* interval specified in jiffies */
20         struct task_struct *it_process; /* process to send signal to */
21         struct timer_list it_timer;
22         struct sigqueue *sigq;          /* signal queue entry. */
23         struct list_head abs_timer_entry; /* clock abs_timer_list */
24         struct timespec wall_to_prev;   /* wall_to_monotonic used when set */
25 };
26
27 struct k_clock_abs {
28         struct list_head list;
29         spinlock_t lock;
30 };
31 struct k_clock {
32         int res;                /* in nano seconds */
33         struct k_clock_abs *abs_struct;
34         int (*clock_set) (struct timespec * tp);
35         int (*clock_get) (struct timespec * tp);
36         int (*timer_create) (struct k_itimer *timer);
37         int (*nsleep) (int which_clock, int flags,
38                        struct timespec * t);
39         int (*timer_set) (struct k_itimer * timr, int flags,
40                           struct itimerspec * new_setting,
41                           struct itimerspec * old_setting);
42         int (*timer_del) (struct k_itimer * timr);
43         void (*timer_get) (struct k_itimer * timr,
44                            struct itimerspec * cur_setting);
45 };
46
47 void register_posix_clock(int clock_id, struct k_clock *new_clock);
48
49 /* Error handlers for timer_create, nanosleep and settime */
50 int do_posix_clock_notimer_create(struct k_itimer *timer);
51 int do_posix_clock_nonanosleep(int which_clock, int flags, struct timespec * t);
52 int do_posix_clock_nosettime(struct timespec *tp);
53
54 /* function to call to trigger timer event */
55 int posix_timer_event(struct k_itimer *timr, int si_private);
56
57 struct now_struct {
58         unsigned long jiffies;
59 };
60
61 #define posix_get_now(now) (now)->jiffies = jiffies;
62 #define posix_time_before(timer, now) \
63                       time_before((timer)->expires, (now)->jiffies)
64
65 #define posix_bump_timer(timr, now)                                     \
66          do {                                                           \
67               long delta, orun;                                         \
68               delta = now.jiffies - (timr)->it_timer.expires;           \
69               if (delta >= 0) {                                         \
70                    orun = 1 + (delta / (timr)->it_incr);                \
71                   (timr)->it_timer.expires += orun * (timr)->it_incr;   \
72                   (timr)->it_overrun += orun;                           \
73               }                                                         \
74             }while (0)
75 #endif
76