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

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

Issue 1271243003: CrossThreadPersistent invalidation: add missing orphaned check. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add unit test Created 5 years, 4 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
« no previous file with comments | « no previous file | Source/platform/heap/PersistentNode.cpp » ('j') | Source/platform/heap/PersistentNode.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/HeapTest.cpp
diff --git a/Source/platform/heap/HeapTest.cpp b/Source/platform/heap/HeapTest.cpp
index ef5316f86191c7afc2478270eb131b84b6aeee82..6e5d83500c2d7ae9d1d3d0615091b3f64352bf63 100644
--- a/Source/platform/heap/HeapTest.cpp
+++ b/Source/platform/heap/HeapTest.cpp
@@ -5672,6 +5672,54 @@ TEST(HeapTest, RecursiveMutex)
RecursiveLockingTester::test();
}
+class CrossThreadPersistentOnMainThreadTester {
+public:
+ static void test()
+ {
+ MutexLocker locker(mainThreadMutex());
+ OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThread("Test Worker Thread"));
+ workerThread->postTask(FROM_HERE, new Task(threadSafeBind(workerThreadMain)));
+
+ parkMainThread();
+
+ // (Temporarily) detach main thread and wake the worker thread, so that it
+ // can do its detach().
+ ThreadState::detachMainThread();
+ wakeWorkerThread();
+
+ parkMainThread();
+ ThreadState::attachMainThread();
+ }
+
+private:
+
+ static void workerThreadMain()
+ {
+ MutexLocker locker(workerThreadMutex());
+
+ // Start up a worker thread and have it detach after the main thread has.
+ // Do this to verify that CrossThreadPersistent<>s referring to objects
+ // on one of the main thread's heaps does not upset the CTP invalidation
+ // pass that ThreadState::detach() performs.
+ ThreadState::attach();
+
+ CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(43));
+
+ // Wait for the main thread to detach.
+ wakeMainThread();
+ parkWorkerThread();
+
+ ThreadState::detach();
+ wakeMainThread();
+ }
+};
+
+TEST(HeapTest, CrossThreadPersistentOnMainThread)
+{
+ CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(42));
+ CrossThreadPersistentOnMainThreadTester::test();
+}
+
template<typename T>
class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester<T>> {
public:
« no previous file with comments | « no previous file | Source/platform/heap/PersistentNode.cpp » ('j') | Source/platform/heap/PersistentNode.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698