00001 #ifndef KAL_TIMER_WHEEL_H_
00002 #define KAL_TIMER_WHEEL_H_
00003
00004 #include "kal_time.h"
00005
00006 #include <linux/aquosa/qos_debug.h>
00007 #include <linux/aquosa/qos_types.h>
00008 #include <linux/aquosa/qos_memory.h>
00009
00010 #include <linux/time.h>
00011 #include <linux/timer.h>
00012 #include <linux/jiffies.h>
00013
00014
00015
00016 #include "kal_arg.h"
00017 typedef void (*linux_timer_cb)(unsigned long cb_data);
00018 typedef void (*kal_timer_cb)(kal_arg_t cb_data);
00019
00020 typedef struct {
00021 struct timer_list timer;
00022 kal_timer_cb timer_cb;
00023 kal_arg_t timer_cb_data;
00024 char handler_running;
00025 } kal_timer_t;
00026
00027 static void timer_callback(unsigned long cb_data) {
00028 kal_timer_t *p_timer = (kal_timer_t *) cb_data;
00029 qos_chk_do(qos_mem_valid(p_timer), return);
00030 p_timer->handler_running = 1;
00031 p_timer->timer_cb(p_timer->timer_cb_data);
00032 p_timer->handler_running = 0;
00033 }
00034
00035 static inline void kal_timer_init(kal_timer_t * p_timer, kal_timer_cb cb, kal_arg_t cb_data) {
00036 p_timer->timer_cb = cb;
00037 p_timer->timer_cb_data = cb_data;
00038 setup_timer(&p_timer->timer, timer_callback, (unsigned long) p_timer);
00039 }
00040
00041 static inline void kal_timer_init_now(kal_timer_t * p_timer, kal_timer_cb cb, kal_arg_t cb_data) {
00042 unsigned long expires = get_jiffies();
00043 kal_timer_init(p_timer, cb, cb_data);
00044
00045 p_timer->timer.expires = expires;
00046 }
00047
00048 static inline void kal_timer_set(kal_timer_t * p_timer, kal_time_t t) {
00049 unsigned long expires = kal_time2jiffies(t);
00050
00051 del_timer(&p_timer->timer);
00052 p_timer->timer.expires = expires;
00053 add_timer(&p_timer->timer);
00054 }
00055
00056 static inline void kal_timer_del(kal_timer_t * p_timer) {
00057 if (timer_pending(&p_timer->timer) && (! p_timer->handler_running))
00058 del_timer_sync(&p_timer->timer);
00059 }
00060
00061 static inline void kal_timer_forward(kal_timer_t * p_timer, kal_time_t t) {
00062 unsigned long expires = p_timer->timer.expires + kal_time2jiffies(t);
00063
00064
00065 kal_timer_del(p_timer);
00066 p_timer->timer.expires = expires;
00067 add_timer(&p_timer->timer);
00068 }
00069
00070 static inline int kal_timer_pending(kal_timer_t *p_timer) {
00071 return timer_pending(&p_timer->timer);
00072 }
00073
00074 #endif