Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Missing GetTickCount64 (Added function on posix platforms for cross compilation)
Missing GetTickCount64 [message #43811] Thu, 23 October 2014 11:50 Go to next message
steffen is currently offline  steffen
Messages: 38
Registered: May 2007
Location: Denmark
Member

Windows Vista and newer has got a GetTickCount64 function, I was recently making a long running application and had a use for a non overflowing timer value.

So here is a simple expansion of the existing block in Core/Utils:

#ifdef PLATFORM_POSIX
dword GetTickCount() {
#if _POSIX_C_SOURCE >= 199309L
	struct timespec tp;
	if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
	{
		return (dword)((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000));
	}
	return 0; // ?? (errno is set)
#else
	struct timeval tv[1];
	struct timezone tz[1];
	memset(tz, 0, sizeof(tz));
	gettimeofday(tv, tz);
	return (dword)tv->tv_sec * 1000 + tv->tv_usec / 1000;
#endif
}

qword GetTickCount64() {
#if _POSIX_C_SOURCE >= 199309L
	struct timespec tp;
	if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
	{
		return (qword)((tp.tv_sec * 1000) + (tp.tv_nsec / 1000000));
	}
	return 0; // ?? (errno is set)
#else
	struct timeval tv[1];
	struct timezone tz[1];
	memset(tz, 0, sizeof(tz));
	gettimeofday(tv, tz);
	return (qword)tv->tv_sec * 1000 + tv->tv_usec / 1000;
#endif
}
#endif
Re: Missing GetTickCount64 [message #43820 is a reply to message #43811] Wed, 29 October 2014 09:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14160
Registered: November 2005
Ultimate Member
It is a good idea, actually, I have a similar task in RM for some time now too. However, I think we might want that for WindowsXP too?
Re: Missing GetTickCount64 [message #43825 is a reply to message #43820] Wed, 29 October 2014 10:27 Go to previous message
Tom1
Messages: 1281
Registered: March 2007
Senior Contributor
Hi,

This is not an easy task. I have spent days or maybe weeks over the last 20 years to get a reliable, precise monotonic timer that works. This relatively recent Microsoft article sheds some light on the task:

http://msdn.microsoft.com/en-us/library/windows/desktop/dn55 3408%28v=vs.85%29.aspx

I guess QueryPerformanceCounter() is the way to go, but it is slow to call and has not been entirely trouble free either. I have solved the problem using the 32 bit timer and some overflow detection solutions to build monotonic timer for longer periods. (Sleeping and hibernating might still be a problem though.)

Best regards,

Tom

Previous Topic: Any good reason why SSL support is hardcoded to SSLv3 usage?
Next Topic: Problem with some keyboard keys
Goto Forum:
  


Current Time: Mon Dec 09 11:22:19 CET 2024

Total time taken to generate the page: 0.02725 seconds