Changeset 162352 in webkit
- Timestamp:
- Jan 20, 2014 9:10:36 AM (10 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r162284 r162352 1 2014-01-19 Anders Carlsson <andersca@apple.com> 2 3 Convert GCThreadSharedData over to STL threading primitives 4 https://bugs.webkit.org/show_bug.cgi?id=127256 5 6 Reviewed by Andreas Kling. 7 8 * heap/GCThread.cpp: 9 (JSC::GCThread::waitForNextPhase): 10 (JSC::GCThread::gcThreadMain): 11 * heap/GCThreadSharedData.cpp: 12 (JSC::GCThreadSharedData::GCThreadSharedData): 13 (JSC::GCThreadSharedData::~GCThreadSharedData): 14 (JSC::GCThreadSharedData::startNextPhase): 15 (JSC::GCThreadSharedData::endCurrentPhase): 16 (JSC::GCThreadSharedData::didStartMarking): 17 (JSC::GCThreadSharedData::didFinishMarking): 18 * heap/GCThreadSharedData.h: 19 * heap/SlotVisitor.cpp: 20 (JSC::SlotVisitor::donateKnownParallel): 21 (JSC::SlotVisitor::drainFromShared): 22 1 23 2014-01-18 Andreas Kling <akling@apple.com> 2 24 -
trunk/Source/JavaScriptCore/heap/GCThread.cpp
r140594 r162352 70 70 GCPhase GCThread::waitForNextPhase() 71 71 { 72 MutexLocker locker(m_shared.m_phaseLock); 73 while (m_shared.m_gcThreadsShouldWait) 74 m_shared.m_phaseCondition.wait(m_shared.m_phaseLock); 72 std::unique_lock<std::mutex> lock(m_shared.m_phaseMutex); 73 m_shared.m_phaseConditionVariable.wait(lock, [this] { return !m_shared.m_gcThreadsShouldWait; }); 75 74 76 75 m_shared.m_numberOfActiveGCThreads--; 77 76 if (!m_shared.m_numberOfActiveGCThreads) 78 m_shared.m_activityCondition .signal();77 m_shared.m_activityConditionVariable.notify_one(); 79 78 80 while (m_shared.m_currentPhase == NoPhase) 81 m_shared.m_phaseCondition.wait(m_shared.m_phaseLock); 79 m_shared.m_phaseConditionVariable.wait(lock, [this] { return m_shared.m_currentPhase != NoPhase; }); 82 80 m_shared.m_numberOfActiveGCThreads++; 83 81 return m_shared.m_currentPhase; … … 93 91 // creating this thread. We aren't guaranteed to have a valid threadID until the main thread releases this lock. 94 92 { 95 MutexLocker locker(m_shared.m_phaseLock);93 std::lock_guard<std::mutex> lock(m_shared.m_phaseMutex); 96 94 } 97 95 { -
trunk/Source/JavaScriptCore/heap/GCThreadSharedData.cpp
r162017 r162352 84 84 #if ENABLE(PARALLEL_GC) 85 85 // Grab the lock so the new GC threads can be properly initialized before they start running. 86 MutexLocker locker(m_phaseLock);86 std::unique_lock<std::mutex> lock(m_phaseMutex); 87 87 for (unsigned i = 1; i < Options::numberOfGCMarkers(); ++i) { 88 88 m_numberOfActiveGCThreads++; … … 96 96 97 97 // Wait for all the GCThreads to get to the right place. 98 while (m_numberOfActiveGCThreads) 99 m_activityCondition.wait(m_phaseLock); 98 m_activityConditionVariable.wait(lock, [this] { return !m_numberOfActiveGCThreads; }); 100 99 #endif 101 100 } … … 106 105 // Destroy our marking threads. 107 106 { 108 MutexLocker markingLocker(m_markingLock);109 MutexLocker phaseLocker(m_phaseLock);107 std::lock_guard<std::mutex> markingLock(m_markingMutex); 108 std::lock_guard<std::mutex> phaseLock(m_phaseMutex); 110 109 ASSERT(m_currentPhase == NoPhase); 111 110 m_parallelMarkersShouldExit = true; 112 111 m_gcThreadsShouldWait = false; 113 112 m_currentPhase = Exit; 114 m_phaseCondition .broadcast();113 m_phaseConditionVariable.notify_all(); 115 114 } 116 115 for (unsigned i = 0; i < m_gcThreads.size(); ++i) { … … 140 139 void GCThreadSharedData::startNextPhase(GCPhase phase) 141 140 { 142 MutexLocker phaseLocker(m_phaseLock);141 std::lock_guard<std::mutex> lock(m_phaseMutex); 143 142 ASSERT(!m_gcThreadsShouldWait); 144 143 ASSERT(m_currentPhase == NoPhase); 145 144 m_gcThreadsShouldWait = true; 146 145 m_currentPhase = phase; 147 m_phaseCondition .broadcast();146 m_phaseConditionVariable.notify_all(); 148 147 } 149 148 … … 151 150 { 152 151 ASSERT(m_gcThreadsShouldWait); 153 MutexLocker locker(m_phaseLock);152 std::unique_lock<std::mutex> lock(m_phaseMutex); 154 153 m_currentPhase = NoPhase; 155 154 m_gcThreadsShouldWait = false; 156 m_phaseCondition.broadcast(); 157 while (m_numberOfActiveGCThreads) 158 m_activityCondition.wait(m_phaseLock); 155 m_phaseConditionVariable.notify_all(); 156 m_activityConditionVariable.wait(lock, [this] { return !m_numberOfActiveGCThreads; }); 159 157 } 160 158 161 159 void GCThreadSharedData::didStartMarking() 162 160 { 163 MutexLocker markingLocker(m_markingLock);161 std::lock_guard<std::mutex> lock(m_markingMutex); 164 162 m_parallelMarkersShouldExit = false; 165 163 startNextPhase(Mark); … … 169 167 { 170 168 { 171 MutexLocker markingLocker(m_markingLock);169 std::lock_guard<std::mutex> lock(m_markingMutex); 172 170 m_parallelMarkersShouldExit = true; 173 m_markingCondition .broadcast();171 m_markingConditionVariable.notify_all(); 174 172 } 175 173 -
trunk/Source/JavaScriptCore/heap/GCThreadSharedData.h
r155317 r162352 32 32 #include "UnconditionalFinalizer.h" 33 33 #include "WeakReferenceHarvester.h" 34 #include <condition_variable> 34 35 #include <wtf/HashSet.h> 35 36 #include <wtf/TCSpinLock.h> 36 #include <wtf/Threading.h>37 37 #include <wtf/Vector.h> 38 38 … … 87 87 Vector<GCThread*> m_gcThreads; 88 88 89 Mutex m_markingLock;90 ThreadCondition m_markingCondition;89 std::mutex m_markingMutex; 90 std::condition_variable m_markingConditionVariable; 91 91 MarkStackArray m_sharedMarkStack; 92 92 unsigned m_numberOfActiveParallelMarkers; … … 101 101 static const size_t s_blockFragmentLength = 32; 102 102 103 Mutex m_phaseLock;104 ThreadCondition m_phaseCondition;105 ThreadCondition m_activityCondition;103 std::mutex m_phaseMutex; 104 std::condition_variable m_phaseConditionVariable; 105 std::condition_variable m_activityConditionVariable; 106 106 unsigned m_numberOfActiveGCThreads; 107 107 bool m_gcThreadsShouldWait; -
trunk/Source/JavaScriptCore/heap/SlotVisitor.cpp
r161615 r162352 119 119 // If we're contending on the lock, be conservative and assume that another 120 120 // thread is already donating. 121 MutexTryLocker locker(m_shared.m_markingLock);122 if (!lock er.locked())121 std::unique_lock<std::mutex> lock(m_shared.m_markingMutex, std::try_to_lock); 122 if (!lock.owns_lock()) 123 123 return; 124 124 … … 127 127 128 128 if (m_shared.m_numberOfActiveParallelMarkers < Options::numberOfGCMarkers()) 129 m_shared.m_markingCondition .broadcast();129 m_shared.m_markingConditionVariable.notify_all(); 130 130 } 131 131 … … 182 182 #if ENABLE(PARALLEL_GC) 183 183 { 184 MutexLocker locker(m_shared.m_markingLock);184 std::lock_guard<std::mutex> lock(m_shared.m_markingMutex); 185 185 m_shared.m_numberOfActiveParallelMarkers++; 186 186 } 187 187 while (true) { 188 188 { 189 MutexLocker locker(m_shared.m_markingLock);189 std::unique_lock<std::mutex> lock(m_shared.m_markingMutex); 190 190 m_shared.m_numberOfActiveParallelMarkers--; 191 191 … … 198 198 if (!m_shared.m_numberOfActiveParallelMarkers && m_shared.m_sharedMarkStack.isEmpty()) { 199 199 // Let any sleeping slaves know it's time for them to return; 200 m_shared.m_markingCondition .broadcast();200 m_shared.m_markingConditionVariable.notify_all(); 201 201 return; 202 202 } … … 207 207 208 208 // Otherwise wait. 209 m_shared.m_markingCondition .wait(m_shared.m_markingLock);209 m_shared.m_markingConditionVariable.wait(lock); 210 210 } 211 211 } else { … … 214 214 // Did we detect termination? If so, let the master know. 215 215 if (!m_shared.m_numberOfActiveParallelMarkers && m_shared.m_sharedMarkStack.isEmpty()) 216 m_shared.m_markingCondition.broadcast(); 217 218 while (m_shared.m_sharedMarkStack.isEmpty() && !m_shared.m_parallelMarkersShouldExit) 219 m_shared.m_markingCondition.wait(m_shared.m_markingLock); 216 m_shared.m_markingConditionVariable.notify_all(); 217 218 m_shared.m_markingConditionVariable.wait(lock, [this] { return !m_shared.m_sharedMarkStack.isEmpty() || m_shared.m_parallelMarkersShouldExit; }); 220 219 221 220 // Is the current phase done? If so, return from this function.
Note: See TracChangeset
for help on using the changeset viewer.