Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
OnceTest.cpp File Reference
#include "include/private/base/SkOnce.h"
#include "src/core/SkTaskGroup.h"
#include "tests/Test.h"
#include <functional>

Go to the source code of this file.

Functions

static void add_five (int *x)
 
 DEF_TEST (SkOnce_Singlethreaded, r)
 
 DEF_TEST (SkOnce_Multithreaded, r)
 
static void inc_gX ()
 
 DEF_TEST (SkOnce_NoArg, r)
 

Variables

static int gX = 0
 

Function Documentation

◆ add_five()

static void add_five ( int x)
static

Definition at line 14 of file OnceTest.cpp.

14 {
15 *x += 5;
16}
double x

◆ DEF_TEST() [1/3]

DEF_TEST ( SkOnce_Multithreaded  ,
 
)

Definition at line 32 of file OnceTest.cpp.

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

◆ DEF_TEST() [2/3]

DEF_TEST ( SkOnce_NoArg  ,
 
)

Definition at line 48 of file OnceTest.cpp.

48 {
49 SkOnce once;
50 once(inc_gX);
51 once(inc_gX);
52 once(inc_gX);
53 REPORTER_ASSERT(r, 1 == gX);
54}
static void inc_gX()
Definition OnceTest.cpp:46
static int gX
Definition OnceTest.cpp:45

◆ DEF_TEST() [3/3]

DEF_TEST ( SkOnce_Singlethreaded  ,
 
)

Definition at line 18 of file OnceTest.cpp.

18 {
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}
static void add_five(int *x)
Definition OnceTest.cpp:14

◆ inc_gX()

static void inc_gX ( )
static

Definition at line 46 of file OnceTest.cpp.

46{ gX++; }

Variable Documentation

◆ gX

int gX = 0
static

Definition at line 45 of file OnceTest.cpp.