[PATCH] D43981: [XRay] [compiler-rt] [macosx] Add getTSCFrequency implementation for macOS.

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 17:15:30 PST 2018


dberris requested changes to this revision.
dberris added a comment.
This revision now requires changes to proceed.

Just one suggestion below.

Thanks, @nglevin!



================
Comment at: lib/xray/xray_x86_64.cc:101-103
+    if (TimebaseInfo.denom == 0) {
+      mach_timebase_info(&TimebaseInfo);
+    }
----------------
You can turn this into an "assured once" initialisation by doing something like:

```
static const mach_timebase_info_data_t TI = [] {
  mach_timebase_info_data_t LocalTI;
  mach_timebase_info(&LocalTI);
  return LocalTI;
}();
```

This way you let the compiler do the ensuring that the object is initialised once, and only on the first time it's invoked, in a thread-safe manner.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D43981





More information about the llvm-commits mailing list