proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
Barrier.h
Go to the documentation of this file.
1
/*
2
* Copyright 2018-present Facebook, Inc.
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
*/
16
#pragma once
17
18
#include <condition_variable>
19
#include <mutex>
20
21
#include <stdint.h>
22
23
namespace
folly
{
24
25
namespace
test
{
26
27
struct
Barrier
{
28
explicit
Barrier
(
size_t
count
) :
lock_
(),
cv_
(),
count_
(count) {}
29
30
void
wait
() {
31
std::unique_lock<std::mutex> lockHeld(
lock_
);
32
auto
gen =
gen_
;
33
if
(++
num_
==
count_
) {
34
num_
= 0;
35
gen_
++;
36
cv_
.notify_all();
37
}
else
{
38
cv_
.wait(lockHeld, [&]() {
return
gen ==
gen_
; });
39
}
40
}
41
42
private
:
43
std::mutex
lock_
;
44
std::condition_variable
cv_
;
45
size_t
num_
{0};
46
size_t
count_
;
47
size_t
gen_
{0};
48
};
49
50
}
// namespace test
51
}
// namespace folly
folly::test::Barrier::Barrier
Barrier(size_t count)
Definition:
Barrier.h:28
folly::test::Barrier::wait
void wait()
Definition:
Barrier.h:30
folly::test::Barrier::lock_
std::mutex lock_
Definition:
Barrier.h:43
test
folly
—— Concurrent Priority Queue Implementation ——
Definition:
AtomicBitSet.h:29
folly::test::Barrier::count_
size_t count_
Definition:
Barrier.h:46
folly::test::Barrier::cv_
std::condition_variable cv_
Definition:
Barrier.h:44
folly::test::Barrier::num_
size_t num_
Definition:
Barrier.h:45
count
int * count
Definition:
gmock_stress_test.cc:176
folly::test::Barrier::gen_
size_t gen_
Definition:
Barrier.h:47
mutex
std::mutex mutex
Definition:
StaticSingletonManager.cpp:39
folly::test::Barrier
Definition:
Barrier.h:27
proxygen
folly
folly
synchronization
test
Barrier.h
Generated by
1.8.11