2 *------------------------------------------------------------------
5 * Copyright (c) 2008-2009 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
19 #ifndef __SPP_TIMERS_H__
20 #define __SPP_TIMERS_H__
23 typedef struct d_list_el_ {
24 struct d_list_el_ *next;
25 struct d_list_el_ *prev;
32 static inline void d_list_init (d_list_el_t *headp)
34 headp->prev = headp->next = headp;
38 * d_list_init - add at head of list
41 static inline void d_list_add_head (d_list_el_t *headp,
44 ASSERT(elp->prev == elp); /* multiple enqueue, BAD! */
45 ASSERT(elp->next == elp);
47 elp->next = headp->next;
49 elp->prev = elp->next->prev;
50 elp->next->prev = elp;
54 * d_list_add_tail - add element at tail of list
56 static inline void d_list_add_tail (d_list_el_t *headp,
59 ASSERT(elp->prev == elp); /* multiple enqueue, BAD! */
60 ASSERT(elp->next == elp);
64 elp->next = headp->next;
66 elp->prev = elp->next->prev;
67 elp->next->prev = elp;
71 * d_list_rem_head - removes first element from list
73 static inline d_list_el_t *d_list_rem_head (d_list_el_t *headp)
80 headp->next = elp->next;
81 elp->next->prev = elp->prev;
83 elp->next = elp->prev = elp;
88 * d_list_rem_elem - removes specific element from list.
90 static inline void d_list_rem_elem (d_list_el_t *elp)
96 headp->next = elp->next;
97 elp->next->prev = elp->prev;
98 elp->next = elp->prev = elp;
101 #define TIMER_BKTS_PER_WHEEL 128 /* power of 2, please */
102 #define TIMER_NWHEELS 4
105 i32 curindex; /* current index for this wheel */
106 d_list_el_t *bkts; /* vector of bucket listheads */
111 u64 next_run_ticks; /* Next time we expire timers */
112 spp_timer_wheel_t **wheels; /* pointers to wheels */
123 #define SPP_TIMER_RUNNING 0x0001
129 void spp_timer_set_ticks_per_ms(u64);
130 void spp_timer_axle_init (spp_timer_axle_t *ta);
131 void spp_timer_expire(spp_timer_axle_t *ta, u64 now);
132 void spp_timer_final_init(void);
134 void spp_timer_start(spp_timer_t *tp);
135 void spp_timer_start_axle(spp_timer_axle_t *ta, spp_timer_t *tp);
136 void spp_timer_stop(spp_timer_t *tp);
137 u16 spp_timer_register_callback (void (*fp)(spp_timer_t *));
139 #endif /* __SPP_TIMERS_H__ */