Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,425 +0,0 @@
1
-/*
2
- * Copyright (C) 2009 iptelorg GmbH
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-/**
18
- * @file
19
- * @brief Kamailio core ::  timer - separate process timers
20
- *
21
- *  (unrelated to the main fast and slow timers)
22
- *
23
- * @ingroup core
24
- * Module: @ref core
25
- */
26
-
27
-#include "timer_proc.h"
28
-#include "cfg/cfg_struct.h"
29
-#include "pt.h"
30
-#include "ut.h"
31
-#include "mem/shm_mem.h"
32
-
33
-#include <unistd.h>
34
-
35
-
36
-/**
37
- * \brief update internal counters for running new basic sec. timers
38
- * @param timers number of basic timer processes
39
- * @return 0 on success; -1 on error
40
- */
41
-int register_basic_timers(int timers)
42
-{
43
-	if(register_procs(timers)<0)
44
-		return -1;
45
-	cfg_register_child(timers);
46
-	return 0;
47
-}
48
-
49
-/**
50
- * \brief Forks a separate simple sleep() periodic timer
51
- *
52
- * Forks a very basic periodic timer process, that just sleep()s for
53
- * the specified interval and then calls the timer function.
54
- * The new "basic timer" process execution start immediately, the sleep()
55
- * is called first (so the first call to the timer function will happen
56
- * \<interval\> seconds after the call to fork_basic_timer)
57
- * @param child_id  @see fork_process()
58
- * @param desc      @see fork_process()
59
- * @param make_sock @see fork_process()
60
- * @param f         timer function/callback
61
- * @param param     parameter passed to the timer function
62
- * @param interval  interval in seconds.
63
- * @return pid of the new process on success, -1 on error
64
- * (doesn't return anything in the child process)
65
- */
66
-int fork_basic_timer(int child_id, char* desc, int make_sock,
67
-						timer_function* f, void* param, int interval)
68
-{
69
-	int pid;
70
-
71
-	pid=fork_process(child_id, desc, make_sock);
72
-	if (pid<0) return -1;
73
-	if (pid==0){
74
-		/* child */
75
-		if (cfg_child_init()) return -1;
76
-		for(;;){
77
-			sleep(interval);
78
-			cfg_update();
79
-			f(get_ticks(), param); /* ticks in s for compatibility with old
80
-									* timers */
81
-		}
82
-	}
83
-	/* parent */
84
-	return pid;
85
-}
86
-
87
-/**
88
- * \brief Forks a separate simple microsecond-sleep() periodic timer
89
- *
90
- * Forks a very basic periodic timer process, that just us-sleep()s for
91
- * the specified interval and then calls the timer function.
92
- * The new "basic timer" process execution start immediately, the us-sleep()
93
- * is called first (so the first call to the timer function will happen
94
- * \<interval\> microseconds after the call to fork_basic_utimer)
95
- * @param child_id  @see fork_process()
96
- * @param desc      @see fork_process()
97
- * @param make_sock @see fork_process()
98
- * @param f         timer function/callback
99
- * @param param     parameter passed to the timer function
100
- * @param uinterval  interval in micro-seconds.
101
- * @return pid of the new process on success, -1 on error
102
- * (doesn't return anything in the child process)
103
- */
104
-int fork_basic_utimer(int child_id, char* desc, int make_sock,
105
-						utimer_function* f, void* param, int uinterval)
106
-{
107
-	int pid;
108
-	ticks_t ts;
109
-
110
-	pid=fork_process(child_id, desc, make_sock);
111
-	if (pid<0) return -1;
112
-	if (pid==0){
113
-		/* child */
114
-		if (cfg_child_init()) return -1;
115
-		for(;;){
116
-			sleep_us(uinterval);
117
-			cfg_update();
118
-			ts = get_ticks_raw();
119
-			f(TICKS_TO_MS(ts), param); /* ticks in mili-seconds */
120
-		}
121
-	}
122
-	/* parent */
123
-	return pid;
124
-}
125
-
126
-
127
-/**
128
- * \brief Forks a timer process based on the local timer
129
- *
130
- * Forks a separate timer process running a local_timer.h type of timer
131
- * A pointer to the local_timer handle (allocated in shared memory) is
132
- * returned in lt_h. It can be used to add/delete more timers at runtime
133
- * (via local_timer_add()/local_timer_del() a.s.o).
134
- * If timers are added from separate processes, some form of locking must be
135
- * used (all the calls to local_timer* must be enclosed by locks if it
136
- * cannot be guaranteed that they cannot execute in the same time)
137
- * The timer "engine" must be run manually from the child process. For
138
- * example a very simple local timer process that just runs a single
139
- * periodic timer can be started in the following way:
140
- * struct local_timer* lt_h;
141
- *
142
- * pid=fork_local_timer_process(...., &lt_h);
143
- * if (pid==0){
144
- *          timer_init(&my_timer, my_timer_f, 0, 0);
145
- *          local_timer_add(&lt_h, &my_timer, S_TO_TICKS(10), get_ticks_raw());
146
- *          while(1) { sleep(1); local_timer_run(lt, get_ticks_raw()); }
147
- * }
148
- *
149
- * @param child_id  @see fork_process()
150
- * @param desc      @see fork_process()
151
- * @param make_sock @see fork_process()
152
- * @param lt_h      local_timer handler
153
- * @return pid to the parent, 0 to the child, -1 if error.
154
- */
155
-int fork_local_timer_process(int child_id, char* desc, int make_sock,
156
-						struct local_timer** lt_h)
157
-{
158
-	int pid;
159
-	struct local_timer* lt;
160
-
161
-	lt=shm_malloc(sizeof(*lt));
162
-	if (lt==0) goto error;
163
-	if (init_local_timer(lt, get_ticks_raw())<0) goto error;
164
-	pid=fork_process(child_id, desc, make_sock);
165
-	if (pid<0) goto error;
166
-	*lt_h=lt;
167
-	return pid;
168
-error:
169
-	if (lt) shm_free(lt);
170
-	return -1;
171
-}
172
-
173
-/**
174
- * \brief update internal counters for running new sync sec. timers
175
- * @param timers number of basic timer processes
176
- * @return 0 on success; -1 on error
177
- */
178
-int register_sync_timers(int timers)
179
-{
180
-	if(register_procs(timers)<0)
181
-		return -1;
182
-	cfg_register_child(timers);
183
-	return 0;
184
-}
185
-
186
-/**
187
- * \brief Forks a separate simple sleep() -&- sync periodic timer
188
- *
189
- * Forks a very basic periodic timer process, that just sleep()s for
190
- * the specified interval and then calls the timer function.
191
- * The new "sync timer" process execution start immediately, the sleep()
192
- * is called first (so the first call to the timer function will happen
193
- * \<interval\> seconds after the call to fork_sync_timer)
194
- * @param child_id  @see fork_process()
195
- * @param desc      @see fork_process()
196
- * @param make_sock @see fork_process()
197
- * @param f         timer function/callback
198
- * @param param     parameter passed to the timer function
199
- * @param interval  interval in seconds.
200
- * @return pid of the new process on success, -1 on error
201
- * (doesn't return anything in the child process)
202
- */
203
-int fork_sync_timer(int child_id, char* desc, int make_sock,
204
-						timer_function* f, void* param, int interval)
205
-{
206
-	int pid;
207
-	ticks_t ts1 = 0;
208
-	ticks_t ts2 = 0;
209
-
210
-	pid=fork_process(child_id, desc, make_sock);
211
-	if (pid<0) return -1;
212
-	if (pid==0){
213
-		/* child */
214
-		interval *= 1000;  /* miliseconds */
215
-		ts2 = interval;
216
-		if (cfg_child_init()) return -1;
217
-		for(;;){
218
-			if (ts2>interval)
219
-				sleep_us(1000);    /* 1 milisecond sleep to catch up */
220
-			else
221
-				sleep_us(ts2*1000); /* microseconds sleep */
222
-			ts1 = get_ticks_raw();
223
-			cfg_update();
224
-			f(TICKS_TO_S(ts1), param); /* ticks in sec for compatibility with old
225
-										* timers */
226
-			/* adjust the next sleep duration */
227
-			ts2 = interval - TICKS_TO_MS(get_ticks_raw()) + TICKS_TO_MS(ts1);
228
-		}
229
-	}
230
-	/* parent */
231
-	return pid;
232
-}
233
-
234
-
235
-/**
236
- * \brief Forks a separate simple microsecond-sleep() -&- sync periodic timer
237
- *
238
- * Forks a very basic periodic timer process, that just us-sleep()s for
239
- * the specified interval and then calls the timer function.
240
- * The new "sync timer" process execution start immediately, the us-sleep()
241
- * is called first (so the first call to the timer function will happen
242
- * \<interval\> microseconds after the call to fork_basic_utimer)
243
- * @param child_id  @see fork_process()
244
- * @param desc      @see fork_process()
245
- * @param make_sock @see fork_process()
246
- * @param f         timer function/callback
247
- * @param param     parameter passed to the timer function
248
- * @param uinterval  interval in micro-seconds.
249
- * @return pid of the new process on success, -1 on error
250
- * (doesn't return anything in the child process)
251
- */
252
-int fork_sync_utimer(int child_id, char* desc, int make_sock,
253
-						utimer_function* f, void* param, int uinterval)
254
-{
255
-	int pid;
256
-	ticks_t ts1 = 0;
257
-	ticks_t ts2 = 0;
258
-
259
-	pid=fork_process(child_id, desc, make_sock);
260
-	if (pid<0) return -1;
261
-	if (pid==0){
262
-		/* child */
263
-		ts2 = uinterval;
264
-		if (cfg_child_init()) return -1;
265
-		for(;;){
266
-			if(ts2>uinterval)
267
-				sleep_us(1);
268
-			else
269
-				sleep_us(ts2);
270
-			ts1 = get_ticks_raw();
271
-			cfg_update();
272
-			f(TICKS_TO_MS(ts1), param); /* ticks in mili-seconds */
273
-			ts2 = uinterval - get_ticks_raw() + ts1;
274
-		}
275
-	}
276
-	/* parent */
277
-	return pid;
278
-}
279
-
280
-
281
-/* number of slots in the wheel timer */
282
-#define SR_WTIMER_SIZE	16
283
-
284
-typedef struct sr_wtimer_node {
285
-	struct sr_wtimer_node *next;
286
-	uint32_t interval;  /* frequency of execution (secs) */
287
-	uint32_t steps;     /* init: interval = loops * SR_WTIMER_SIZE + steps */
288
-	uint32_t loops;
289
-	uint32_t eloop;
290
-	timer_function* f;
291
-	void* param;
292
-} sr_wtimer_node_t;
293
-
294
-typedef struct sr_wtimer {
295
-	uint32_t itimer;
296
-	sr_wtimer_node_t *wlist[SR_WTIMER_SIZE];
297
-} sr_wtimer_t;
298
-
299
-static sr_wtimer_t *_sr_wtimer = NULL;;
300
-
301
-/**
302
- *
303
- */
304
-int sr_wtimer_init(void)
305
-{
306
-	if(_sr_wtimer!=NULL)
307
-		return 0;
308
-	_sr_wtimer = (sr_wtimer_t *)pkg_malloc(sizeof(sr_wtimer_t));
309
-	if(_sr_wtimer==NULL) {
310
-		LM_ERR("no more pkg memory\n");
311
-		return -1;
312
-	}
313
-
314
-	memset(_sr_wtimer, 0, sizeof(sr_wtimer_t));
315
-	register_sync_timers(1);
316
-	return 0;
317
-}
318
-
319
-/**
320
- *
321
- */
322
-int sr_wtimer_add(timer_function* f, void* param, int interval)
323
-{
324
-	sr_wtimer_node_t *wt;
325
-	if(_sr_wtimer==NULL) {
326
-		LM_ERR("wtimer not initialized\n");
327
-		return -1;
328
-	}
329
-
330
-	wt = (sr_wtimer_node_t*)pkg_malloc(sizeof(sr_wtimer_node_t));
331
-	if(wt==NULL) {
332
-		LM_ERR("no more pkg memory\n");
333
-		return -1;
334
-	}
335
-	memset(wt, 0, sizeof(sr_wtimer_node_t));
336
-	wt->f = f;
337
-	wt->param = param;
338
-	wt->interval = interval;
339
-	wt->steps = interval % SR_WTIMER_SIZE;
340
-	wt->loops = interval / SR_WTIMER_SIZE;
341
-	wt->eloop = wt->loops;
342
-	wt->next = _sr_wtimer->wlist[wt->steps];
343
-	_sr_wtimer->wlist[wt->steps] = wt;
344
-
345
-	return 0;
346
-}
347
-
348
-/**
349
- *
350
- */
351
-int sr_wtimer_reinsert(uint32_t cs, sr_wtimer_node_t *wt)
352
-{
353
-	uint32_t ts;
354
-
355
-	ts = (cs + wt->interval) % SR_WTIMER_SIZE;
356
-	wt->eloop = wt->interval / SR_WTIMER_SIZE;
357
-	wt->next = _sr_wtimer->wlist[ts];
358
-	_sr_wtimer->wlist[ts] = wt;
359
-
360
-	return 0;
361
-}
362
-
363
-/**
364
- *
365
- */
366
-void sr_wtimer_exec(unsigned int ticks, void *param)
367
-{
368
-	sr_wtimer_node_t *wt;
369
-	sr_wtimer_node_t *wn;
370
-	sr_wtimer_node_t *wp;
371
-	uint32_t cs;
372
-
373
-	if(_sr_wtimer==NULL) {
374
-		LM_ERR("wtimer not initialized\n");
375
-		return;
376
-	}
377
-
378
-	_sr_wtimer->itimer++;
379
-	cs = _sr_wtimer->itimer % SR_WTIMER_SIZE;
380
-	/* uint32_t cl;
381
-	cl = _sr_wtimer->itimer / SR_WTIMER_SIZE;
382
-	LM_DBG("wtimer - loop: %u - slot: %u\n", cl, cs); */
383
-
384
-	wp = NULL;
385
-	wt=_sr_wtimer->wlist[cs];
386
-	while(wt) {
387
-		wn = wt->next;
388
-		if(wt->eloop==0) {
389
-			/* execute timer callback function */
390
-			wt->f(ticks, wt->param);
391
-			/* extract and reinsert timer item */
392
-			if(wp==NULL) {
393
-				_sr_wtimer->wlist[cs] = wn;
394
-			} else {
395
-				wp->next = wn;
396
-			}
397
-			sr_wtimer_reinsert(cs, wt);
398
-		} else {
399
-			wt->eloop--;
400
-			wp = wt;
401
-		}
402
-		wt = wn;
403
-	}
404
-}
405
-
406
-/**
407
- *
408
- */
409
-int sr_wtimer_start(void)
410
-{
411
-	if(_sr_wtimer==NULL) {
412
-		LM_ERR("wtimer not initialized\n");
413
-		return -1;
414
-	}
415
-
416
-	if(fork_sync_timer(-1 /*PROC_TIMER*/, "secondary timer", 1,
417
-				sr_wtimer_exec, NULL, 1)<0) {
418
-		LM_ERR("wtimer starting failed\n");
419
-		return -1;
420
-	}
421
-
422
-	return 0;
423
-}
424
-
425
-/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
Browse code

