5548752100
http://codereview.appspot.com/6195071/ This also adds a cross platform SkThread for testing purposes. git-svn-id: http://skia.googlecode.com/svn/trunk@3921 2bbb7eff-a529-9590-31e7-b0007b416f81
45 lines
996 B
C++
45 lines
996 B
C++
/*
|
|
* Copyright 2012 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "SkTypes.h"
|
|
#include "Test.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
#include "SkThreadUtils.h"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
static void bounce_ref(void* data) {
|
|
SkRefCnt* ref = static_cast<SkRefCnt*>(data);
|
|
for (int i = 0; i < 100000; ++i) {
|
|
ref->ref();
|
|
ref->unref();
|
|
}
|
|
}
|
|
|
|
static void test_refCnt(skiatest::Reporter* reporter) {
|
|
SkRefCnt* ref = new SkRefCnt();
|
|
|
|
SkThread thing1(bounce_ref, ref);
|
|
SkThread thing2(bounce_ref, ref);
|
|
|
|
thing1.setProcessorAffinity(0);
|
|
thing2.setProcessorAffinity(23);
|
|
|
|
SkASSERT(thing1.start());
|
|
SkASSERT(thing2.start());
|
|
|
|
thing1.join();
|
|
thing2.join();
|
|
|
|
REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
|
|
ref->unref();
|
|
}
|
|
|
|
#include "TestClassDef.h"
|
|
DEFINE_TESTCLASS("ref_cnt", RefCntTestClass, test_refCnt)
|