Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: tests/OnceTest.cpp

Issue 26470005: SkThreadPool: tweak two little things that have been annoying me (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reup Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/utils/SkThreadPool.cpp ('k') | tests/skia_test.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkOnce.h" 8 #include "SkOnce.h"
9 #include "SkRunnable.h"
10 #include "SkThreadPool.h" 9 #include "SkThreadPool.h"
11 #include "Test.h" 10 #include "Test.h"
12 #include "TestClassDef.h" 11 #include "TestClassDef.h"
13 12
14 DEF_SK_ONCE(add_five, int* x) { 13 DEF_SK_ONCE(add_five, int* x) {
15 *x += 5; 14 *x += 5;
16 } 15 }
17 16
18 DEF_TEST(SkOnce_Singlethreaded, r) { 17 DEF_TEST(SkOnce_Singlethreaded, r) {
19 int x = 0; 18 int x = 0;
(...skipping 29 matching lines...) Expand all
49 const int kTasks = 16, kThreads = 4; 48 const int kTasks = 16, kThreads = 4;
50 49
51 // Make a bunch of tasks that will race to be the first to add six to x. 50 // Make a bunch of tasks that will race to be the first to add six to x.
52 Racer racers[kTasks]; 51 Racer racers[kTasks];
53 int x = 0; 52 int x = 0;
54 for (int i = 0; i < kTasks; i++) { 53 for (int i = 0; i < kTasks; i++) {
55 racers[i].ptr = &x; 54 racers[i].ptr = &x;
56 } 55 }
57 56
58 // Let them race. 57 // Let them race.
59 SkAutoTDelete<SkThreadPool> pool(new SkThreadPool(kThreads)); 58 SkThreadPool pool(kThreads);
60 for (int i = 0; i < kTasks; i++) { 59 for (int i = 0; i < kTasks; i++) {
61 pool->add(&racers[i]); 60 pool.add(&racers[i]);
62 } 61 }
63 pool.free(); // Blocks until all threads are done. 62 pool.wait();
64 63
65 // Only one should have done the +=. 64 // Only one should have done the +=.
66 REPORTER_ASSERT(r, 6 == x); 65 REPORTER_ASSERT(r, 6 == x);
67 } 66 }
OLDNEW
« no previous file with comments | « src/utils/SkThreadPool.cpp ('k') | tests/skia_test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698