diff --git a/src/sdptr.cpp b/src/sdptr.cpp index 4002c3b7b54624e0ba2f9a865b38e3f3485404eb..735da970000036cb33a23327d168cb50e51bcca1 100644 --- a/src/sdptr.cpp +++ b/src/sdptr.cpp @@ -70,13 +70,25 @@ void monitor() pthread_cond_init(&SD.newpoint_cond, NULL); SD.uptime = 0; - + gettimeofday(¤t_time, NULL); SD.start_time = current_time.tv_sec; while (ServerRunning) { + struct timespec current_time_timespec; + clock_gettime(CLOCK_REALTIME, (struct timespec *)¤t_time_timespec); + SD.t0.tv_sec = SD.t0.tv_sec + SD.timetick; // specify next position in time + if (SD.t0.tv_sec < current_time_timespec.tv_sec) { + // skip ahead if we already are beyond the next tick. + // this prevents us from trying to catch up if the host system + // was in hibernation or this process was otherwise suspended. + // this means that SD.uptime will reflect the number of seconds + // this process was actually running, and now - SD.start_time + // reflects the wall-clock time that passed since start. + SD.t0.tv_sec = current_time_timespec.tv_sec + SD.timetick; + } SD.t0.tv_nsec = 10000000L; // 0..999999999 // offset 10ms in a new second pthread_mutex_lock(&SD.newpoint_lock); pthread_cond_timedwait(&SD.newpoint_cond, &SD.newpoint_lock, (const struct timespec *)&SD.t0); @@ -104,12 +116,12 @@ void server_init(bool warm_start) ConfigReader* p = ConfigReader::getInstance(); // create object of the class ConfigReader p->parseFile(SD.configfile); // parse the configuration file p->dumpFileValues(); // print map on the console after parsing it - + p->getValue(SD.ant_band_station_type, "n_fpgas", SD.n_fpgas); p->getValue(SD.ant_band_station_type, "first_fpga_nr", SD.first_fpga_nr); p->getValue(SD.ant_band_station_type, "n_beamsets", SD.n_beamsets); p->getValue(SD.ant_band_station_type, "ip_prefix", SD.ip_prefix); - + if (SD.n_fpgas == 0) { cerr << "ERROR, no settings found for '" << SD.ant_band_station_type << "'" <<endl; exit(EXIT_FAILURE); @@ -178,7 +190,7 @@ int main (int argc, char* argv[]) SD.configfile = "/etc/sdptr.conf"; SD.ant_band_station_type = "-"; - + // set default values SD.n_fpgas = 16; SD.first_fpga_nr = 0;