File: time_util.cc

package info (click to toggle)
xgalaga%2B%2B 0.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 360 kB
  • ctags: 557
  • sloc: cpp: 2,715; makefile: 128
file content (24 lines) | stat: -rw-r--r-- 541 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "time_util.h"
#include <sys/time.h>
#include <sys/select.h>


double CurrentMicroSecond()
{
	timeval now;
	gettimeofday(&now, 0);
	return now.tv_sec + now.tv_usec / 1000000.0;
}


double SleepTimeInterval(double interval_start_time, double interval)
{
	const double remaining (interval_start_time + interval - CurrentMicroSecond());
	if (remaining > 0) {
		timeval timeout;
		timeout.tv_sec  = remaining;
		timeout.tv_usec = (remaining - timeout.tv_sec) * 1000000;
		select(0, 0, 0, 0, &timeout);
	}
	return CurrentMicroSecond();
}