Browse Source

Explicitly check for clock_nanosleep and only use it when available

Luke Dashjr 12 years ago
parent
commit
e7bae59209
2 changed files with 5 additions and 0 deletions
  1. 1 0
      configure.ac
  2. 4 0
      util.c

+ 1 - 0
configure.ac

@@ -915,6 +915,7 @@ AC_TRY_COMPILE([
 	AC_MSG_RESULT([yes])
 	AC_DEFINE([HAVE_CLOCK_GETTIME_MONOTONIC], [1], [Defined to 1 if clock_gettime(CLOCK_MONOTONIC) is defined])
 	AC_SEARCH_LIBS([clock_gettime],[rt posix4])
+	AC_CHECK_FUNCS([clock_nanosleep])
 	AC_MSG_CHECKING([for clock_gettime(CLOCK_MONOTONIC_RAW)])
 	AC_TRY_COMPILE([
 		#define _GNU_SOURCE

+ 4 - 0
util.c

@@ -1135,6 +1135,7 @@ void _now_clock_gettime(struct timeval *tv)
 	};
 }
 
+#ifdef HAVE_CLOCK_NANOSLEEP
 static
 void _cgsleep_us_r_monotonic(cgtimer_t *tv_start, int64_t us)
 {
@@ -1148,6 +1149,7 @@ void _cgsleep_us_r_monotonic(cgtimer_t *tv_start, int64_t us)
 		ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts_end, NULL);
 	} while (ret == EINTR);
 }
+#endif
 
 static
 bool _bfg_try_clock_gettime(clockid_t clk)
@@ -1176,7 +1178,9 @@ void bfg_init_time()
 	if (_bfg_try_clock_gettime(CLOCK_MONOTONIC))
 	{
 		applog(LOG_DEBUG, "Timers: Using clock_gettime(CLOCK_MONOTONIC)");
+#ifdef HAVE_CLOCK_NANOSLEEP
 		cgsleep_us_r = _cgsleep_us_r_monotonic;
+#endif
 	}
 	else
 #endif