Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(0.33.0) macOS: Use clock_gettime_nsec_np() for omrtime_hires_clock() #150

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion port/unix/omrtime.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2016 IBM Corp. and others
* Copyright (c) 1991, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -35,8 +35,13 @@
#include <sys/time.h>
#include "omrport.h"

#if defined(OSX)
/* Frequency is nanoseconds / second */
#define OMRTIME_HIRES_CLOCK_FREQUENCY J9CONST_U64(1000000000)
#else /* defined(OSX) */
/* Frequency is microseconds / second */
#define OMRTIME_HIRES_CLOCK_FREQUENCY J9CONST_U64(1000000)
#endif /* defined(OSX) */

#define OMRTIME_NANOSECONDS_PER_SECOND J9CONST_I64(1000000000)

Expand Down Expand Up @@ -154,10 +159,14 @@ omrtime_current_time_millis(struct OMRPortLibrary *portLibrary)
uint64_t
omrtime_hires_clock(struct OMRPortLibrary *portLibrary)
{
#if defined(OSX)
return clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW);
#else /* defined(OSX) */
struct timeval tp;

gettimeofday(&tp, NULL);
return ((uint64_t)tp.tv_sec * 1000000) + (uint64_t)tp.tv_usec;
#endif /* defined(OSX) */
}
/**
* Query OS for clock frequency
Expand Down