| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkRefCnt.h" | 8 #include "SkRefCnt.h" |
| 9 #include "SkThreadUtils.h" | 9 #include "SkThreadUtils.h" |
| 10 #include "SkTypes.h" | 10 #include "SkTypes.h" |
| 11 #include "SkWeakRefCnt.h" | 11 #include "SkWeakRefCnt.h" |
| 12 #include "Test.h" | 12 #include "Test.h" |
| 13 | 13 |
| 14 static void bounce_ref(void* data) { | 14 static void bounce_ref(void* data) { |
| 15 SkRefCnt* ref = static_cast<SkRefCnt*>(data); | 15 SkRefCnt* ref = static_cast<SkRefCnt*>(data); |
| 16 for (int i = 0; i < 100000; ++i) { | 16 for (int i = 0; i < 100000; ++i) { |
| 17 ref->ref(); | 17 ref->ref(); |
| 18 ref->unref(); | 18 ref->unref(); |
| 19 } | 19 } |
| 20 } | 20 } |
| 21 | 21 |
| 22 static void test_refCnt(skiatest::Reporter* reporter) { | 22 static void test_refCnt(skiatest::Reporter* reporter) { |
| 23 SkRefCnt* ref = new SkRefCnt(); | 23 SkRefCnt* ref = new SkRefCnt(); |
| 24 | 24 |
| 25 SkThread thing1(bounce_ref, ref); | 25 SkThread thing1(bounce_ref, ref); |
| 26 SkThread thing2(bounce_ref, ref); | 26 SkThread thing2(bounce_ref, ref); |
| 27 | 27 |
| 28 thing1.setProcessorAffinity(0); | |
| 29 thing2.setProcessorAffinity(23); | |
| 30 | |
| 31 SkASSERT(thing1.start()); | 28 SkASSERT(thing1.start()); |
| 32 SkASSERT(thing2.start()); | 29 SkASSERT(thing2.start()); |
| 33 | 30 |
| 34 thing1.join(); | 31 thing1.join(); |
| 35 thing2.join(); | 32 thing2.join(); |
| 36 | 33 |
| 37 REPORTER_ASSERT(reporter, ref->unique()); | 34 REPORTER_ASSERT(reporter, ref->unique()); |
| 38 ref->unref(); | 35 ref->unref(); |
| 39 } | 36 } |
| 40 | 37 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 } | 53 } |
| 57 | 54 |
| 58 static void test_weakRefCnt(skiatest::Reporter* reporter) { | 55 static void test_weakRefCnt(skiatest::Reporter* reporter) { |
| 59 SkWeakRefCnt* ref = new SkWeakRefCnt(); | 56 SkWeakRefCnt* ref = new SkWeakRefCnt(); |
| 60 | 57 |
| 61 SkThread thing1(bounce_ref, ref); | 58 SkThread thing1(bounce_ref, ref); |
| 62 SkThread thing2(bounce_ref, ref); | 59 SkThread thing2(bounce_ref, ref); |
| 63 SkThread thing3(bounce_weak_ref, ref); | 60 SkThread thing3(bounce_weak_ref, ref); |
| 64 SkThread thing4(bounce_weak_weak_ref, ref); | 61 SkThread thing4(bounce_weak_weak_ref, ref); |
| 65 | 62 |
| 66 thing1.setProcessorAffinity(0); | |
| 67 thing2.setProcessorAffinity(23); | |
| 68 thing3.setProcessorAffinity(2); | |
| 69 thing4.setProcessorAffinity(17); | |
| 70 | |
| 71 SkASSERT(thing1.start()); | 63 SkASSERT(thing1.start()); |
| 72 SkASSERT(thing2.start()); | 64 SkASSERT(thing2.start()); |
| 73 SkASSERT(thing3.start()); | 65 SkASSERT(thing3.start()); |
| 74 SkASSERT(thing4.start()); | 66 SkASSERT(thing4.start()); |
| 75 | 67 |
| 76 thing1.join(); | 68 thing1.join(); |
| 77 thing2.join(); | 69 thing2.join(); |
| 78 thing3.join(); | 70 thing3.join(); |
| 79 thing4.join(); | 71 thing4.join(); |
| 80 | 72 |
| 81 REPORTER_ASSERT(reporter, ref->unique()); | 73 REPORTER_ASSERT(reporter, ref->unique()); |
| 82 REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); | 74 REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); |
| 83 ref->unref(); | 75 ref->unref(); |
| 84 } | 76 } |
| 85 | 77 |
| 86 DEF_TEST(RefCnt, reporter) { | 78 DEF_TEST(RefCnt, reporter) { |
| 87 test_refCnt(reporter); | 79 test_refCnt(reporter); |
| 88 test_weakRefCnt(reporter); | 80 test_weakRefCnt(reporter); |
| 89 } | 81 } |
| OLD | NEW |