core: fix spelling errors catched by lintian #688

Victor Seva authored on 29/06/2016 14:29:17
Showing 1 changed files
... ...
@@ -323,7 +323,7 @@ int sr_wtimer_add(timer_function* f, void* param, int interval)
323 323
 {
324 324
 	sr_wtimer_node_t *wt;
325 325
 	if(_sr_wtimer==NULL) {
326
-		LM_ERR("wtimer not intialized\n");
326
+		LM_ERR("wtimer not initialized\n");
327 327
 		return -1;
328 328
 	}
329 329
 
... ...
@@ -371,7 +371,7 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
371 371
 	uint32_t cs;
372 372
 
373 373
 	if(_sr_wtimer==NULL) {
374
-		LM_ERR("wtimer not intialized\n");
374
+		LM_ERR("wtimer not initialized\n");
375 375
 		return;
376 376
 	}
377 377
 
... ...
@@ -409,7 +409,7 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
409 409
 int sr_wtimer_start(void)
410 410
 {
411 411
 	if(_sr_wtimer==NULL) {
412
-		LM_ERR("wtimer not intialized\n");
412
+		LM_ERR("wtimer not initialized\n");
413 413
 		return -1;
414 414
 	}
415 415
 
Browse code

core: timer - coherent indentation and whitespacing

Daniel-Constantin Mierla authored on 05/05/2016 06:28:19
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * Copyright (C) 2009 iptelorg GmbH
3 3
  *
4 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -48,8 +48,8 @@ int register_basic_timers(int timers)
48 48
 
49 49
 /**
50 50
  * \brief Forks a separate simple sleep() periodic timer
51
- * 
52
- * Forks a very basic periodic timer process, that just sleep()s for 
51
+ *
52
+ * Forks a very basic periodic timer process, that just sleep()s for
53 53
  * the specified interval and then calls the timer function.
54 54
  * The new "basic timer" process execution start immediately, the sleep()
55 55
  * is called first (so the first call to the timer function will happen
... ...
@@ -67,7 +67,7 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
67 67
 						timer_function* f, void* param, int interval)
68 68
 {
69 69
 	int pid;
70
-	
70
+
71 71
 	pid=fork_process(child_id, desc, make_sock);
72 72
 	if (pid<0) return -1;
73 73
 	if (pid==0){
... ...
@@ -77,7 +77,7 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
77 77
 			sleep(interval);
78 78
 			cfg_update();
79 79
 			f(get_ticks(), param); /* ticks in s for compatibility with old
80
-									  timers */
80
+									* timers */
81 81
 		}
82 82
 	}
