src/hotspot/os/posix/os_posix.cpp
changeset 51989 7ac0ac1e57b6
parent 51106 f605c91e5219
child 52585 f7f90fddce02
--- a/src/hotspot/os/posix/os_posix.cpp	Tue Oct 02 12:08:51 2018 -0700
+++ b/src/hotspot/os/posix/os_posix.cpp	Tue Oct 02 17:12:13 2018 -0400
@@ -1609,10 +1609,25 @@
 // This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC
 
 static int (*_clock_gettime)(clockid_t, struct timespec *);
+static int (*_clock_getres)(clockid_t, struct timespec *);
 static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t);
 
 static bool _use_clock_monotonic_condattr;
 
+// Exported clock functionality
+
+int os::Posix::clock_gettime(clockid_t clock_id, struct timespec *tp) {
+  return _clock_gettime != NULL ? _clock_gettime(clock_id, tp) : -1;
+}
+
+int os::Posix::clock_getres(clockid_t clock_id, struct timespec *tp) {
+  return _clock_getres != NULL ? _clock_getres(clock_id, tp) : -1;
+}
+
+bool os::Posix::supports_monotonic_clock() {
+  return _clock_gettime != NULL;
+}
+
 // Determine what POSIX API's are present and do appropriate
 // configuration.
 void os::Posix::init(void) {
@@ -1620,8 +1635,6 @@
   // NOTE: no logging available when this is called. Put logging
   // statements in init_2().
 
-  // Copied from os::Linux::clock_init(). The duplication is temporary.
-
   // 1. Check for CLOCK_MONOTONIC support.
 
   void* handle = NULL;
@@ -1642,6 +1655,7 @@
   }
 
   _clock_gettime = NULL;
+  _clock_getres = NULL;
 
   int (*clock_getres_func)(clockid_t, struct timespec*) =
     (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
@@ -1656,6 +1670,7 @@
         clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) {
       // Yes, monotonic clock is supported.
       _clock_gettime = clock_gettime_func;
+      _clock_getres = clock_getres_func;
     } else {
 #ifdef NEEDS_LIBRT
       // Close librt if there is no monotonic clock.