Support clock_gettime() on OSX El Capitan and earlier

This commit is contained in:
Christian Göttsche 2020-12-13 13:16:44 +01:00 committed by BenBE
parent 0401df8cbd
commit 26993d2d2b
4 changed files with 41 additions and 3 deletions

View File

@ -11,12 +11,18 @@ in the source distribution for its full text.
#include <errno.h> #include <errno.h>
#include <fcntl.h> // IWYU pragma: keep #include <fcntl.h> // IWYU pragma: keep
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> // IWYU pragma: keep #include <sys/types.h> // IWYU pragma: keep
#include "XUtils.h" // IWYU pragma: keep #include "XUtils.h" // IWYU pragma: keep
#ifdef HAVE_HOST_GET_CLOCK_SERVICE
#include <mach/clock.h>
#include <mach/mach.h>
#endif
int Compat_faccessat(int dirfd, int Compat_faccessat(int dirfd,
const char* pathname, const char* pathname,
@ -117,3 +123,31 @@ ssize_t Compat_readlinkat(int dirfd,
#endif #endif
} }
int Compat_clock_monotonic_gettime(struct timespec *tp) {
#if defined(HAVE_CLOCK_GETTIME)
return clock_gettime(CLOCK_MONOTONIC, tp);
#elif defined(HAVE_HOST_GET_CLOCK_SERVICE)
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
tp->tv_sec = mts.tv_sec;
tp->tv_nsec = mts.tv_nsec;
return 0;
#else
#error No Compat_clock_monotonic_gettime() implementation!
#endif
}

View File

@ -56,4 +56,6 @@ ssize_t Compat_readlinkat(int dirfd,
char* buf, char* buf,
size_t bufsize); size_t bufsize);
int Compat_clock_monotonic_gettime(struct timespec *tp);
#endif /* HEADER_Compat */ #endif /* HEADER_Compat */

View File

@ -10,8 +10,8 @@ in the source distribution for its full text.
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "Compat.h"
#include "CRT.h" #include "CRT.h"
#include "Hashtable.h" #include "Hashtable.h"
#include "Macros.h" #include "Macros.h"
@ -538,8 +538,8 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
if (!firstScanDone) { if (!firstScanDone) {
this->scanTs = 0; this->scanTs = 0;
firstScanDone = true; firstScanDone = true;
} else if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) { } else if (Compat_clock_monotonic_gettime(&now) == 0) {
this->scanTs = now.tv_sec; this->scanTs = now.tv_sec + now.tv_nsec / 1000000000;
} }
ProcessList_goThroughEntries(this, false); ProcessList_goThroughEntries(this, false);

View File

@ -93,8 +93,10 @@ AC_TYPE_UINT64_T
AC_FUNC_CLOSEDIR_VOID AC_FUNC_CLOSEDIR_VOID
AC_FUNC_STAT AC_FUNC_STAT
AC_CHECK_FUNCS([\ AC_CHECK_FUNCS([\
clock_gettime\
faccessat\ faccessat\
fstatat\ fstatat\
host_get_clock_service\
openat\ openat\
readlinkat\ readlinkat\
]) ])