blob: e48fd8a292251814551333cf00a62aaa97ba91ca [file] [log] [blame]
bungeman@google.com55487522012-05-14 14:09:24 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkTypes.h"
9#include "Test.h"
10
11#include "SkRefCnt.h"
12#include "SkThreadUtils.h"
13
14///////////////////////////////////////////////////////////////////////////////
15
16static void bounce_ref(void* data) {
17 SkRefCnt* ref = static_cast<SkRefCnt*>(data);
18 for (int i = 0; i < 100000; ++i) {
19 ref->ref();
20 ref->unref();
21 }
22}
23
24static void test_refCnt(skiatest::Reporter* reporter) {
25 SkRefCnt* ref = new SkRefCnt();
26
27 SkThread thing1(bounce_ref, ref);
28 SkThread thing2(bounce_ref, ref);
29
30 thing1.setProcessorAffinity(0);
31 thing2.setProcessorAffinity(23);
32
33 SkASSERT(thing1.start());
34 SkASSERT(thing2.start());
35
36 thing1.join();
37 thing2.join();
38
39 REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
40 ref->unref();
41}
42
43#include "TestClassDef.h"
44DEFINE_TESTCLASS("ref_cnt", RefCntTestClass, test_refCnt)