| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 | 141 |
| 142 // The ContextSwitcher thread is used to schedule regular preemptions to | 142 // The ContextSwitcher thread is used to schedule regular preemptions to |
| 143 // multiple running V8 threads. Generally it is necessary to call | 143 // multiple running V8 threads. Generally it is necessary to call |
| 144 // StartPreemption if there is more than one thread running. If not, a single | 144 // StartPreemption if there is more than one thread running. If not, a single |
| 145 // JavaScript can take full control of V8 and not allow other threads to run. | 145 // JavaScript can take full control of V8 and not allow other threads to run. |
| 146 class ContextSwitcher: public Thread { | 146 class ContextSwitcher: public Thread { |
| 147 public: | 147 public: |
| 148 // Set the preemption interval for the ContextSwitcher thread. | 148 // Set the preemption interval for the ContextSwitcher thread. |
| 149 static void StartPreemption(int every_n_ms); | 149 static void StartPreemption(Isolate* isolate, int every_n_ms); |
| 150 | 150 |
| 151 // Stop sending preemption requests to threads. | 151 // Stop sending preemption requests to threads. |
| 152 static void StopPreemption(); | 152 static void StopPreemption(Isolate* isolate); |
| 153 | 153 |
| 154 // Preempted thread needs to call back to the ContextSwitcher to acknowledge | 154 // Preempted thread needs to call back to the ContextSwitcher to acknowledge |
| 155 // the handling of a preemption request. | 155 // the handling of a preemption request. |
| 156 static void PreemptionReceived(); | 156 static void PreemptionReceived(); |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 ContextSwitcher(Isolate* isolate, int every_n_ms); | 159 ContextSwitcher(Isolate* isolate, int every_n_ms); |
| 160 | 160 |
| 161 Isolate* isolate() const { return isolate_; } | 161 Isolate* isolate() const { return isolate_; } |
| 162 | 162 |
| 163 void Run(); | 163 void Run(); |
| 164 | 164 |
| 165 bool keep_going_; | 165 bool keep_going_; |
| 166 int sleep_ms_; | 166 int sleep_ms_; |
| 167 Isolate* isolate_; | 167 Isolate* isolate_; |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 } } // namespace v8::internal | 170 } } // namespace v8::internal |
| 171 | 171 |
| 172 #endif // V8_V8THREADS_H_ | 172 #endif // V8_V8THREADS_H_ |
| OLD | NEW |