| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SafePoint_h | 5 #ifndef SafePoint_h |
| 6 #define SafePoint_h | 6 #define SafePoint_h |
| 7 | 7 |
| 8 #include "platform/heap/ThreadState.h" | 8 #include "platform/heap/ThreadState.h" |
| 9 #include "wtf/ThreadingPrimitives.h" | 9 #include "wtf/ThreadingPrimitives.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class SafePointScope final { | 13 class SafePointScope final { |
| 14 WTF_MAKE_NONCOPYABLE(SafePointScope); | 14 WTF_MAKE_NONCOPYABLE(SafePointScope); |
| 15 public: | 15 public: |
| 16 explicit SafePointScope(ThreadState::StackState stackState, ThreadState* sta
te = ThreadState::current()) | 16 explicit SafePointScope(BlinkGC::StackState stackState, ThreadState* state =
ThreadState::current()) |
| 17 : m_state(state) | 17 : m_state(state) |
| 18 { | 18 { |
| 19 if (m_state) { | 19 if (m_state) { |
| 20 RELEASE_ASSERT(!m_state->isAtSafePoint()); | 20 RELEASE_ASSERT(!m_state->isAtSafePoint()); |
| 21 m_state->enterSafePoint(stackState, this); | 21 m_state->enterSafePoint(stackState, this); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 ~SafePointScope() | 25 ~SafePointScope() |
| 26 { | 26 { |
| 27 if (m_state) | 27 if (m_state) |
| 28 m_state->leaveSafePoint(); | 28 m_state->leaveSafePoint(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 ThreadState* m_state; | 32 ThreadState* m_state; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for | 35 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for |
| 36 // a mutex lock. It also ensures that the lock is not held while waiting for a G
C | 36 // a mutex lock. It also ensures that the lock is not held while waiting for a G
C |
| 37 // to complete in the leaveSafePoint method, by releasing the lock if the | 37 // to complete in the leaveSafePoint method, by releasing the lock if the |
| 38 // leaveSafePoint method cannot complete without blocking, see | 38 // leaveSafePoint method cannot complete without blocking, see |
| 39 // SafePointBarrier::checkAndPark. | 39 // SafePointBarrier::checkAndPark. |
| 40 class SafePointAwareMutexLocker final { | 40 class SafePointAwareMutexLocker final { |
| 41 WTF_MAKE_NONCOPYABLE(SafePointAwareMutexLocker); | 41 WTF_MAKE_NONCOPYABLE(SafePointAwareMutexLocker); |
| 42 public: | 42 public: |
| 43 explicit SafePointAwareMutexLocker(MutexBase& mutex, ThreadState::StackState
stackState = ThreadState::HeapPointersOnStack) | 43 explicit SafePointAwareMutexLocker(MutexBase& mutex, BlinkGC::StackState sta
ckState = BlinkGC::HeapPointersOnStack) |
| 44 : m_mutex(mutex) | 44 : m_mutex(mutex) |
| 45 , m_locked(false) | 45 , m_locked(false) |
| 46 { | 46 { |
| 47 ThreadState* state = ThreadState::current(); | 47 ThreadState* state = ThreadState::current(); |
| 48 do { | 48 do { |
| 49 bool leaveSafePoint = false; | 49 bool leaveSafePoint = false; |
| 50 // We cannot enter a safepoint if we are currently sweeping. In that | 50 // We cannot enter a safepoint if we are currently sweeping. In that |
| 51 // case we just try to acquire the lock without being at a safepoint
. | 51 // case we just try to acquire the lock without being at a safepoint
. |
| 52 // If another thread tries to do a GC at that time it might time out | 52 // If another thread tries to do a GC at that time it might time out |
| 53 // due to this thread not being at a safepoint and waiting on the lo
ck. | 53 // due to this thread not being at a safepoint and waiting on the lo
ck. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 volatile int m_canResume; | 123 volatile int m_canResume; |
| 124 volatile int m_unparkedThreadCount; | 124 volatile int m_unparkedThreadCount; |
| 125 Mutex m_mutex; | 125 Mutex m_mutex; |
| 126 ThreadCondition m_parked; | 126 ThreadCondition m_parked; |
| 127 ThreadCondition m_resume; | 127 ThreadCondition m_resume; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 } // namespace blink | 130 } // namespace blink |
| 131 | 131 |
| 132 #endif | 132 #endif |
| OLD | NEW |