Definition in file timer.h.
#include "worker.h"
Go to the source code of this file.
Data Structures | |
| struct | _timer_cb_t |
| timer element More... | |
| struct | timer_cb_list_t |
| timer list More... | |
Typedefs | |
| typedef void(*) | callback_f (time_t now, void *ptr) |
| callback function for timer event | |
| typedef _timer_cb_t | timer_cb_t |
| timer element | |
Functions | |
| int | add_timer (int expires_in, int one_time, callback_f cb, void *ptr) |
| Adds a timer to the timer list. | |
| void | timer_cdp_init () |
| Init the timer structures. | |
| void | timer_cdp_destroy () |
| Destroy the timer structures. | |
| void | timer_process (int returns) |
| Timer Process function. | |
| typedef void(*) callback_f(time_t now, void *ptr) |
| typedef struct _timer_cb_t timer_cb_t |
timer element
| int add_timer | ( | int | expires_in, | |
| int | one_time, | |||
| callback_f | cb, | |||
| void * | ptr | |||
| ) |
Adds a timer to the timer list.
| expires_in | - time until expiration in seconds | |
| one_time | - if after expiration it should be removed or kept in the timers list | |
| cb | - callback function to be called on expiration | |
| ptr | - generic pointer to pass to the callback on expiration |
Definition at line 132 of file timer.c.
References _timer_cb_t::cb, _timer_cb_t::expires, timer_cb_list_t::head, _timer_cb_t::interval, LOG_NO_MEM, _timer_cb_t::next, _timer_cb_t::one_time, _timer_cb_t::prev, _timer_cb_t::ptr, timer_cb_list_t::tail, timers, and timers_lock.
Referenced by peer_manager_init(), and trans_init().
00133 { 00134 timer_cb_t *n; 00135 if (expires_in==0){ 00136 LOG(L_ERR,"ERROR:add_timer(): Minimum expiration time is 1 second!\n"); 00137 return 0; 00138 } 00139 n = shm_malloc(sizeof(timer_cb_t)); 00140 if (!n){ 00141 LOG_NO_MEM("shm",sizeof(timer_cb_t)); 00142 return 0; 00143 } 00144 n->ptr = shm_malloc(sizeof(void*)); 00145 if (!n){ 00146 LOG_NO_MEM("shm",sizeof(void*)); 00147 shm_free(n); 00148 return 0; 00149 } 00150 n->expires = expires_in + time(0); 00151 n->one_time = one_time; 00152 n->interval = expires_in; 00153 n->cb = cb; 00154 *(n->ptr) = ptr; 00155 00156 lock_get(timers_lock); 00157 n->prev = timers->tail; 00158 n->next = 0; 00159 if (!timers->head) timers->head = n; 00160 if (timers->tail) timers->tail->next = n; 00161 timers->tail = n; 00162 lock_release(timers_lock); 00163 return 1; 00164 }
| void timer_cdp_init | ( | ) |
Init the timer structures.
Definition at line 169 of file timer.c.
References timer_cb_list_t::head, timer_cb_list_t::tail, timers, and timers_lock.
Referenced by diameter_peer_init().
00170 { 00171 timers = shm_malloc(sizeof(timer_cb_list_t)); 00172 timers->head=0; 00173 timers->tail=0; 00174 timers_lock = lock_alloc(); 00175 timers_lock = lock_init(timers_lock); 00176 }
| void timer_cdp_destroy | ( | ) |
Destroy the timer structures.
Definition at line 181 of file timer.c.
References timer_cb_list_t::head, _timer_cb_t::next, _timer_cb_t::ptr, timers, and timers_lock.
Referenced by diameter_peer_destroy().
00182 { 00183 timer_cb_t *n,*i; 00184 /* lock_get(timers_lock);*/ 00185 i = timers->head; 00186 while(i){ 00187 n = i->next; 00188 if (i->ptr) shm_free(i->ptr); 00189 shm_free(i); 00190 i = n; 00191 } 00192 shm_free(timers); 00193 lock_destroy(timers_lock); 00194 lock_dealloc((void*)timers_lock); 00195 }
| void timer_process | ( | int | returns | ) |
Timer Process function.
It calls timer_loop().
| returns | - whether on shutdown this function should return or exit |
Definition at line 203 of file timer.c.
References dp_del_pid(), memlog, and timer_loop().
Referenced by diameter_peer_start().
00204 { 00205 LOG(L_INFO,"INFO:Timer process starting up...\n"); 00206 00207 timer_loop(); 00208 00209 LOG(L_INFO,"INFO:... Timer process finished\n"); 00210 if (!returns) { 00211 #ifdef CDP_FOR_SER 00212 #else 00213 #ifdef PKG_MALLOC 00214 #ifdef PKG_MALLOC 00215 LOG(memlog, "Timer Memory status (pkg):\n"); 00216 //pkg_status(); 00217 #ifdef pkg_sums 00218 pkg_sums(); 00219 #endif 00220 #endif 00221 #endif 00222 dp_del_pid(getpid()); 00223 #endif 00224 00225 exit(0); 00226 } 00227 }
1.5.2