| * Copyright 2013 Google Inc. |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| #include "include/private/base/SkOnce.h" |
| #include "src/core/SkTaskGroup.h" |
| static void add_five(int* x) { |
| DEF_TEST(SkOnce_Singlethreaded, r) { |
| // No matter how many times we do this, x will be 5. |
| REPORTER_ASSERT(r, 5 == x); |
| DEF_TEST(SkOnce_Multithreaded, r) { |
| // Run a bunch of tasks to be the first to add six to x. |
| SkTaskGroup().batch(1021, [&](int) { |
| // Only one should have done the +=. |
| REPORTER_ASSERT(r, 6 == x); |
| static void inc_gX() { gX++; } |
| DEF_TEST(SkOnce_NoArg, r) { |
| REPORTER_ASSERT(r, 1 == gX); |