83 83
 	/* parent */
... ...
@@ -86,8 +86,8 @@ int fork_basic_timer(int child_id, char* desc, int make_sock,
86 86
 
87 87
 /**
88 88
  * \brief Forks a separate simple microsecond-sleep() periodic timer
89
- * 
90
- * Forks a very basic periodic timer process, that just us-sleep()s for 
89
+ *
90
+ * Forks a very basic periodic timer process, that just us-sleep()s for
91 91
  * the specified interval and then calls the timer function.
92 92
  * The new "basic timer" process execution start immediately, the us-sleep()
93 93
  * is called first (so the first call to the timer function will happen
... ...
@@ -106,7 +106,7 @@ int fork_basic_utimer(int child_id, char* desc, int make_sock,
106 106
 {
107 107
 	int pid;
108 108
 	ticks_t ts;
109
-	
109
+
110 110
 	pid=fork_process(child_id, desc, make_sock);
111 111
 	if (pid<0) return -1;
112 112
 	if (pid==0){
... ...
@@ -126,7 +126,7 @@ int fork_basic_utimer(int child_id, char* desc, int make_sock,
126 126
 
127 127
 /**
128 128
  * \brief Forks a timer process based on the local timer
129
- * 
129
+ *
130 130
  * Forks a separate timer process running a local_timer.h type of timer
131 131
  * A pointer to the local_timer handle (allocated in shared memory) is
132 132
  * returned in lt_h. It can be used to add/delete more timers at runtime
... ...
@@ -135,10 +135,10 @@ int fork_basic_utimer(int child_id, char* desc, int make_sock,
135 135
  * used (all the calls to local_timer* must be enclosed by locks if it
136 136
  * cannot be guaranteed that they cannot execute in the same time)
137 137
  * The timer "engine" must be run manually from the child process. For
138
- * example a very simple local timer process that just runs a single 
138
+ * example a very simple local timer process that just runs a single
139 139
  * periodic timer can be started in the following way:
140 140
  * struct local_timer* lt_h;
141
- * 
141
+ *
142 142
  * pid=fork_local_timer_process(...., &lt_h);
143 143
  * if (pid==0){
144 144
  *          timer_init(&my_timer, my_timer_f, 0, 0);
... ...
@@ -157,7 +157,7 @@ int fork_local_timer_process(int child_id, char* desc, int make_sock,
157 157
 {
158 158
 	int pid;
159 159
 	struct local_timer* lt;
160
-	
160
+
161 161
 	lt=shm_malloc(sizeof(*lt));
162 162
 	if (lt==0) goto error;
163 163
 	if (init_local_timer(lt, get_ticks_raw())<0) goto error;
... ...
@@ -186,7 +186,7 @@ int register_sync_timers(int timers)
186 186
 /**
187 187
  * \brief Forks a separate simple sleep() -&- sync periodic timer
188 188
  *
189
- * Forks a very basic periodic timer process, that just sleep()s for 
189
+ * Forks a very basic periodic timer process, that just sleep()s for
190 190
  * the specified interval and then calls the timer function.
191 191
  * The new "sync timer" process execution start immediately, the sleep()
192 192
  * is called first (so the first call to the timer function will happen
... ...
@@ -222,7 +222,7 @@ int fork_sync_timer(int child_id, char* desc, int make_sock,
222 222
 			ts1 = get_ticks_raw();
223 223
 			cfg_update();
224 224
 			f(TICKS_TO_S(ts1), param); /* ticks in sec for compatibility with old
225
-									  timers */
225
+										* timers */
226 226
 			/* adjust the next sleep duration */
227 227
 			ts2 = interval - TICKS_TO_MS(get_ticks_raw()) + TICKS_TO_MS(ts1);
228 228
 		}
