Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
thread_barrier_test.cc
Go to the documentation of this file.
1
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
5
#include "
vm/thread_barrier.h
"
6
#include "
platform/assert.h
"
7
#include "
vm/random.h
"
8
#include "
vm/thread_pool.h
"
9
#include "
vm/unit_test.h
"
10
11
namespace
dart
{
12
13
class
FuzzTask
:
public
ThreadPool::Task
{
14
public
:
15
FuzzTask
(intptr_t num_rounds,
ThreadBarrier
* barrier, uint64_t seed)
16
: num_rounds_(num_rounds), barrier_(barrier), rng_(seed) {}
17
18
virtual
void
Run
() {
19
for
(intptr_t i = 0; i < num_rounds_; ++i) {
20
RandomSleep();
21
barrier_->
Sync
();
22
}
23
barrier_->
Release
();
24
}
25
26
private
:
27
void
RandomSleep() {
28
int64_t ms = rng_.
NextUInt32
() % 4;
29
if
(ms > 0) {
30
OS::Sleep
(ms);
31
}
32
}
33
34
const
intptr_t num_rounds_;
35
ThreadBarrier* barrier_;
36
Random rng_;
37
};
38
39
VM_UNIT_TEST_CASE
(
ThreadBarrier
) {
40
const
intptr_t kNumTasks = 5;
41
const
intptr_t kNumRounds = 500;
42
43
ThreadBarrier
* barrier =
new
ThreadBarrier
(kNumTasks + 1, kNumTasks + 1);
44
for
(intptr_t i = 0; i < kNumTasks; ++i) {
45
Dart::thread_pool
()->
Run
<
FuzzTask
>(kNumRounds, barrier, i + 1);
46
}
47
for
(intptr_t i = 0; i < kNumRounds; ++i) {
48
barrier->
Sync
();
49
}
50
barrier->
Release
();
51
}
52
53
}
// namespace dart
assert.h
dart::Dart::thread_pool
static ThreadPool * thread_pool()
Definition
dart.h:73
dart::FuzzTask
Definition
thread_barrier_test.cc:13
dart::FuzzTask::Run
virtual void Run()
Definition
thread_barrier_test.cc:18
dart::FuzzTask::FuzzTask
FuzzTask(intptr_t num_rounds, ThreadBarrier *barrier, uint64_t seed)
Definition
thread_barrier_test.cc:15
dart::OS::Sleep
static void Sleep(int64_t millis)
dart::Random::NextUInt32
uint32_t NextUInt32()
Definition
random.cc:73
dart::ThreadBarrier
Definition
thread_barrier.h:47
dart::ThreadBarrier::Sync
void Sync()
Definition
thread_barrier.h:66
dart::ThreadBarrier::Release
void Release()
Definition
thread_barrier.h:83
dart::ThreadPool::Task
Definition
thread_pool.h:23
dart::ThreadPool::Run
bool Run(Args &&... args)
Definition
thread_pool.h:45
dart
Definition
dart_vm.cc:33
random.h
thread_barrier.h
thread_pool.h
unit_test.h
VM_UNIT_TEST_CASE
#define VM_UNIT_TEST_CASE(name)
Definition
unit_test.h:33
Generated on Fri Apr 26 2024 06:15:19 for Flutter Engine by
1.9.8