Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
40d2069d
Unverified
Commit
40d2069d
authored
Jun 28, 2021
by
Mircea Trofin
Committed by
GitHub
Jun 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use C++11 atomic_signal_fence for ClobberMemory (#1190)
* Use C++11 atomic_signal_fence for ClobberMemory * include * Conditionally using std::atomic_signal_fence when C++11 is available
parent
38b767e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
benchmark.h
include/benchmark/benchmark.h
+14
-3
No files found.
include/benchmark/benchmark.h
View file @
40d2069d
...
...
@@ -187,6 +187,7 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#include <vector>
#if defined(BENCHMARK_HAS_CXX11)
#include <atomic>
#include <initializer_list>
#include <type_traits>
#include <utility>
...
...
@@ -327,6 +328,14 @@ BENCHMARK_UNUSED static int stream_init_anchor = InitializeStreams();
#define BENCHMARK_HAS_NO_INLINE_ASSEMBLY
#endif
// Force the compiler to flush pending writes to global memory. Acts as an
// effective read/write barrier
#ifdef BENCHMARK_HAS_CXX11
inline
BENCHMARK_ALWAYS_INLINE
void
ClobberMemory
()
{
std
::
atomic_signal_fence
(
std
::
memory_order_acq_rel
);
}
#endif
// The DoNotOptimize(...) function can be used to prevent a value or
// expression from being optimized away by the compiler. This function is
// intended to add little to no overhead.
...
...
@@ -346,11 +355,11 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) {
#endif
}
// Force the compiler to flush pending writes to global memory. Acts as an
// effective read/write barrier
#ifndef BENCHMARK_HAS_CXX11
inline
BENCHMARK_ALWAYS_INLINE
void
ClobberMemory
()
{
asm
volatile
(
""
:
:
:
"memory"
);
}
#endif
#elif defined(_MSC_VER)
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
...
...
@@ -358,13 +367,15 @@ inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const& value) {
_ReadWriteBarrier
();
}
#ifndef BENCHMARK_HAS_CXX11
inline
BENCHMARK_ALWAYS_INLINE
void
ClobberMemory
()
{
_ReadWriteBarrier
();
}
#endif
#else
template
<
class
Tp
>
inline
BENCHMARK_ALWAYS_INLINE
void
DoNotOptimize
(
Tp
const
&
value
)
{
internal
::
UseCharPointer
(
&
reinterpret_cast
<
char
const
volatile
&>
(
value
));
}
// FIXME Add ClobberMemory() for non-gnu and non-msvc compilers
// FIXME Add ClobberMemory() for non-gnu and non-msvc compilers
, before C++11.
#endif
// This class is used for user-defined counters.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment