Cleaned up code

Moved current_utc_time out of the central tlUtils header where
it does not belong. It a time function, so tlTimer.h is the better
place. Plus it does not make sense to make this inline. This just
spoils build times on changes.
This commit is contained in:
Matthias Koefferlein 2018-07-29 10:06:11 +02:00
parent 3efde26584
commit 3d7bd0f32d
3 changed files with 31 additions and 27 deletions

View File

@ -36,9 +36,33 @@
# include <unistd.h>
#endif
#if defined(__MACH__)
#include <mach/clock.h>
#include <mach/mach.h>
#endif
namespace tl
{
// -------------------------------------------------------------
void current_utc_time (struct timespec *ts)
{
#if defined(__MACH__)
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, ts);
#endif
}
// -------------------------------------------------------------
// Gets the current time in ms from epoch

View File

@ -28,12 +28,19 @@
#include <string>
#include <stdint.h>
#include <time.h>
class QDateTime;
namespace tl
{
/**
* @brief clock_gettime is not implemented in Mac OS X 10.11 and lower
* From: https://gist.githubusercontent.com/jbenet/1087739/raw/638b37f76cdd9dc46d617443cab27eac297e2ee3/current_utc_time.c
*/
void current_utc_time (struct timespec *ts);
/**
* @brief A basic timer class
*

View File

@ -27,37 +27,10 @@
#include "tlAssert.h"
#include <map>
#include <time.h>
#if defined(__MACH__)
#include <mach/clock.h>
#include <mach/mach.h>
#endif
namespace tl
{
/**
* @brief clock_gettime is not implemented in Mac OS X 10.11 and lower
* From: https://gist.githubusercontent.com/jbenet/1087739/raw/638b37f76cdd9dc46d617443cab27eac297e2ee3/current_utc_time.c
*/
inline void current_utc_time(struct timespec *ts) {
#if defined(__MACH__)
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, ts);
#endif
}
/**
* @brief A template class mapping a begin .. end iterator pair to the at_end semantics
*/