Flutter Engine
The Flutter Engine
third_party
skia
tests
SkSharedMutexTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2015 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 "
src/base/SkSharedMutex.h
"
9
#include "
src/core/SkTaskGroup.h
"
10
#include "
tests/Test.h
"
11
12
#include <functional>
13
14
DEF_TEST
(SkSharedMutexBasic, r) {
15
SkSharedMutex sm;
16
sm.acquire();
17
sm.assertHeld();
18
sm.release();
19
sm.acquireShared();
20
sm.assertHeldShared();
21
sm.releaseShared();
22
}
23
24
DEF_TEST
(SkSharedMutexMultiThreaded, r) {
25
SkSharedMutex sm;
26
static
const
int
kSharedSize = 10;
27
int
shared[kSharedSize];
28
int
value
= 0;
29
for
(
int
i
= 0;
i
< kSharedSize; ++
i
) {
30
shared[
i
] = 0;
31
}
32
SkTaskGroup
().
batch
(8, [&](
int
threadIndex) {
33
if
(threadIndex % 4 != 0) {
34
for
(
int
c = 0; c < 100000; ++c) {
35
sm.acquireShared();
36
sm.assertHeldShared();
37
int
v = shared[0];
38
for
(
int
i
= 1;
i
< kSharedSize; ++
i
) {
39
REPORTER_ASSERT
(r, v == shared[
i
]);
40
}
41
sm.releaseShared();
42
}
43
}
else
{
44
for
(
int
c = 0; c < 100000; ++c) {
45
sm.acquire();
46
sm.assertHeld();
47
value
+= 1;
48
for
(
int
i
= 0;
i
< kSharedSize; ++
i
) {
49
shared[
i
] =
value
;
50
}
51
sm.release();
52
}
53
}
54
});
55
}
DEF_TEST
DEF_TEST(SkSharedMutexBasic, r)
Definition:
SkSharedMutexTest.cpp:14
SkSharedMutex.h
SkTaskGroup.h
Test.h
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition:
Test.h:286
SkTaskGroup
Definition:
SkTaskGroup.h:20
SkTaskGroup::batch
void batch(int N, std::function< void(int)> fn)
Definition:
SkTaskGroup.cpp:24
i
int i
Definition:
fl_socket_accessible.cc:18
value
uint8_t value
Definition:
fl_standard_message_codec.cc:36
Generated on Sun Jun 23 2024 21:56:48 for Flutter Engine by
1.9.4