... ...
@@ -235,7 +235,7 @@ int fork_sync_timer(int child_id, char* desc, int make_sock,
235 235
 /**
236 236
  * \brief Forks a separate simple microsecond-sleep() -&- sync periodic timer
237 237
  *
238
- * Forks a very basic periodic timer process, that just us-sleep()s for 
238
+ * Forks a very basic periodic timer process, that just us-sleep()s for
239 239
  * the specified interval and then calls the timer function.
240 240
  * The new "sync timer" process execution start immediately, the us-sleep()
241 241
  * is called first (so the first call to the timer function will happen
Browse code

core: avoid compiler warning about variable cl being set but not used

Juha Heinanen authored on 04/02/2016 02:43:40
Showing 1 changed files
... ...
@@ -369,7 +369,6 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
369 369
 	sr_wtimer_node_t *wn;
370 370
 	sr_wtimer_node_t *wp;
371 371
 	uint32_t cs;
372
-	uint32_t cl;
373 372
 
374 373
 	if(_sr_wtimer==NULL) {
375 374
 		LM_ERR("wtimer not intialized\n");
... ...
@@ -378,8 +377,9 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
378 377
 
379 378
 	_sr_wtimer->itimer++;
380 379
 	cs = _sr_wtimer->itimer % SR_WTIMER_SIZE;
380
+	/* uint32_t cl;
381 381
 	cl = _sr_wtimer->itimer / SR_WTIMER_SIZE;
382
-	/* LM_DBG("wtimer - loop: %u - slot: %u\n", cl, cs); */
382
+	LM_DBG("wtimer - loop: %u - slot: %u\n", cl, cs); */
383 383
 
384 384
 	wp = NULL;
385 385
 	wt=_sr_wtimer->wlist[cs];
Browse code

core: wtimer - disabled debug message

Daniel-Constantin Mierla authored on 01/02/2016 23:01:31
Showing 1 changed files
... ...
@@ -379,7 +379,7 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
379 379
 	_sr_wtimer->itimer++;
380 380
 	cs = _sr_wtimer->itimer % SR_WTIMER_SIZE;
381 381
 	cl = _sr_wtimer->itimer / SR_WTIMER_SIZE;
382
-	LM_DBG("wtimer - loop: %u - slot: %u\n", cl, cs);
382
+	/* LM_DBG("wtimer - loop: %u - slot: %u\n", cl, cs); */
383 383
 
384 384
 	wp = NULL;
385 385
 	wt=_sr_wtimer->wlist[cs];
Browse code

core: secondary timer implemented as classic wheel timer (wtimer)

Daniel-Constantin Mierla authored on 25/01/2016 23:35:57
Showing 1 changed files
... ...
@@ -284,8 +284,9 @@ int fork_sync_utimer(int child_id, char* desc, int make_sock,
284 284
 typedef struct sr_wtimer_node {
285 285
 	struct sr_wtimer_node *next;
286 286
 	uint32_t interval;  /* frequency of execution (secs) */
287
-	uint32_t steps;     /* interval = loops * SR_WTIMER_SIZE + steps */
287
+	uint32_t steps;     /* init: interval = loops * SR_WTIMER_SIZE + steps */
288 288
 	uint32_t loops;
289
+	uint32_t eloop;
289 290
 	timer_function* f;
290 291
 	void* param;
291 292
 } sr_wtimer_node_t;
... ...
@@ -337,20 +338,38 @@ int sr_wtimer_add(timer_function* f, void* param, int interval)
337 338
 	wt->interval = interval;
338 339
 	wt->steps = interval % SR_WTIMER_SIZE;
339 340
 	wt->loops = interval / SR_WTIMER_SIZE;
341
+	wt->eloop = wt->loops;
340 342
 	wt->next = _sr_wtimer->wlist[wt->steps];
341 343
 	_sr_wtimer->wlist[wt->steps] = wt;
342 344
 
343 345
 	return 0;
344 346
 }
345 347
 
348
+/**
349
+ *
350
+ */
351
+int sr_wtimer_reinsert(uint32_t cs, sr_wtimer_node_t *wt)
352
+{
353
+	uint32_t ts;
354
+
355
+	ts = (cs + wt->interval) % SR_WTIMER_SIZE;
356
+	wt->eloop = wt->interval / SR_WTIMER_SIZE;
357
+	wt->next = _sr_wtimer->wlist[ts];
358
+	_sr_wtimer->wlist[ts] = wt;
359
+
360
+	return 0;
361
+}
362
+
346 363
 /**
347 364
  *
348 365
  */
349 366
 void sr_wtimer_exec(unsigned int ticks, void *param)
350 367
 {
351 368
 	sr_wtimer_node_t *wt;
352
-	uint32_t i;
353
-	uint32_t c;
369
+	sr_wtimer_node_t *wn;
370
+	sr_wtimer_node_t *wp;
371
+	uint32_t cs;
372
+	uint32_t cl;
354 373
 
355 374
 	if(_sr_wtimer==NULL) {
356 375
 		LM_ERR("wtimer not intialized\n");
... ...
@@ -358,17 +377,29 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
358 377
 	}
359 378
 
360 379
 	_sr_wtimer->itimer++;
361
-	c = _sr_wtimer->itimer / SR_WTIMER_SIZE;
362
-
363
-	for(i=1; i<=SR_WTIMER_SIZE; i++) {
364
-		if(_sr_wtimer->itimer % i == 0) {
365
-			for(wt=_sr_wtimer->wlist[i % SR_WTIMER_SIZE];
366
-					wt!=NULL; wt = wt->next) {
367
-				if(wt->loops==0 || (c % wt->loops==0)) {
368
-					wt->f(ticks, wt->param);
369
-				}
380
+	cs = _sr_wtimer->itimer % SR_WTIMER_SIZE;
381
+	cl = _sr_wtimer->itimer / SR_WTIMER_SIZE;
382
+	LM_DBG("wtimer - loop: %u - slot: %u\n", cl, cs);
383
+
384
+	wp = NULL;
385
+	wt=_sr_wtimer->wlist[cs];
386
+	while(wt) {
387
+		wn = wt->next;
388
+		if(wt->eloop==0) {
389
+			/* execute timer callback function */
390
+			wt->f(ticks, wt->param);
391
+			/* extract and reinsert timer item */
392
+			if(wp==NULL) {
393
+				_sr_wtimer->wlist[cs] = wn;
394
+			} else {
395
+				wp->next = wn;
370 396
 			}
397
+			sr_wtimer_reinsert(cs, wt);
398
+		} else {
399
+			wt->eloop--;
400
+			wp = wt;
371 401
 		}
402
+		wt = wn;
372 403
 	}
373 404
 }
374 405
 
Browse code

core: renamed cycles to loops to reflect rotation of the wheel timer

Daniel-Constantin Mierla authored on 25/01/2016 22:37:49
Showing 1 changed files
... ...
@@ -278,13 +278,14 @@ int fork_sync_utimer(int child_id, char* desc, int make_sock,
278 278
 }
279 279
 
280 280
 
281
+/* number of slots in the wheel timer */
281 282
 #define SR_WTIMER_SIZE	16
282 283
 
283 284
 typedef struct sr_wtimer_node {
284 285
 	struct sr_wtimer_node *next;
285
-	uint32_t interval;
286
-	uint32_t steps;
287
-	uint32_t cycles;
286
+	uint32_t interval;  /* frequency of execution (secs) */
287
+	uint32_t steps;     /* interval = loops * SR_WTIMER_SIZE + steps */
288
+	uint32_t loops;
288 289
 	timer_function* f;
289 290
 	void* param;
290 291
 } sr_wtimer_node_t;
... ...
@@ -335,7 +336,7 @@ int sr_wtimer_add(timer_function* f, void* param, int interval)
335 336
 	wt->param = param;
336 337
 	wt->interval = interval;
337 338
 	wt->steps = interval % SR_WTIMER_SIZE;
338
-	wt->cycles = interval / SR_WTIMER_SIZE;
339
+	wt->loops = interval / SR_WTIMER_SIZE;
339 340
 	wt->next = _sr_wtimer->wlist[wt->steps];
340 341
 	_sr_wtimer->wlist[wt->steps] = wt;
341 342
 
... ...
@@ -363,7 +364,7 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
363 364
 		if(_sr_wtimer->itimer % i == 0) {
364 365
 			for(wt=_sr_wtimer->wlist[i % SR_WTIMER_SIZE];
365 366
 					wt!=NULL; wt = wt->next) {
366
-				if(wt->cycles==0 || (c % wt->cycles==0)) {
367
+				if(wt->loops==0 || (c % wt->loops==0)) {
367 368
 					wt->f(ticks, wt->param);
368 369
 				}
369 370
 			}
Browse code

core: wheel timer advertised as secondary timer

- safety checks when running wtimer functions

Daniel-Constantin Mierla authored on 21/01/2016 13:44:44
Showing 1 changed files
... ...
@@ -304,7 +304,7 @@ int sr_wtimer_init(void)
304 304
 	if(_sr_wtimer!=NULL)
305 305
 		return 0;
306 306
 	_sr_wtimer = (sr_wtimer_t *)pkg_malloc(sizeof(sr_wtimer_t));
307
-	if(_sr_wtimer!=NULL) {
307
+	if(_sr_wtimer==NULL) {
308 308
 		LM_ERR("no more pkg memory\n");
309 309
 		return -1;
310 310
 	}
... ...
@@ -320,7 +320,7 @@ int sr_wtimer_init(void)
320 320
 int sr_wtimer_add(timer_function* f, void* param, int interval)
321 321
 {
322 322
 	sr_wtimer_node_t *wt;
323
-	if(_sr_wtimer!=NULL) {
323
+	if(_sr_wtimer==NULL) {
324 324
 		LM_ERR("wtimer not intialized\n");
325 325
 		return -1;
326 326
 	}
... ...
@@ -351,7 +351,7 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
351 351
 	uint32_t i;
352 352
 	uint32_t c;
353 353
 
354
-	if(_sr_wtimer!=NULL) {
354
+	if(_sr_wtimer==NULL) {
355 355
 		LM_ERR("wtimer not intialized\n");
356 356
 		return;
357 357
 	}
... ...
@@ -376,12 +376,12 @@ void sr_wtimer_exec(unsigned int ticks, void *param)
376 376
  */
377 377
 int sr_wtimer_start(void)
378 378
 {
379
-	if(_sr_wtimer!=NULL) {
379
+	if(_sr_wtimer==NULL) {
380 380
 		LM_ERR("wtimer not intialized\n");
381 381
 		return -1;
382 382
 	}
383 383
 
384
-	if(fork_sync_timer(-1 /*PROC_TIMER*/, "WTIMER", 1,
384
+	if(fork_sync_timer(-1 /*PROC_TIMER*/, "secondary timer", 1,
385 385
 				sr_wtimer_exec, NULL, 1)<0) {
386 386
 		LM_ERR("wtimer starting failed\n");
387 387
 		return -1;
Browse code

core: wheel timer implementation

- to be shared by modules needing to execute timer tasks, don't want to
interfere with main core timers, but don't do lots of operations to
create own timer

Daniel-Constantin Mierla authored on 21/01/2016 13:17:37
Showing 1 changed files
... ...
@@ -278,4 +278,116 @@ int fork_sync_utimer(int child_id, char* desc, int make_sock,
278 278
 }
279 279
 
280 280
 
281
+#define SR_WTIMER_SIZE	16
282
+
283
+typedef struct sr_wtimer_node {
284
+	struct sr_wtimer_node *next;
285
+	uint32_t interval;
286
+	uint32_t steps;
287
+	uint32_t cycles;
288
+	timer_function* f;
289
+	void* param;
290
+} sr_wtimer_node_t;
291
+
292
+typedef struct sr_wtimer {
293
+	uint32_t itimer;
294
+	sr_wtimer_node_t *wlist[SR_WTIMER_SIZE];
295
+} sr_wtimer_t;
296
+
297
+static sr_wtimer_t *_sr_wtimer = NULL;;
298
+
299
+/**
300
+ *
301
+ */
302
+int sr_wtimer_init(void)
303
+{
304
+	if(_sr_wtimer!=NULL)
305
+		return 0;
306
+	_sr_wtimer = (sr_wtimer_t *)pkg_malloc(sizeof(sr_wtimer_t));
307
+	if(_sr_wtimer!=NULL) {
308
+		LM_ERR("no more pkg memory\n");
309
+		return -1;
310
+	}
311
+
312
+	memset(_sr_wtimer, 0, sizeof(sr_wtimer_t));
313
+	register_sync_timers(1);
314
+	return 0;
315
+}
316
+
317
+/**
318
+ *
319
+ */
320
+int sr_wtimer_add(timer_function* f, void* param, int interval)
321
+{
322
+	sr_wtimer_node_t *wt;
323
+	if(_sr_wtimer!=NULL) {
324
+		LM_ERR("wtimer not intialized\n");
325
+		return -1;
326
+	}
327
+
328
+	wt = (sr_wtimer_node_t*)pkg_malloc(sizeof(sr_wtimer_node_t));
329
+	if(wt==NULL) {
330
+		LM_ERR("no more pkg memory\n");
331
+		return -1;
332
+	}
333
+	memset(wt, 0, sizeof(sr_wtimer_node_t));
334
+	wt->f = f;
335
+	wt->param = param;
336
+	wt->interval = interval;
337
+	wt->steps = interval % SR_WTIMER_SIZE;
338
+	wt->cycles = interval / SR_WTIMER_SIZE;
339
+	wt->next = _sr_wtimer->wlist[wt->steps];
340
+	_sr_wtimer->wlist[wt->steps] = wt;
341
+
342
+	return 0;
343
+}
344
+
345
+/**
346
+ *
347
+ */
348
+void sr_wtimer_exec(unsigned int ticks, void *param)
349
+{
350
+	sr_wtimer_node_t *wt;
351
+	uint32_t i;
352
+	uint32_t c;
353
+
354
+	if(_sr_wtimer!=NULL) {
355
+		LM_ERR("wtimer not intialized\n");
356
+		return;
357
+	}
358
+
359
+	_sr_wtimer->itimer++;
360
+	c = _sr_wtimer->itimer / SR_WTIMER_SIZE;
361
+
362
+	for(i=1; i<=SR_WTIMER_SIZE; i++) {
363
+		if(_sr_wtimer->itimer % i == 0) {
364
+			for(wt=_sr_wtimer->wlist[i % SR_WTIMER_SIZE];
365
+					wt!=NULL; wt = wt->next) {
366
+				if(wt->cycles==0 || (c % wt->cycles==0)) {
367
+					wt->f(ticks, wt->param);
368
+				}
369
+			}
370
+		}
371
+	}
372
+}
373
+
374
+/**
375
+ *
376
+ */
377
+int sr_wtimer_start(void)
378
+{
379
+	if(_sr_wtimer!=NULL) {
380
+		LM_ERR("wtimer not intialized\n");
381
+		return -1;
382
+	}
383
+
384
+	if(fork_sync_timer(-1 /*PROC_TIMER*/, "WTIMER", 1,
385
+				sr_wtimer_exec, NULL, 1)<0) {
386
+		LM_ERR("wtimer starting failed\n");
387
+		return -1;
388
+	}
389
+
390
+	return 0;
391
+}
392
+
281 393
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */
Browse code

core Update headers, change "SIP-router" to "Kamailio", update doxygen file headers

Olle E. Johansson authored on 03/01/2015 14:15:58
Showing 1 changed files
... ...
@@ -16,7 +16,7 @@
16 16
 
17 17
 /**
18 18
  * @file
19
- * @brief SIP-router core ::  timer - separate process timers
19
+ * @brief Kamailio core ::  timer - separate process timers
20 20
  *
21 21
  *  (unrelated to the main fast and slow timers)
22 22
  *
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /* 
2
- * $Id$
3
- * 
4 2
  * Copyright (C) 2009 iptelorg GmbH
5 3
  *
6 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -15,15 +13,6 @@
15 13
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 14
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 15
  */
18
-/*
19
- * timer_proc.c  - separate process timers
20
- * (unrelated to the main fast and slow timers)
21
- */
22
-/*
23