]> git.webhop.me Git - lcd4linux.git/commitdiff
Ticket #284
authorvolker <volker@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 13 Feb 2013 14:00:30 +0000 (14:00 +0000)
committervolker <volker@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 13 Feb 2013 14:00:30 +0000 (14:00 +0000)
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1193 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

svn_version.h
timer_group.c

index 5df47cf6c508c6950e6a726435b2b311ee28a588..c5c25bcbd6b3e20b65ce64832b5d83ce4936d1a0 100644 (file)
@@ -1 +1 @@
-#define SVN_VERSION "1192"
+#define SVN_VERSION "1193"
index 777c2db50f552ab3dbf28e5c0976f8c9e82e39eb..4dfbb1b49dc46737a45031dd892936878c036259 100644 (file)
 
 /* 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 */