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(BlinkGC::StackState stackState, ThreadState* state =
ThreadState::current()) | 16 explicit SafePointScope(BlinkGC::StackState stackState, ThreadState* state =
ThreadState::current(), bool delayEnter = false) |
17 : m_state(state) | 17 : m_state(state) |
18 { | 18 { |
19 if (m_state) { | 19 if (delayEnter) |
20 RELEASE_ASSERT(!m_state->isAtSafePoint()); | 20 return; |
21 m_state->enterSafePoint(stackState, this); | 21 enter(stackState); |
22 } | |
23 } | 22 } |
24 | 23 |
25 ~SafePointScope() | 24 ~SafePointScope() |
26 { | 25 { |
27 if (m_state) | 26 if (m_state) |
28 m_state->leaveSafePoint(); | 27 m_state->leaveSafePoint(); |
29 } | 28 } |
30 | 29 |
| 30 void enter(BlinkGC::StackState stackState) |
| 31 { |
| 32 if (!m_state) |
| 33 return; |
| 34 |
| 35 RELEASE_ASSERT(!m_state->isAtSafePoint()); |
| 36 m_state->enterSafePoint(stackState, this); |
| 37 } |
| 38 |
31 private: | 39 private: |
32 ThreadState* m_state; | 40 ThreadState* m_state; |
33 }; | 41 }; |
34 | 42 |
35 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for | 43 // 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 | 44 // 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 | 45 // to complete in the leaveSafePoint method, by releasing the lock if the |
38 // leaveSafePoint method cannot complete without blocking, see | 46 // leaveSafePoint method cannot complete without blocking, see |
39 // SafePointBarrier::checkAndPark. | 47 // SafePointBarrier::checkAndPark. |
40 class SafePointAwareMutexLocker final { | 48 class SafePointAwareMutexLocker final { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 volatile int m_canResume; | 131 volatile int m_canResume; |
124 volatile int m_unparkedThreadCount; | 132 volatile int m_unparkedThreadCount; |
125 Mutex m_mutex; | 133 Mutex m_mutex; |
126 ThreadCondition m_parked; | 134 ThreadCondition m_parked; |
127 ThreadCondition m_resume; | 135 ThreadCondition m_resume; |
128 }; | 136 }; |
129 | 137 |
130 } // namespace blink | 138 } // namespace blink |
131 | 139 |
132 #endif | 140 #endif |
OLD | NEW |