cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
windows_sync_barrier.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <Windows.h>
23#include <fmt/format.h>
24#include <synchapi.h>
25
28
29namespace stat_bench {
30namespace util {
31
36class WindowsSyncBarrier final : public ISyncBarrier {
37public:
43 explicit WindowsSyncBarrier(std::size_t num_waiting_threads) {
44 if (num_waiting_threads < 2U) {
46 "Invalid number of threads to wait in WindowsSyncBarrier.");
47 }
48 BOOL result = InitializeSynchronizationBarrier(
49 &barrier_, static_cast<LONG>(num_waiting_threads), -1);
50 if (result == FALSE) {
51 throw StatBenchException(fmt::format(
52 "Failed to initialize WindowsSyncBarrier (error code: {}).",
53 GetLastError()));
54 }
55 }
56
60 void wait() override { EnterSynchronizationBarrier(&barrier_, 0); }
61
64 auto operator=(const WindowsSyncBarrier&) = delete;
65 auto operator=(WindowsSyncBarrier&&) = delete;
66
68 ~WindowsSyncBarrier() override { DeleteSynchronizationBarrier(&barrier_); }
69
70private:
72 SYNCHRONIZATION_BARRIER barrier_{};
73};
74
75} // namespace util
76} // namespace stat_bench
Class of exceptions in this library.
Class of barriers to synchronize threads using synchronization barriers in Windows.
void wait() override
Wait for other threads.
WindowsSyncBarrier(std::size_t num_waiting_threads)
Constructor.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.
Definition of StatBenchException class.
Definition of SyncBarrier class.