mirror of https://github.com/KLayout/klayout.git
Moved current_utc_time to tlUtils and fixed tlTimer
This commit is contained in:
parent
106b57c676
commit
5f6c265e4b
|
|
@ -23,44 +23,21 @@
|
|||
#if !defined(HAVE_QT)
|
||||
|
||||
#include "tlThreads.h"
|
||||
#include "tlUtils.h"
|
||||
#include "tlLog.h"
|
||||
#include "tlInternational.h"
|
||||
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#if defined(__MACH__)
|
||||
#include <mach/clock.h>
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
namespace tl
|
||||
{
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// 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) {
|
||||
|
||||
#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
|
||||
|
||||
}
|
||||
// -------------------------------------------------------------------------------
|
||||
// WaitCondition implementation
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
|
||||
#include "tlTimer.h"
|
||||
#include "tlUtils.h"
|
||||
#include "tlLog.h"
|
||||
#include "tlString.h"
|
||||
|
||||
|
|
@ -30,7 +31,6 @@
|
|||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _MSC_VER // not available on MS VC++
|
||||
# include <unistd.h>
|
||||
|
|
@ -45,7 +45,7 @@ namespace tl
|
|||
static int64_t ms_time ()
|
||||
{
|
||||
struct timespec spec;
|
||||
clock_gettime (CLOCK_REALTIME, &spec);
|
||||
current_utc_time (&spec);
|
||||
|
||||
return int64_t (spec.tv_sec) * 1000 + int64_t (0.5 + spec.tv_nsec / 1.0e6);
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ Timer::start ()
|
|||
#endif
|
||||
|
||||
struct timespec spec;
|
||||
clock_gettime (CLOCK_REALTIME, &spec);
|
||||
current_utc_time (&spec);
|
||||
|
||||
m_wall_ms += ms_time ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,37 @@
|
|||
#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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue