2012-05-21 15:27:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-04-08 13:58:51 +00:00
|
|
|
#include "SkAtomics.h"
|
2012-05-21 15:27:23 +00:00
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkTLS.h"
|
|
|
|
#include "SkThreadUtils.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2012-05-21 15:27:23 +00:00
|
|
|
|
|
|
|
static void thread_main(void*) {
|
|
|
|
SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
|
|
|
|
|
|
|
|
const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
size_t len = strlen(text);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
|
|
|
for (int i = 9; i <= 48; ++i) {
|
|
|
|
paint.setTextSize(SkIntToScalar(i));
|
|
|
|
paint.setAntiAlias(false);
|
|
|
|
paint.measureText(text, len);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.measureText(text, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:12:40 +00:00
|
|
|
static void test_threads(SkThread::entryPointProc proc) {
|
2012-05-21 15:27:23 +00:00
|
|
|
SkThread* threads[8];
|
|
|
|
int N = SK_ARRAY_COUNT(threads);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < N; ++i) {
|
2012-10-25 19:12:40 +00:00
|
|
|
threads[i] = new SkThread(proc);
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-21 15:27:23 +00:00
|
|
|
for (i = 0; i < N; ++i) {
|
|
|
|
threads[i]->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < N; ++i) {
|
|
|
|
threads[i]->join();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < N; ++i) {
|
|
|
|
delete threads[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:12:40 +00:00
|
|
|
static int32_t gCounter;
|
|
|
|
|
|
|
|
static void* FakeCreateTLS() {
|
|
|
|
sk_atomic_inc(&gCounter);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-10-25 19:12:40 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 19:17:41 +00:00
|
|
|
static void FakeDeleteTLS(void*) {
|
2012-10-25 19:12:40 +00:00
|
|
|
sk_atomic_dec(&gCounter);
|
|
|
|
}
|
|
|
|
|
2013-02-27 19:17:41 +00:00
|
|
|
static void testTLSDestructor(void*) {
|
2012-10-25 19:12:40 +00:00
|
|
|
SkTLS::Get(FakeCreateTLS, FakeDeleteTLS);
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(TLS, reporter) {
|
2012-10-25 19:12:40 +00:00
|
|
|
// TODO: Disabled for now to work around
|
|
|
|
// http://code.google.com/p/skia/issues/detail?id=619
|
|
|
|
// ('flaky segfault in TLS test on Shuttle_Ubuntu12 buildbots')
|
2013-01-07 16:47:43 +00:00
|
|
|
if( false ) test_threads(&thread_main);
|
2012-10-25 19:12:40 +00:00
|
|
|
|
|
|
|
// Test to ensure that at thread destruction, TLS destructors
|
|
|
|
// have been called.
|
|
|
|
test_threads(&testTLSDestructor);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == gCounter);
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|