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) | 16 SafePointScope(ThreadState::StackState stackState, ThreadState* state = Thre
adState::current()) |
17 : m_state(ThreadState::current()) | 17 : m_state(state) |
18 { | 18 { |
19 RELEASE_ASSERT(!m_state->isAtSafePoint()); | 19 RELEASE_ASSERT(!m_state->isAtSafePoint()); |
20 m_state->enterSafePoint(stackState, this); | 20 m_state->enterSafePoint(stackState, this); |
21 } | 21 } |
22 | 22 |
23 ~SafePointScope() | 23 ~SafePointScope() |
24 { | 24 { |
25 if (m_state) | 25 m_state->leaveSafePoint(); |
26 m_state->leaveSafePoint(); | |
27 } | 26 } |
28 | 27 |
29 private: | 28 private: |
30 ThreadState* m_state; | 29 ThreadState* m_state; |
31 }; | 30 }; |
32 | 31 |
33 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for | 32 // The SafePointAwareMutexLocker is used to enter a safepoint while waiting for |
34 // a mutex lock. It also ensures that the lock is not held while waiting for a G
C | 33 // a mutex lock. It also ensures that the lock is not held while waiting for a G
C |
35 // to complete in the leaveSafePoint method, by releasing the lock if the | 34 // to complete in the leaveSafePoint method, by releasing the lock if the |
36 // leaveSafePoint method cannot complete without blocking, see | 35 // leaveSafePoint method cannot complete without blocking, see |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 volatile int m_canResume; | 120 volatile int m_canResume; |
122 volatile int m_unparkedThreadCount; | 121 volatile int m_unparkedThreadCount; |
123 Mutex m_mutex; | 122 Mutex m_mutex; |
124 ThreadCondition m_parked; | 123 ThreadCondition m_parked; |
125 ThreadCondition m_resume; | 124 ThreadCondition m_resume; |
126 }; | 125 }; |
127 | 126 |
128 } // namespace blink | 127 } // namespace blink |
129 | 128 |
130 #endif | 129 #endif |
OLD | NEW |