From b3e14fc9bd379ad77c13ade0bc60dc32f1d55ade Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 12 Jan 2018 09:50:36 +0100 Subject: [PATCH] drouting: option to use a static structure for computing ac max val --- src/modules/drouting/dr_time.c | 25 ++++++++++++++++--------- src/modules/drouting/dr_time.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/modules/drouting/dr_time.c b/src/modules/drouting/dr_time.c index 879665a07d5..0af2e513260 100644 --- a/src/modules/drouting/dr_time.c +++ b/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; diff --git a/src/modules/drouting/dr_time.h b/src/modules/drouting/dr_time.h index 86c041a6463..67638e2358b 100644 --- a/src/modules/drouting/dr_time.h +++ b/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);