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 previous 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
 
Read Message
Read Message
Read Message
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 Apr 29 19:50:06 CEST 2024

Total time taken to generate the page: 0.03170 seconds