Browse Source

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

Andrei Pelinescu-Onciul 24 years ago
parent
commit
d4f2d8b08f
4 changed files with 56 additions and 14 deletions
  1. 1 1
      Makefile.rules
  2. 7 2
      main.c
  3. 47 11
      timer.c
  4. 1 0
      timer.h

+ 1 - 1
Makefile.rules

@@ -58,6 +58,6 @@ TAGS:
 	
 
 ifneq (,$(filter-out clean proper distclean realclean mantainer-clean TAGS \
-		tar, $(MAKECMDGOALS)))
+		tar modules, $(MAKECMDGOALS)))
 include $(depends)
 endif

+ 7 - 2
main.c

@@ -251,7 +251,7 @@ int main_loop()
 		/* we need another process to act as the timer*/
 		if (timer_list){
 				if ((pid=fork())<0){
-					LOG(L_CRIT,  "main_loop: Cannot fork\n");
+					LOG(L_CRIT,  "ERRROR: main_loop: Cannot fork\n");
 					goto error;
 				}
 				if (pid==0){
@@ -514,11 +514,16 @@ int main(int argc, char** argv)
 #endif
 
 #ifdef SHM_MEM
-	if (shm_mem_init()==-1) {
+	if (shm_mem_init()<0) {
 		LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
 		goto error;
 	}
 #endif
+	/*init timer, before parsing the cfg!*/
+	if (init_timer()<0){
+		LOG(L_CRIT, "could not initialize timer, exiting...\n");
+		goto error;
+	}
 
 	yyin=cfg_stream;
 	if ((yyparse()!=0)||(cfg_errors)){

+ 47 - 11
timer.c

@@ -6,15 +6,42 @@
 #include "dprint.h"
 #include "error.h"
 #include "config.h"
+#ifdef SHM_MEM
+#include "shm_mem.h"
+#endif
 
 #include <stdlib.h>
 
 
 struct sr_timer* timer_list=0;
 
-static int jiffies=0;
+static int* jiffies=0;
 static int timer_id=0;
 
+
+
+/* ret 0 on success, <0 on error*/
+int init_timer()
+{
+#ifdef SHM_MEM
+	jiffies=shm_malloc(sizeof(int));
+#else
+	/* in this case get_ticks won't work! */
+	LOG(L_INFO, "WARNING: no shared memory support compiled in"
+				" get_ticks won't work\n");
+	jiffies=malloc(sizeof(int));
+#endif
+	if (jiffies==0){
+		LOG(L_CRIT, "ERROR: init_timer: could not init jiffies\n");
+		return E_OUT_OF_MEM;
+	}
+	*jiffies=0;
+	return 0;
+}
+
+
+
+	
 /*register a periodic timer;
  * ret: <0 on error*/
 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)
 	t->timer_f=f;
 	t->t_param=param;
 	t->interval=interval;
-	t->expires=jiffies+interval;
+	t->expires=*jiffies+interval;
 	/* insert it into the list*/
 	t->next=timer_list;
 	timer_list=t;
@@ -47,23 +74,23 @@ void timer_ticker()
 	struct sr_timer* t;
 	unsigned int prev_jiffies;
 	
-	prev_jiffies=jiffies;
-	jiffies+=TIMER_TICK;
+	prev_jiffies=*jiffies;
+	*jiffies+=TIMER_TICK;
 	/* test for overflow (if tick= 1s =>overflow in 136 years)*/
-	if (jiffies<prev_jiffies){ 
+	if (*jiffies<prev_jiffies){ 
 		/*force expire & update every timer, a little buggy but it 
 		 * happens once in 136 years :) */
 		for(t=timer_list;t;t=t->next){
-			t->expires=jiffies+t->interval;
-			t->timer_f(jiffies, t->t_param);
+			t->expires=*jiffies+t->interval;
+			t->timer_f(*jiffies, t->t_param);
 		}
 		return;
 	}
 	
 	for (t=timer_list;t; t=t->next){
-		if (jiffies>=t->expires){
-			t->expires=jiffies+t->interval;
-			t->timer_f(jiffies, t->t_param);
+		if (*jiffies>=t->expires){
+			t->expires=*jiffies+t->interval;
+			t->timer_f(*jiffies, t->t_param);
 		}
 	}
 }
@@ -72,5 +99,14 @@ void timer_ticker()
 
 unsigned int get_ticks()
 {
-	return jiffies;
+	if (jiffies==0){
+		LOG(L_CRIT, "BUG: get_ticks: jiffies not intialized\n");
+		return 0;
+	}
+#ifndef SHM_MEM
+	LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in"
+			", returning 0 (probably wrong)");
+	return 0;
+#endif
+	return *jiffies;
 }

+ 1 - 0
timer.h

@@ -29,6 +29,7 @@ extern struct sr_timer* timer_list;
 
 
 
+int init_timer();
 /*register a periodic timer;
  * ret: <0 on errror*/
 int register_timer(timer_function f, void* param, unsigned int interval);