Changeset 248586 in webkit
- Timestamp:
- Aug 12, 2019 8:01:11 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r248552 r248586 1 2019-08-12 Takashi Komori <Takashi.Komori@sony.com> 2 3 [WTF] Thread::removeFromThreadGroup leaks weak pointers. 4 https://bugs.webkit.org/show_bug.cgi?id=199857 5 6 Reviewed by Yusuke Suzuki. 7 8 Fix leaking of ThreadGroup's weak pointers. 9 10 Tests: WTF.ThreadGroupRemove API tests 11 12 * wtf/Threading.cpp: 13 (WTF::Thread::didExit): 14 (WTF::Thread::addToThreadGroup): 15 (WTF::Thread::removeFromThreadGroup): 16 (WTF::Thread::numberOfThreadGroups): 17 * wtf/Threading.h: 18 1 19 2019-08-12 Sam Weinig <weinig@apple.com> 2 20 -
trunk/Source/WTF/wtf/Threading.cpp
r246490 r248586 212 212 { 213 213 auto locker = holdLock(m_mutex); 214 for (auto& threadGroup : m_threadGroups) {214 for (auto& threadGroupPointerPair : m_threadGroupMap) { 215 215 // If ThreadGroup is just being destroyed, 216 216 // we do not need to perform unregistering. 217 if (auto retained = threadGroup .lock())217 if (auto retained = threadGroupPointerPair.value.lock()) 218 218 threadGroups.append(WTFMove(retained)); 219 219 } … … 241 241 return ThreadGroupAddResult::NotAdded; 242 242 if (threadGroup.m_threads.add(*this).isNewEntry) { 243 m_threadGroup s.append(threadGroup.weakFromThis());243 m_threadGroupMap.add(&threadGroup, threadGroup.weakFromThis()); 244 244 return ThreadGroupAddResult::NewlyAdded; 245 245 } … … 253 253 if (m_isShuttingDown) 254 254 return; 255 m_threadGroups.removeFirstMatching([&] (auto weakPtr) { 256 if (auto sharedPtr = weakPtr.lock()) 257 return sharedPtr.get() == &threadGroup; 258 return false; 259 }); 255 m_threadGroupMap.remove(&threadGroup); 256 } 257 258 unsigned Thread::numberOfThreadGroups() 259 { 260 auto locker = holdLock(m_mutex); 261 return m_threadGroupMap.size(); 260 262 } 261 263 -
trunk/Source/WTF/wtf/Threading.h
r246490 r248586 37 37 #include <wtf/FastTLS.h> 38 38 #include <wtf/Function.h> 39 #include <wtf/HashMap.h> 39 40 #include <wtf/HashSet.h> 40 41 #include <wtf/PlatformRegisters.h> … … 96 97 WTF_EXPORT_PRIVATE static Lock& allThreadsMutex(); 97 98 99 WTF_EXPORT_PRIVATE unsigned numberOfThreadGroups(); 100 98 101 #if OS(WINDOWS) 99 102 // Returns ThreadIdentifier directly. It is useful if the user only cares about identity … … 291 294 WordLock m_mutex; 292 295 StackBounds m_stack { StackBounds::emptyBounds() }; 293 Vector<std::weak_ptr<ThreadGroup>> m_threadGroups;296 HashMap<ThreadGroup*, std::weak_ptr<ThreadGroup>> m_threadGroupMap; 294 297 PlatformThreadHandle m_handle; 295 298 #if OS(WINDOWS) -
trunk/Tools/ChangeLog
r248584 r248586 1 2019-08-12 Takashi Komori <Takashi.Komori@sony.com> 2 3 [WTF] Thread::removeFromThreadGroup leaks weak pointers. 4 https://bugs.webkit.org/show_bug.cgi?id=199857 5 6 Reviewed by Yusuke Suzuki. 7 8 * TestWebKitAPI/Tests/WTF/ThreadGroup.cpp: 9 (TestWebKitAPI::countThreadGroups): 10 (TestWebKitAPI::TEST): 11 1 12 2019-08-12 Alexey Shvayka <shvaikalesh@gmail.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WTF/ThreadGroup.cpp
r229209 r248586 143 143 } 144 144 145 static unsigned countThreadGroups(Vector<Ref<Thread>>& threads) 146 { 147 unsigned count = 0; 148 for (auto& thread : threads) 149 count += thread->numberOfThreadGroups(); 150 151 return count; 152 } 153 154 TEST(WTF, ThreadGroupRemove) 155 { 156 const unsigned NumberOfThreads = 64; 157 158 Lock lock; 159 Condition threadRunningCondition; 160 bool threadRunning = true; 161 162 Vector<Ref<Thread>> threads; 163 164 auto threadGroup = ThreadGroup::create(); 165 for (unsigned i = 0; i < NumberOfThreads; i++) { 166 auto thread = Thread::create("ThreadGroupWorker", [&]() { 167 auto locker = holdLock(lock); 168 threadRunningCondition.wait(lock, [&]() { 169 return !threadRunning; 170 }); 171 }); 172 threadGroup->add(thread.get()); 173 threads.append(WTFMove(thread)); 174 } 175 176 EXPECT_EQ(NumberOfThreads, countThreadGroups(threads)); 177 178 threadGroup = nullptr; 179 180 EXPECT_EQ(0U, countThreadGroups(threads)); 181 182 threadRunning = false; 183 threadRunningCondition.notifyAll(); 184 for (unsigned i = 0; i < NumberOfThreads; i++) 185 threads[i]->waitForCompletion(); 186 } 187 145 188 } // namespace TestWebKitAPI
Note: See TracChangeset
for help on using the changeset viewer.