grpc
third_party
abseil-cpp
absl
base
internal
abseil-cpp/absl/base/internal/spinlock_benchmark.cc
Go to the documentation of this file.
1
// Copyright 2018 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// See also //absl/synchronization:mutex_benchmark for a comparison of SpinLock
16
// and Mutex performance under varying levels of contention.
17
18
#include "absl/base/internal/raw_logging.h"
19
#include "absl/base/internal/scheduling_mode.h"
20
#include "absl/base/internal/spinlock.h"
21
#include "absl/synchronization/internal/create_thread_identity.h"
22
#include "benchmark/benchmark.h"
23
24
namespace
{
25
26
template
<absl::base_
int
ernal::SchedulingMode scheduling_mode>
27
static
void
BM_SpinLock(
benchmark::State
&
state
) {
28
// Ensure a ThreadIdentity is installed.
29
ABSL_INTERNAL_CHECK
(
30
absl::synchronization_internal::GetOrCreateCurrentThreadIdentity
() !=
31
nullptr
,
32
"GetOrCreateCurrentThreadIdentity() failed"
);
33
34
static
auto
* spinlock =
new
absl::base_internal::SpinLock
(scheduling_mode);
35
for
(
auto
_
:
state
) {
36
absl::base_internal::SpinLockHolder
holder(spinlock);
37
}
38
}
39
40
BENCHMARK_TEMPLATE
(BM_SpinLock,
41
absl::base_internal::SCHEDULE_KERNEL_ONLY
)
42
->UseRealTime()
43
->Threads(1)
44
->ThreadPerCpu();
45
46
BENCHMARK_TEMPLATE
(BM_SpinLock,
47
absl::base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL
)
48
->UseRealTime()
49
->Threads(1)
50
->ThreadPerCpu();
51
52
}
// namespace
absl::synchronization_internal::GetOrCreateCurrentThreadIdentity
base_internal::ThreadIdentity * GetOrCreateCurrentThreadIdentity()
Definition:
abseil-cpp/absl/synchronization/internal/create_thread_identity.h:43
absl::base_internal::SpinLockHolder
Definition:
third_party/abseil-cpp/absl/base/internal/spinlock.h:196
ABSL_INTERNAL_CHECK
#define ABSL_INTERNAL_CHECK(condition, message)
Definition:
abseil-cpp/absl/base/internal/raw_logging.h:85
absl::base_internal::SpinLock
Definition:
third_party/abseil-cpp/absl/base/internal/spinlock.h:52
BENCHMARK_TEMPLATE
#define BENCHMARK_TEMPLATE(n, a)
Definition:
benchmark/include/benchmark/benchmark.h:1231
gmock_output_test._
_
Definition:
bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
absl::base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL
@ SCHEDULE_COOPERATIVE_AND_KERNEL
Definition:
abseil-cpp/absl/base/internal/scheduling_mode.h:51
absl::base_internal::SCHEDULE_KERNEL_ONLY
@ SCHEDULE_KERNEL_ONLY
Definition:
abseil-cpp/absl/base/internal/scheduling_mode.h:50
benchmark::State
Definition:
benchmark/include/benchmark/benchmark.h:503
state
Definition:
bloaty/third_party/zlib/contrib/blast/blast.c:41
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:15