2013-04-03 Koichiro KIKUCHI <koichiro@rworks.jp>

* windows_service.cc: Adjust sleep time so that each iteration *starts"
	 with the same interval.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7921 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
koichirok 2013-04-03 11:15:07 +00:00
parent b1f7bb8836
commit a6afc9a0ad
2 changed files with 29 additions and 5 deletions

View File

@ -1,3 +1,8 @@
2013-04-03 Koichiro KIKUCHI <koichiro@rworks.jp>
* windows_service.cc: Adjust sleep time so that each iteration *starts"
with the same interval.
2013-03-12 Ramon Novoa <rnovoa@artica.es>
* bin/util/pandora_revent.exe: Added to repository. Compiled version of

View File

@ -111,13 +111,32 @@ Windows_Service::setInitFunction (void (Windows_Service::*f) ()) {
*/
void
Windows_Service::execRunFunction () {
int sleep_time_remain;
DWORD tickbase, ticknow;
if (run_function != NULL) {
(this->*run_function) ();
if (sleep_time > 0) {
while (WaitForSingleObject (stop_event, sleep_time) != WAIT_OBJECT_0) {
(this->*run_function) ();
tickbase = GetTickCount();
do {
(this->*run_function) ();
if (sleep_time > 0)
break;
ticknow = GetTickCount();
// Subtract time taken by run_funtion() from sleep_time
// to *start* each iteration with the same interval
sleep_time_remain = sleep_time - (ticknow - tickbase);
if (0 <= sleep_time_remain && sleep_time_remain <= sleep_time) {
tickbase += sleep_time;
} else {
// run_function() took more than "sleep_time", or something goes wrong.
sleep_time_remain = 0; // don't sleep
tickbase = ticknow; // use current ticks as base ticks
}
}
} while (WaitForSingleObject (stop_event, sleep_time_remain) != WAIT_OBJECT_0);
}
}