From af89366cb816a159ec6f761ca47e5b52fc0bde7f Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Tue, 3 Oct 2017 11:08:14 -0400 Subject: Make SkString reference counting thread/TSAN safe. BUG=skia:7107 Change-Id: I8ead98f7694faaed8e6f6f29b1fcd88501d36b66 Reviewed-on: https://skia-review.googlesource.com/54400 Reviewed-by: Mike Klein Commit-Queue: Ben Wagner --- tests/StringTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/StringTest.cpp') diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp index 8ae7412187..91ef009edd 100644 --- a/tests/StringTest.cpp +++ b/tests/StringTest.cpp @@ -8,6 +8,7 @@ #include #include #include "SkString.h" +#include "SkThreadUtils.h" #include "Test.h" // Windows vsnprintf doesn't 0-terminate safely), but is so far @@ -287,3 +288,26 @@ DEF_TEST(String_SkStrSplit_All, r) { REPORTER_ASSERT(r, results[2].equals("b")); REPORTER_ASSERT(r, results[3].equals("")); } + +// https://bugs.chromium.org/p/skia/issues/detail?id=7107 +DEF_TEST(String_Threaded, r) { + SkString gString("foo"); + SkThread::entryPointProc readString = [](void* context) -> void { + SkString gStringCopy = *reinterpret_cast(context); + bool equals_string = gStringCopy.equals("test"); + (void)equals_string; + }; + SkThread threads[] = { + {readString, &gString}, + {readString, &gString}, + {readString, &gString}, + {readString, &gString}, + {readString, &gString}, + }; + for (SkThread& thread : threads) { + thread.start(); + } + for (SkThread& thread : threads) { + thread.join(); + } +} -- cgit v1.2.3