Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkSharedMutexTest.cpp File Reference
#include "src/base/SkSharedMutex.h"
#include "src/core/SkTaskGroup.h"
#include "tests/Test.h"
#include <functional>

Go to the source code of this file.

Functions

 DEF_TEST (SkSharedMutexBasic, r)
 
 DEF_TEST (SkSharedMutexMultiThreaded, r)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( SkSharedMutexBasic  ,
 
)

Definition at line 14 of file SkSharedMutexTest.cpp.

14 {
15 SkSharedMutex sm;
16 sm.acquire();
17 sm.assertHeld();
18 sm.release();
19 sm.acquireShared();
20 sm.assertHeldShared();
21 sm.releaseShared();
22}

◆ DEF_TEST() [2/2]

DEF_TEST ( SkSharedMutexMultiThreaded  ,
 
)

Definition at line 24 of file SkSharedMutexTest.cpp.

24 {
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}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void batch(int N, std::function< void(int)> fn)
uint8_t value