Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
I'm trying to use the timer in usrloc to access a function in a module I made, but am encountering an odd problem. In a file from my module called add_entry.c I declare an integer as a global variable and set it to a certain value initially. The variable's value is then set to something else in the module's mod_init function, which of course runs right after the module starts. Next, a function in this file called add_xml_entry runs approximately every 10 seconds indefinitely, and each time it runs it increments the above mentioned integer variable.
Meanwhile, the timer in usrloc is running and going off every 60 seconds, as is the default. One of the functions that gets called in my setup as a result of the timer is "nodb_timer" in urecord.c. In this function I added a call to another function from my add_entry.c file called read_entry. This function simply reads the value of the integer global variable and prints it to the Terminal.
The problem is that when read_entry is called from within nodb_timer, it returns the value that the integer is set to in my module's mod_init function, rather than the value that add_xml_entry sets it to, even though add_xml_entry has run several times since mod_init first ran (and mod_init only runs once, at the beginning). Also, if I call read_entry from anywhere else in urecord.c, it reads the right value (the value that add_xml_entry sets) even though in both instances read_entry is undoubtedly being called after add_xml_entry has run several times.
So, considering I can read the proper value from within urecord.c when I'm not reading it from within a timer-initiated function, it seems that there's some issue with using a timer function from usrloc to read my variable from my function. Would this make sense? If not, can anyone think of another reason for this problem?
Also, I found this comment on line 173 of timer.c, and it seems that it might be related to this problem. Could anyone elaborate on this comment?:
"Hint: if you need in a module, register it from mod_init or it won't work otherwise"
Thanks in advance for the help!