Flutter Engine
The Flutter Engine
third_party
skia
tests
OnceTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2013 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
include/private/base/SkOnce.h
"
9
#include "
src/core/SkTaskGroup.h
"
10
#include "
tests/Test.h
"
11
12
#include <functional>
13
14
static
void
add_five
(
int
*
x
) {
15
*
x
+= 5;
16
}
17
18
DEF_TEST
(SkOnce_Singlethreaded, r) {
19
int
x
= 0;
20
21
// No matter how many times we do this, x will be 5.
22
SkOnce
once;
23
once(
add_five
, &
x
);
24
once(
add_five
, &
x
);
25
once(
add_five
, &
x
);
26
once(
add_five
, &
x
);
27
once(
add_five
, &
x
);
28
29
REPORTER_ASSERT
(r, 5 ==
x
);
30
}
31
32
DEF_TEST
(SkOnce_Multithreaded, r) {
33
int
x
= 0;
34
35
// Run a bunch of tasks to be the first to add six to x.
36
SkOnce
once;
37
SkTaskGroup
().
batch
(1021, [&](
int
) {
38
once([&] {
x
+= 6; });
39
});
40
41
// Only one should have done the +=.
42
REPORTER_ASSERT
(r, 6 ==
x
);
43
}
44
45
static
int
gX
= 0;
46
static
void
inc_gX
() {
gX
++; }
47
48
DEF_TEST
(SkOnce_NoArg, r) {
49
SkOnce
once;
50
once(
inc_gX
);
51
once(
inc_gX
);
52
once(
inc_gX
);
53
REPORTER_ASSERT
(r, 1 ==
gX
);
54
}
inc_gX
static void inc_gX()
Definition:
OnceTest.cpp:46
DEF_TEST
DEF_TEST(SkOnce_Singlethreaded, r)
Definition:
OnceTest.cpp:18
gX
static int gX
Definition:
OnceTest.cpp:45
add_five
static void add_five(int *x)
Definition:
OnceTest.cpp:14
SkOnce.h
SkTaskGroup.h
Test.h
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition:
Test.h:286
SkOnce
Definition:
SkOnce.h:22
SkTaskGroup
Definition:
SkTaskGroup.h:20
SkTaskGroup::batch
void batch(int N, std::function< void(int)> fn)
Definition:
SkTaskGroup.cpp:24
x
double x
Definition:
mouse-input-test.cc:82
Generated on Sun Jun 23 2024 21:56:40 for Flutter Engine by
1.9.4