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

Side by Side Diff: tests/SkSharedMutexTest.cpp

Issue 1285973003: Add asserts for shared mutex. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add SkDebug guards Created 5 years, 4 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
« no previous file with comments | « src/core/SkSharedMutex.cpp ('k') | no next file » | 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 2015 Google Inc. 2 * Copyright 2015 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 "SkSharedMutex.h" 8 #include "SkSharedMutex.h"
9 #include "SkTaskGroup.h" 9 #include "SkTaskGroup.h"
10 10
11 #include "Test.h" 11 #include "Test.h"
12 12
13 DEF_TEST(SkSharedMutexBasic, r) { 13 DEF_TEST(SkSharedMutexBasic, r) {
14 SkSharedMutex sm; 14 SkSharedMutex sm;
15 sm.acquire(); 15 sm.acquire();
16 sm.assertHeld();
16 sm.release(); 17 sm.release();
17 sm.acquireShared(); 18 sm.acquireShared();
19 sm.assertHeldShared();
18 sm.releaseShared(); 20 sm.releaseShared();
19 } 21 }
20 22
21 DEF_TEST(SkSharedMutexMultiThreaded, r) { 23 DEF_TEST(SkSharedMutexMultiThreaded, r) {
22 SkSharedMutex sm; 24 SkSharedMutex sm;
23 static const int kSharedSize = 10; 25 static const int kSharedSize = 10;
24 int shared[kSharedSize]; 26 int shared[kSharedSize];
25 int value = 0; 27 int value = 0;
26 for (int i = 0; i < kSharedSize; ++i) { 28 for (int i = 0; i < kSharedSize; ++i) {
27 shared[i] = 0; 29 shared[i] = 0;
28 } 30 }
29 sk_parallel_for(8, [&](int threadIndex) { 31 sk_parallel_for(8, [&](int threadIndex) {
30 if (threadIndex % 4 != 0) { 32 if (threadIndex % 4 != 0) {
31 for (int c = 0; c < 100000; ++c) { 33 for (int c = 0; c < 100000; ++c) {
32 sm.acquireShared(); 34 sm.acquireShared();
35 sm.assertHeldShared();
33 int v = shared[0]; 36 int v = shared[0];
34 for (int i = 1; i < kSharedSize; ++i) { 37 for (int i = 1; i < kSharedSize; ++i) {
35 REPORTER_ASSERT(r, v == shared[i]); 38 REPORTER_ASSERT(r, v == shared[i]);
36 } 39 }
37 sm.releaseShared(); 40 sm.releaseShared();
38 } 41 }
39 } else { 42 } else {
40 for (int c = 0; c < 100000; ++c) { 43 for (int c = 0; c < 100000; ++c) {
41 sm.acquire(); 44 sm.acquire();
45 sm.assertHeld();
42 value += 1; 46 value += 1;
43 for (int i = 0; i < kSharedSize; ++i) { 47 for (int i = 0; i < kSharedSize; ++i) {
44 shared[i] = value; 48 shared[i] = value;
45 } 49 }
46 sm.release(); 50 sm.release();
47 } 51 }
48 } 52 }
49 }); 53 });
50 } 54 }
OLDNEW
« no previous file with comments | « src/core/SkSharedMutex.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698