Within vos_thread.c (in any flavour) the function cyclic_thread looks like:
for (;; )
{
(void) vos_threadDelay(interval);
pFunction(pArguments);
pthread_testcancel();
}
This implementation disregards the amount of time needed by calling and executing pFunction.
The best approach for getting a better delay value would look like:
gettime(start);
pFunction();
gettime(afterwork);
delay(interval-(afterwork-start));
The caveat is clearly time wraparound.
did a prototype in POSIX in [r1324] which demonstrates the task a bit. a key element is the handling of value ranges, which is limited here to a cyclic interval of 4293 milliseconds (rounded).
Related
Commit: [r1324]
Basically the function cyclic_thread is not prefixed with "vos_" which looks strange. Also it seems to be very easy to pull it into the common vos_utils.c as it can be implemented using pure vos functions. Need to have a glance into this, as having thrice the very same code is kind of awkward from the maintenance point of view.
Renamed the function cyclicThread to vos_cyclicThread and had it copied into Posix/vxWorks/Windows vos subfolder - this is a fast but not really thorough solution. Changeset was [r1334]
Related
Commit: [r1334]
Personally i do not feel well pushing the vos_cyclicThread function into the vos_utils.c/h as it is a thread function, which would not fit into the utils category well.
Intoducing a "thread common" c file seems on one hand ok, but the question is, will it not be just a solution out of some kind of coding rule enforcemet.
I close this ticket for now, and raise a new one about the purpose of vos_cyclicThread (which is currently not referenced) and clarification about its whereabouts, leaving overall file structure untouched.