OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_V8THREADS_H_ | 28 #ifndef V8_V8THREADS_H_ |
29 #define V8_V8THREADS_H_ | 29 #define V8_V8THREADS_H_ |
30 | 30 |
31 namespace v8 { | 31 namespace v8 { |
| 32 |
| 33 struct LockParameters { |
| 34 bool successfully_relaied; |
| 35 }; |
| 36 |
32 namespace internal { | 37 namespace internal { |
33 | 38 |
34 | 39 |
35 class ThreadState { | 40 class ThreadState { |
36 public: | 41 public: |
37 // Iterate over in-use states. | 42 // Iterate over in-use states. |
38 static ThreadState* FirstInUse(); | 43 static ThreadState* FirstInUse(); |
39 // Returns NULL after the last one. | 44 // Returns NULL after the last one. |
40 ThreadState* Next(); | 45 ThreadState* Next(); |
41 | 46 |
(...skipping 29 matching lines...) Expand all Loading... |
71 | 76 |
72 // In the following two lists there is always at least one object on the list. | 77 // In the following two lists there is always at least one object on the list. |
73 // The first object is a flying anchor that is only there to simplify linking | 78 // The first object is a flying anchor that is only there to simplify linking |
74 // and unlinking. | 79 // and unlinking. |
75 // Head of linked list of free states. | 80 // Head of linked list of free states. |
76 static ThreadState* free_anchor_; | 81 static ThreadState* free_anchor_; |
77 // Head of linked list of states in use. | 82 // Head of linked list of states in use. |
78 static ThreadState* in_use_anchor_; | 83 static ThreadState* in_use_anchor_; |
79 }; | 84 }; |
80 | 85 |
| 86 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 87 |
| 88 struct Promises { |
| 89 bool promise_to_process_debug_commands; |
| 90 void Reset() { |
| 91 promise_to_process_debug_commands = false; |
| 92 } |
| 93 }; |
| 94 |
| 95 // This mutex has an additional feature: you may try acquire it if it's free or |
| 96 // ASK someone who owns it right now to do a particular chore for you before |
| 97 // releasing it. The current owner is guaranteed to NOTICE your ask. |
| 98 class MutexWithResponsibilities { |
| 99 public: |
| 100 MutexWithResponsibilities(); |
| 101 ~MutexWithResponsibilities(); |
| 102 void Lock(); |
| 103 bool LockOrAsk(bool Promises::* promise); |
| 104 void Unlock(); |
| 105 |
| 106 private: |
| 107 Mutex* flag_mutex_; |
| 108 Semaphore* sem_; |
| 109 bool locked_; |
| 110 bool has_promises_; |
| 111 Promises promises_; |
| 112 }; |
| 113 #endif |
81 | 114 |
82 class ThreadManager : public AllStatic { | 115 class ThreadManager : public AllStatic { |
83 public: | 116 public: |
84 static void Lock(); | 117 static void Lock(); |
85 static void Unlock(); | 118 static void Unlock(); |
86 | 119 |
| 120 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 121 static bool LockOrAsk(bool Promises::* promise); |
| 122 #endif |
87 static void ArchiveThread(); | 123 static void ArchiveThread(); |
88 static bool RestoreThread(); | 124 static bool RestoreThread(); |
89 static void FreeThreadResources(); | 125 static void FreeThreadResources(); |
90 static bool IsArchived(); | 126 static bool IsArchived(); |
91 | 127 |
92 static void Iterate(ObjectVisitor* v); | 128 static void Iterate(ObjectVisitor* v); |
93 static void MarkCompactPrologue(bool is_compacting); | 129 static void MarkCompactPrologue(bool is_compacting); |
94 static void MarkCompactEpilogue(bool is_compacting); | 130 static void MarkCompactEpilogue(bool is_compacting); |
95 static bool IsLockedByCurrentThread() { return mutex_owner_.IsSelf(); } | 131 static bool IsLockedByCurrentThread() { return mutex_owner_.IsSelf(); } |
96 | 132 |
97 static int CurrentId(); | 133 static int CurrentId(); |
98 static void AssignId(); | 134 static void AssignId(); |
99 static bool HasId(); | 135 static bool HasId(); |
100 | 136 |
101 static void TerminateExecution(int thread_id); | 137 static void TerminateExecution(int thread_id); |
102 | 138 |
103 static const int kInvalidId = -1; | 139 static const int kInvalidId = -1; |
104 private: | 140 private: |
105 static void EagerlyArchiveThread(); | 141 static void EagerlyArchiveThread(); |
106 | 142 |
107 static int last_id_; // V8 threads are identified through an integer. | 143 static int last_id_; // V8 threads are identified through an integer. |
| 144 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 145 static MutexWithResponsibilities* mutex_; |
| 146 #else |
108 static Mutex* mutex_; | 147 static Mutex* mutex_; |
| 148 #endif |
109 static ThreadHandle mutex_owner_; | 149 static ThreadHandle mutex_owner_; |
110 static ThreadHandle lazily_archived_thread_; | 150 static ThreadHandle lazily_archived_thread_; |
111 static ThreadState* lazily_archived_thread_state_; | 151 static ThreadState* lazily_archived_thread_state_; |
112 }; | 152 }; |
113 | 153 |
114 | 154 |
115 // The ContextSwitcher thread is used to schedule regular preemptions to | 155 // The ContextSwitcher thread is used to schedule regular preemptions to |
116 // multiple running V8 threads. Generally it is necessary to call | 156 // multiple running V8 threads. Generally it is necessary to call |
117 // StartPreemption if there is more than one thread running. If not, a single | 157 // StartPreemption if there is more than one thread running. If not, a single |
118 // JavaScript can take full control of V8 and not allow other threads to run. | 158 // JavaScript can take full control of V8 and not allow other threads to run. |
(...skipping 16 matching lines...) Expand all Loading... |
135 | 175 |
136 bool keep_going_; | 176 bool keep_going_; |
137 int sleep_ms_; | 177 int sleep_ms_; |
138 | 178 |
139 static ContextSwitcher* singleton_; | 179 static ContextSwitcher* singleton_; |
140 }; | 180 }; |
141 | 181 |
142 } } // namespace v8::internal | 182 } } // namespace v8::internal |
143 | 183 |
144 #endif // V8_V8THREADS_H_ | 184 #endif // V8_V8THREADS_H_ |
OLD | NEW |