diff options
author | bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-16 18:21:56 +0000 |
---|---|---|
committer | bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-16 18:21:56 +0000 |
commit | a02bc1519cf49afa31fb38bed097dd5014880d04 (patch) | |
tree | 64d0638ce6c287317467d07bb5f7aeeb290d7940 /tests | |
parent | b2aacb6dc29f853e3f37fad208ad8fe8c8138a03 (diff) |
WeakRefCnt
http://codereview.appspot.com/5649046/
git-svn-id: http://skia.googlecode.com/svn/trunk@3978 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RefCntTest.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp index e48fd8a292..4d4ae3f54a 100644 --- a/tests/RefCntTest.cpp +++ b/tests/RefCntTest.cpp @@ -10,6 +10,7 @@ #include "SkRefCnt.h" #include "SkThreadUtils.h" +#include "SkWeakRefCnt.h" /////////////////////////////////////////////////////////////////////////////// @@ -40,5 +41,55 @@ static void test_refCnt(skiatest::Reporter* reporter) { ref->unref(); } +static void bounce_weak_ref(void* data) { + SkWeakRefCnt* ref = static_cast<SkWeakRefCnt*>(data); + for (int i = 0; i < 100000; ++i) { + if (ref->try_ref()) { + ref->unref(); + } + } +} + +static void bounce_weak_weak_ref(void* data) { + SkWeakRefCnt* ref = static_cast<SkWeakRefCnt*>(data); + for (int i = 0; i < 100000; ++i) { + ref->weak_ref(); + ref->weak_unref(); + } +} + +static void test_weakRefCnt(skiatest::Reporter* reporter) { + SkWeakRefCnt* ref = new SkWeakRefCnt(); + + SkThread thing1(bounce_ref, ref); + SkThread thing2(bounce_ref, ref); + SkThread thing3(bounce_weak_ref, ref); + SkThread thing4(bounce_weak_weak_ref, ref); + + thing1.setProcessorAffinity(0); + thing2.setProcessorAffinity(23); + thing3.setProcessorAffinity(2); + thing4.setProcessorAffinity(17); + + SkASSERT(thing1.start()); + SkASSERT(thing2.start()); + SkASSERT(thing3.start()); + SkASSERT(thing4.start()); + + thing1.join(); + thing2.join(); + thing3.join(); + thing4.join(); + + REPORTER_ASSERT(reporter, ref->getRefCnt() == 1); + REPORTER_ASSERT(reporter, ref->getWeakCnt() == 1); + ref->unref(); +} + +static void test_refCntTests(skiatest::Reporter* reporter) { + test_refCnt(reporter); + test_weakRefCnt(reporter); +} + #include "TestClassDef.h" -DEFINE_TESTCLASS("ref_cnt", RefCntTestClass, test_refCnt) +DEFINE_TESTCLASS("RefCnt", RefCntTestClass, test_refCntTests) |