Browse Source

drouting: option to use a static structure for computing ac max val

Daniel-Constantin Mierla 7 years ago
parent
commit
b3e14fc9bd
2 changed files with 17 additions and 10 deletions
  1. 16 9
      src/modules/drouting/dr_time.c
  2. 1 1
      src/modules/drouting/dr_time.h

+ 16 - 9
src/modules/drouting/dr_time.c

@@ -203,17 +203,22 @@ int ac_tm_free(ac_tm_p _atp)
 	return 0;
 }
 
-ac_maxval_p ac_get_maxval(ac_tm_p _atp)
+ac_maxval_p ac_get_maxval(ac_tm_p _atp, int mode)
 {
 	struct tm _tm;
 	int _v;
 	ac_maxval_p _amp = NULL;
+	static ac_maxval_t _amv;
 
 	if(!_atp)
 		return NULL;
-	_amp = (ac_maxval_p)shm_malloc(sizeof(ac_maxval_t));
-	if(!_amp)
-		return NULL;
+	if(mode==1) {
+		_amp = (ac_maxval_p)shm_malloc(sizeof(ac_maxval_t));
+		if(!_amp)
+			return NULL;
+	} else {
+		_amp = &_amv;
+	}
 	memset(_amp, 0, sizeof(ac_maxval_t));
 
 	/* the number of the days in the year */
@@ -270,11 +275,13 @@ ac_maxval_p ac_get_maxval(ac_tm_p _atp)
 				  + 1;
 #endif
 
-	if(_atp->mv!=NULL) {
-		shm_free(_atp->mv);
-	}
+	if(mode==1) {
+		if(_atp->mv!=NULL) {
+			shm_free(_atp->mv);
+		}
 
-	_atp->mv = _amp;
+		_atp->mv = _amp;
+	}
 	return _amp;
 }
 
@@ -1050,7 +1057,7 @@ int check_byxxx(tmrec_p _trp, ac_tm_p _atp)
 			&& !_trp->byweekno)
 		return REC_MATCH;
 
-	_amp = ac_get_maxval(_atp);
+	_amp = ac_get_maxval(_atp, 0);
 	if(!_amp)
 		return REC_NOMATCH;
 

+ 1 - 1
src/modules/drouting/dr_time.h

@@ -76,7 +76,7 @@ int ac_tm_free(ac_tm_p);
 
 int ac_get_mweek(struct tm *);
 int ac_get_yweek(struct tm *);
-ac_maxval_p ac_get_maxval(ac_tm_p);
+ac_maxval_p ac_get_maxval(ac_tm_p, int);
 int ac_get_wkst();
 
 int ac_print(ac_tm_p);