Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 5733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5744 } | 5744 } |
| 5745 | 5745 |
| 5746 static volatile IntWrapper* s_workerObjectPointer; | 5746 static volatile IntWrapper* s_workerObjectPointer; |
| 5747 }; | 5747 }; |
| 5748 | 5748 |
| 5749 TEST(HeapTest, RecursiveMutex) | 5749 TEST(HeapTest, RecursiveMutex) |
| 5750 { | 5750 { |
| 5751 RecursiveLockingTester::test(); | 5751 RecursiveLockingTester::test(); |
| 5752 } | 5752 } |
| 5753 | 5753 |
| 5754 class CrossThreadPersistentOnMainThreadTester { | |
|
haraken
2016/03/10 10:45:18
Would it make sense to remove this test?
| |
| 5755 public: | |
| 5756 static void test() | |
| 5757 { | |
| 5758 MutexLocker locker(mainThreadMutex()); | |
| 5759 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread")); | |
| 5760 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi nd(workerThreadMain)); | |
| 5761 | |
| 5762 parkMainThread(); | |
| 5763 | |
| 5764 // (Temporarily) detach main thread and wake the worker thread, so that it | |
| 5765 // can do its detach(). | |
| 5766 ThreadState::detachMainThread(); | |
|
haraken
2016/03/10 10:45:18
It's not allowed to detach the main thread before
| |
| 5767 wakeWorkerThread(); | |
| 5768 | |
| 5769 parkMainThread(); | |
| 5770 ThreadState::attachMainThread(); | |
| 5771 } | |
| 5772 | |
| 5773 private: | |
| 5774 | |
| 5775 static void workerThreadMain() | |
| 5776 { | |
| 5777 MutexLocker locker(workerThreadMutex()); | |
| 5778 | |
| 5779 // Start up a worker thread and have it detach after the main thread has . | |
| 5780 // Do this to verify that CrossThreadPersistent<>s referring to objects | |
|
haraken
2016/03/10 10:45:18
The CrossThreadPersistent is not pointing to an ob
| |
| 5781 // on one of the main thread's arenas does not upset the CTP invalidatio n | |
| 5782 // pass that ThreadState::detach() performs. | |
| 5783 ThreadState::attach(); | |
| 5784 | |
| 5785 CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(43)); | |
| 5786 | |
| 5787 // Wait for the main thread to detach. | |
| 5788 wakeMainThread(); | |
| 5789 parkWorkerThread(); | |
| 5790 | |
| 5791 ThreadState::detach(); | |
| 5792 wakeMainThread(); | |
| 5793 } | |
| 5794 }; | |
| 5795 | |
| 5796 TEST(HeapTest, CrossThreadPersistentOnMainThread) | |
| 5797 { | |
| 5798 CrossThreadPersistent<IntWrapper> persistent(IntWrapper::create(42)); | |
| 5799 CrossThreadPersistentOnMainThreadTester::test(); | |
| 5800 } | |
| 5801 | |
| 5802 template<typename T> | 5754 template<typename T> |
| 5803 class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester <T>> { | 5755 class TraceIfNeededTester : public GarbageCollectedFinalized<TraceIfNeededTester <T>> { |
| 5804 public: | 5756 public: |
| 5805 static TraceIfNeededTester<T>* create() { return new TraceIfNeededTester<T>( ); } | 5757 static TraceIfNeededTester<T>* create() { return new TraceIfNeededTester<T>( ); } |
| 5806 static TraceIfNeededTester<T>* create(const T& obj) { return new TraceIfNeed edTester<T>(obj); } | 5758 static TraceIfNeededTester<T>* create(const T& obj) { return new TraceIfNeed edTester<T>(obj); } |
| 5807 DEFINE_INLINE_TRACE() { TraceIfNeeded<T>::trace(visitor, m_obj); } | 5759 DEFINE_INLINE_TRACE() { TraceIfNeeded<T>::trace(visitor, m_obj); } |
| 5808 T& obj() { return m_obj; } | 5760 T& obj() { return m_obj; } |
| 5809 ~TraceIfNeededTester() { } | 5761 ~TraceIfNeededTester() { } |
| 5810 private: | 5762 private: |
| 5811 TraceIfNeededTester() { } | 5763 TraceIfNeededTester() { } |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6531 EXPECT_EQ(1u, vector2.size()); | 6483 EXPECT_EQ(1u, vector2.size()); |
| 6532 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables | 6484 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables |
| 6533 // Vector<>s with inline capacity, remove. | 6485 // Vector<>s with inline capacity, remove. |
| 6534 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) | 6486 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) |
| 6535 EXPECT_EQ(16u, vector1.capacity()); | 6487 EXPECT_EQ(16u, vector1.capacity()); |
| 6536 EXPECT_EQ(16u, vector2.capacity()); | 6488 EXPECT_EQ(16u, vector2.capacity()); |
| 6537 #endif | 6489 #endif |
| 6538 } | 6490 } |
| 6539 | 6491 |
| 6540 } // namespace blink | 6492 } // namespace blink |
| OLD | NEW |