From 1024b52f2cdc1a0975d96f8aceb861ddcccba806 Mon Sep 17 00:00:00 2001 From: volker Date: Wed, 13 Feb 2013 14:00:30 +0000 Subject: Ticket #284 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1193 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- svn_version.h | 2 +- timer_group.c | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/svn_version.h b/svn_version.h index 5df47cf..c5c25bc 100644 --- a/svn_version.h +++ b/svn_version.h @@ -1 +1 @@ -#define SVN_VERSION "1192" +#define SVN_VERSION "1193" diff --git a/timer_group.c b/timer_group.c index 777c2db..4dfbb1b 100644 --- a/timer_group.c +++ b/timer_group.c @@ -75,10 +75,10 @@ /* structure for storing all relevant data of a single timer group */ typedef struct TIMER_GROUP { - /* group's triggering interval in milliseconds; + /* pointer to the group's triggering interval in milliseconds; this will be used to identify a specific timer group and also as callback data for the underlying generic timer */ - int interval; + int *interval; /* marks timer group as being active (so it will get processed) or inactive (which means the timer group has been deleted and its @@ -144,7 +144,7 @@ int timer_group_exists(const int interval) if (TimerGroups[group].active == TIMER_INACTIVE) continue; - if (TimerGroups[group].interval == interval) { + if (*TimerGroups[group].interval == interval) { /* matching timer group found, so signal success by returning a value of 1 */ return 1; @@ -185,6 +185,7 @@ int timer_add_group(const int interval) if (TimerGroups[group].active == TIMER_INACTIVE) { /* we've just found one, so let's reuse it ("group" holds its ID) by breaking the loop */ + debug("Reusing Timergroup %i", group); break; } } @@ -195,15 +196,21 @@ int timer_add_group(const int interval) TIMER_GROUP *tmp; if ((tmp = realloc(TimerGroups, (nTimerGroups + 1) * sizeof(*TimerGroups))) == NULL) { + error("Error expanding TimerGroups"); /* signal unsuccessful timer group creation */ return -1; } TimerGroups = tmp; nTimerGroups++; + + if ((TimerGroups[group].interval = malloc(sizeof(int))) == NULL) { + /* signal unsuccessful timer group creation */ + return -1; + } } /* initialize timer group's interval */ - TimerGroups[group].interval = interval; + *TimerGroups[group].interval = interval; /* set timer group to active so that it is processed and not overwritten by the memory optimization routine above */ @@ -211,7 +218,7 @@ int timer_add_group(const int interval) /* finally, request a generic timer that calls this group and signal success or failure */ - return timer_add(timer_process_group, &TimerGroups[group].interval, interval, 0); + return timer_add(timer_process_group, TimerGroups[group].interval, interval, 0); } @@ -255,7 +262,7 @@ int timer_remove_group(const int interval) if (TimerGroups[group].active == TIMER_INACTIVE) continue; - if (TimerGroups[group].interval == interval) { + if (*TimerGroups[group].interval == interval) { /* we have found the timer group slot, so mark it as being inactive; we will not actually delete the slot, so its allocated memory may be re-used */ @@ -504,7 +511,11 @@ void timer_exit_group(void) /* loop through all timer groups and remove them one by one */ for (group = 0; group < nTimerGroups; group++) { /* remove generic timer */ - timer_remove(timer_process_group, &TimerGroups[group].interval); + timer_remove(timer_process_group, TimerGroups[group].interval); + + /* free memory allocated for callback data (i.e. the group's + triggering interval in milliseconds) */ + free(TimerGroups[group].interval); } /* reset number of allocated timer groups */ -- cgit v1.2.3