Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Unified Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 1881933005: Oilpan: Add ThreadState cleanup callbacks for static thread-specific persistent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unit test Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/heap/HeapTest.cpp
diff --git a/third_party/WebKit/Source/platform/heap/HeapTest.cpp b/third_party/WebKit/Source/platform/heap/HeapTest.cpp
index 66e9220f27561f0d36387cb1317592a45d316076..c3e3884f35ca6d57d53a6b204603bb0a65a9dcea 100644
--- a/third_party/WebKit/Source/platform/heap/HeapTest.cpp
+++ b/third_party/WebKit/Source/platform/heap/HeapTest.cpp
@@ -497,6 +497,10 @@ private:
}
};
+// Needed to give this variable a definition (the initializer above is only a
+// declaration), so that subclasses can use it.
+const int ThreadedTesterBase::numberOfThreads;
+
class ThreadedHeapTester : public ThreadedTesterBase {
public:
static void test()
@@ -6483,4 +6487,45 @@ TEST(HeapTest, TestStaticLocals)
EXPECT_EQ(33, heapVectorIntWrapper[0]->value());
}
+namespace {
+
+class ThreadedClearOnShutdownTester : public ThreadedTesterBase {
+public:
+ static void test()
+ {
+ IntWrapper::s_destructorCalls = 0;
+ ThreadedTesterBase::test(new ThreadedClearOnShutdownTester);
+ EXPECT_EQ(numberOfThreads, IntWrapper::s_destructorCalls);
+ }
+
+private:
+ void runThread() override
+ {
+ ThreadState::attach();
+ EXPECT_EQ(42, threadSpecificIntWrapper().value());
+ ThreadState::detach();
+ atomicDecrement(&m_threadsToFinish);
+ }
+
+ static IntWrapper& threadSpecificIntWrapper()
+ {
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ ThreadSpecific<Persistent<IntWrapper>>, intWrapper,
+ new ThreadSpecific<Persistent<IntWrapper>>);
+ Persistent<IntWrapper>& handle = *intWrapper;
+ if (!handle) {
+ handle = new IntWrapper(42);
+ handle.clearOnThreadShutdown();
+ }
+ return *handle;
+ }
+};
+
+} // namespace
+
+TEST(HeapTest, TestClearOnShutdown)
+{
+ ThreadedClearOnShutdownTester::test();
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698