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 class InstCounterClass { | |
15 public: | |
16 InstCounterClass() { fCount = gInstCounter++; } | |
17 InstCounterClass(const InstCounterClass& src) { | |
18 fCount = src.fCount; | |
19 gInstCounter += 1; | |
20 } | |
21 virtual ~InstCounterClass() { gInstCounter -= 1; } | |
22 | |
23 static int gInstCounter; | |
24 int fCount; | |
25 }; | |
26 | |
27 int InstCounterClass::gInstCounter; | |
28 | |
29 static void bounce_ref(void* data) { | 14 static void bounce_ref(void* data) { |
30 SkRefCnt* ref = static_cast<SkRefCnt*>(data); | 15 SkRefCnt* ref = static_cast<SkRefCnt*>(data); |
31 for (int i = 0; i < 100000; ++i) { | 16 for (int i = 0; i < 100000; ++i) { |
32 ref->ref(); | 17 ref->ref(); |
33 ref->unref(); | 18 ref->unref(); |
34 } | 19 } |
35 } | 20 } |
36 | 21 |
37 static void test_refCnt(skiatest::Reporter* reporter) { | 22 static void test_refCnt(skiatest::Reporter* reporter) { |
38 SkRefCnt* ref = new SkRefCnt(); | 23 SkRefCnt* ref = new SkRefCnt(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 80 |
96 REPORTER_ASSERT(reporter, ref->unique()); | 81 REPORTER_ASSERT(reporter, ref->unique()); |
97 REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); | 82 REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); |
98 ref->unref(); | 83 ref->unref(); |
99 } | 84 } |
100 | 85 |
101 DEF_TEST(RefCnt, reporter) { | 86 DEF_TEST(RefCnt, reporter) { |
102 test_refCnt(reporter); | 87 test_refCnt(reporter); |
103 test_weakRefCnt(reporter); | 88 test_weakRefCnt(reporter); |
104 } | 89 } |
OLD | NEW |