Skip to content

Commit

Permalink
Don't use CLOCK_UPTIME_RAW if it won't be defined (#16951)
Browse files Browse the repository at this point in the history
This will fix #15957 by not trying to use CLOCK_UPTIME_RAW if the feature test macros are not currently set to make it available.

Since the build system is in charge of the feature test macros, and since this header might be included under any end user program's build system, we can't just #define the macros we would like.

Closes #16951

COPYBARA_INTEGRATE_REVIEW=#16951 from adamnovak:patch-1 cebf44e
FUTURE_COPYBARA_INTEGRATE_REVIEW=#16951 from adamnovak:patch-1 cebf44e
PiperOrigin-RevId: 696207015
  • Loading branch information
adamnovak authored and copybara-github committed Nov 13, 2024
1 parent e27c6d9 commit 1360502
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/google/protobuf/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include "absl/memory/memory.h"
#include "google/protobuf/message_lite.h"

#if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__)
#if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__) && \
(!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
#include <time.h>
#endif

Expand Down Expand Up @@ -728,9 +729,10 @@ class PROTOBUF_EXPORT UntypedMapBase {
map_index_t Seed() const {
uint64_t s = 0;
#if !defined(GOOGLE_PROTOBUF_NO_RDTSC)
#if defined(__APPLE__)
#if defined(__APPLE__) && \
(!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
// Use a commpage-based fast time function on Apple environments (MacOS,
// iOS, tvOS, watchOS, etc).
// iOS, tvOS, watchOS, etc), if we think the system headers expose it.
s = clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#elif defined(__x86_64__) && defined(__GNUC__)
uint32_t hi, lo;
Expand Down

0 comments on commit 1360502

Please sign in to comment.