File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22# configure node for building
33#
44include (CheckFunctionExists )
5-
5+ include (CheckLibraryExists )
6+ include (CheckSymbolExists )
67
78if (NOT "v${CMAKE_BUILD_TYPE } " MATCHES vDebug)
89 set (CMAKE_BUILD_TYPE "Release" )
@@ -72,6 +73,20 @@ else()
7273 add_definitions (-DHAVE_FDATASYNC=0 )
7374endif ()
7475
76+ # check first without rt and then with rt
77+ check_function_exists (clock_gettime HAVE_CLOCK_GETTIME )
78+ check_library_exists (rt clock_gettime "" HAVE_CLOCK_GETTIME_RT )
79+
80+ if (HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_RT)
81+ check_symbol_exists (CLOCK_MONOTONIC "time.h" HAVE_MONOTONIC_CLOCK )
82+ endif ()
83+
84+ if (HAVE_MONOTONIC_CLOCK)
85+ add_definitions (-DHAVE_MONOTONIC_CLOCK=1 )
86+ else ()
87+ add_definitions (-DHAVE_MONOTONIC_CLOCK=0 )
88+ endif ()
89+
7590if (DTRACE)
7691 if (NOT ${node_platform} MATCHES sunos)
7792 message (FATAL_ERROR "DTrace support only currently available on Solaris" )
Original file line number Diff line number Diff line change 1515#include < stdlib.h> // free
1616#include < string.h> // strdup
1717
18+ #if HAVE_MONOTONIC_CLOCK
19+ #include < time.h>
20+ #endif
21+
1822namespace node {
1923
2024using namespace v8 ;
@@ -240,13 +244,21 @@ double Platform::GetTotalMemory() {
240244}
241245
242246double Platform::GetUptimeImpl () {
247+ #if HAVE_MONOTONIC_CLOCK
248+ struct timespec now;
249+ if (0 == clock_gettime (CLOCK_MONOTONIC , &now)) {
250+ double uptime = now.tv_sec ;
251+ uptime += (double )now.tv_nsec / 1000000000.0 ;
252+ return uptime;
253+ }
254+ return -1 ;
255+ #else
243256 struct sysinfo info;
244-
245257 if (sysinfo (&info) < 0 ) {
246258 return -1 ;
247259 }
248-
249260 return static_cast <double >(info.uptime );
261+ #endif
250262}
251263
252264int Platform::GetLoadAvg (Local<Array> *loads) {
Original file line number Diff line number Diff line change @@ -328,7 +328,24 @@ def configure(conf):
328328 elif 'DEST_CPU' in conf .env and conf .env ['DEST_CPU' ]:
329329 conf .env ['DEST_CPU' ] = canonical_cpu_type (conf .env ['DEST_CPU' ])
330330
331- conf .check (lib = 'rt' , uselib_store = 'RT' )
331+ have_librt = conf .check (lib = 'rt' , uselib_store = 'RT' )
332+
333+ have_monotonic = False
334+ if have_librt :
335+ code = """
336+ #include <time.h>
337+ int main(void) {
338+ struct timespec now;
339+ clock_gettime(CLOCK_MONOTONIC, &now);
340+ return 0;
341+ }
342+ """
343+ have_monotonic = conf .check_cc (lib = "rt" , msg = "Checking for CLOCK_MONOTONIC" , fragment = code )
344+
345+ if have_monotonic :
346+ conf .env .append_value ('CPPFLAGS' , '-DHAVE_MONOTONIC_CLOCK=1' )
347+ else :
348+ conf .env .append_value ('CPPFLAGS' , '-DHAVE_MONOTONIC_CLOCK=0' )
332349
333350 if sys .platform .startswith ("sunos" ):
334351 if not conf .check (lib = 'socket' , uselib_store = "SOCKET" ):
You can’t perform that action at this time.
0 commit comments