Browse code

- fixed timer get_ticks bug - fixed make modules (no longer tries to build depends for the ser core)

Andrei Pelinescu-Onciul authored on 10/12/2001 16:11:42
Showing 4 changed files
... ...
@@ -58,6 +58,6 @@ TAGS:
58 58
 	
59 59
 
60 60
 ifneq (,$(filter-out clean proper distclean realclean mantainer-clean TAGS \
61
-		tar, $(MAKECMDGOALS)))
61
+		tar modules, $(MAKECMDGOALS)))
62 62
 include $(depends)
63 63
 endif
... ...
@@ -251,7 +251,7 @@ int main_loop()
251 251
 		/* we need another process to act as the timer*/
252 252
 		if (timer_list){
253 253
 				if ((pid=fork())<0){
254
-					LOG(L_CRIT,  "main_loop: Cannot fork\n");
254
+					LOG(L_CRIT,  "ERRROR: main_loop: Cannot fork\n");
255 255
 					goto error;
256 256
 				}
257 257
 				if (pid==0){
... ...
@@ -514,11 +514,16 @@ int main(int argc, char** argv)
514 514
 #endif
515 515
 
516 516
 #ifdef SHM_MEM
517
-	if (shm_mem_init()==-1) {
517
+	if (shm_mem_init()<0) {
518 518
 		LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
519 519
 		goto error;
520 520
 	}
521 521
 #endif
522
+	/*init timer, before parsing the cfg!*/
523
+	if (init_timer()<0){
524
+		LOG(L_CRIT, "could not initialize timer, exiting...\n");
525
+		goto error;
526
+	}
522 527
 
523 528
 	yyin=cfg_stream;
524 529
 	if ((yyparse()!=0)||(cfg_errors)){
... ...
@@ -6,15 +6,42 @@
6 6
 #include "dprint.h"
7 7
 #include "error.h"
8 8
 #include "config.h"
9
+#ifdef SHM_MEM
10
+#include "shm_mem.h"
11
+#endif
9 12
 
10 13
 #include <stdlib.h>
11 14
 
12 15
 
13 16
 struct sr_timer* timer_list=0;
14 17
 
15
-static int jiffies=0;
18
+static int* jiffies=0;
16 19
 static int timer_id=0;
17 20
 
21
+
22
+
23
+/* ret 0 on success, <0 on error*/
24
+int init_timer()
25
+{
26
+#ifdef SHM_MEM
27
+	jiffies=shm_malloc(sizeof(int));
28
+#else
29
+	/* in this case get_ticks won't work! */
30
+	LOG(L_INFO, "WARNING: no shared memory support compiled in"
31
+				" get_ticks won't work\n");
32
+	jiffies=malloc(sizeof(int));
33
+#endif
34
+	if (jiffies==0){
35
+		LOG(L_CRIT, "ERROR: init_timer: could not init jiffies\n");
36
+		return E_OUT_OF_MEM;
37
+	}
38
+	*jiffies=0;
39
+	return 0;
40
+}
41
+
42
+
43
+
44
+	
18 45
 /*register a periodic timer;
19 46
  * ret: <0 on error*/
20 47
 int register_timer(timer_function f, void* param, unsigned int interval)
... ...
@@ -30,7 +57,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
30 30
 	t->timer_f=f;
31 31
 	t->t_param=param;
32 32
 	t->interval=interval;
33
-	t->expires=jiffies+interval;
33
+	t->expires=*jiffies+interval;
34 34
 	/* insert it into the list*/
35 35
 	t->next=timer_list;
36 36
 	timer_list=t;
... ...
@@ -47,23 +74,23 @@ void timer_ticker()
47 47
 	struct sr_timer* t;
48 48
 	unsigned int prev_jiffies;
49 49
 	
50
-	prev_jiffies=jiffies;
51
-	jiffies+=TIMER_TICK;
50
+	prev_jiffies=*jiffies;
51
+	*jiffies+=TIMER_TICK;
52 52
 	/* test for overflow (if tick= 1s =>overflow in 136 years)*/
53
-	if (jiffies<prev_jiffies){ 
53
+	if (*jiffies<prev_jiffies){ 
54 54
 		/*force expire & update every timer, a little buggy but it 
55 55
 		 * happens once in 136 years :) */
56 56
 		for(t=timer_list;t;t=t->next){
57
-			t->expires=jiffies+t->interval;
58
-			t->timer_f(jiffies, t->t_param);
57
+			t->expires=*jiffies+t->interval;
58
+			t->timer_f(*jiffies, t->t_param);
59 59
 		}
60 60
 		return;
61 61
 	}
62 62
 	
63 63
 	for (t=timer_list;t; t=t->next){
64
-		if (jiffies>=t->expires){
65
-			t->expires=jiffies+t->interval;
66
-			t->timer_f(jiffies, t->t_param);
64
+		if (*jiffies>=t->expires){
65
+			t->expires=*jiffies+t->interval;
66
+			t->timer_f(*jiffies, t->t_param);
67 67
 		}
68 68
 	}
69 69
 }
... ...
@@ -72,5 +99,14 @@ void timer_ticker()
72 72
 
73 73
 unsigned int get_ticks()
74 74
 {
75
-	return jiffies;
75
+	if (jiffies==0){
76
+		LOG(L_CRIT, "BUG: get_ticks: jiffies not intialized\n");
77
+		return 0;
78
+	}
79
+#ifndef SHM_MEM
80
+	LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in"
81
+			", returning 0 (probably wrong)");
82
+	return 0;
83
+#endif
84
+	return *jiffies;
76 85
 }
... ...
@@ -29,6 +29,7 @@ extern struct sr_timer* timer_list;
29 29
 
30 30
 
31 31
 
32
+int init_timer();
32 33
 /*register a periodic timer;
33 34
  * ret: <0 on errror*/
34 35
 int register_timer(timer_function f, void* param, unsigned int interval);