Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: src/d8.h

Issue 1226143003: d8: Fix some TSAN bugs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: can't use DCHECK for join_called_, unused in NDEBUG builds Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 V8_D8_H_ 5 #ifndef V8_D8_H_
6 #define V8_D8_H_ 6 #define V8_D8_H_
7 7
8 #ifndef V8_SHARED 8 #ifndef V8_SHARED
9 #include "src/allocation.h" 9 #include "src/allocation.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 i::List<SerializationData*> data_; 232 i::List<SerializationData*> data_;
233 }; 233 };
234 234
235 235
236 class Worker { 236 class Worker {
237 public: 237 public:
238 Worker(); 238 Worker();
239 ~Worker(); 239 ~Worker();
240 240
241 void StartExecuteInThread(Isolate* isolate, const char* script); 241 void StartExecuteInThread(Isolate* isolate, const char* script);
242 // Post a message to the worker's incoming message queue. The worker will
243 // take ownership of the SerializationData.
242 void PostMessage(SerializationData* data); 244 void PostMessage(SerializationData* data);
245 // Synchronously retrieve messages from the worker's outgoing message queue.
246 // If there is no message in the queue, block until a message is available.
247 // If there are no messages in the queue and the worker is no longer running,
248 // return nullptr.
243 SerializationData* GetMessage(); 249 SerializationData* GetMessage();
250 // Terminate the worker's event loop. Messages from the worker that have been
251 // queued can still be read via GetMessage().
244 void Terminate(); 252 void Terminate();
253 // Terminate and join the thread.
254 void WaitForThread();
245 255
246 private: 256 private:
247 class WorkerThread : public base::Thread { 257 class WorkerThread : public base::Thread {
248 public: 258 public:
249 explicit WorkerThread(Worker* worker) 259 explicit WorkerThread(Worker* worker)
250 : base::Thread(base::Thread::Options("WorkerThread")), 260 : base::Thread(base::Thread::Options("WorkerThread")),
251 worker_(worker) {} 261 worker_(worker) {}
252 262
253 virtual void Run() { worker_->ExecuteInThread(); } 263 virtual void Run() { worker_->ExecuteInThread(); }
254 264
255 private: 265 private:
256 Worker* worker_; 266 Worker* worker_;
257 }; 267 };
258 268
259 enum State { IDLE, RUNNING, TERMINATED }; 269 enum State {
270 IDLE, // The worker thread hasn't been started yet
271 RUNNING, // The worker thread is running and hasn't been terminated
272 TERMINATED // The worker thread has been terminated and will soon finish
273 };
260 274
261 void ExecuteInThread(); 275 void ExecuteInThread();
262 void Cleanup(); 276 void Cleanup();
263 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args); 277 static void PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args);
264 278
265 base::Semaphore in_semaphore_; 279 base::Semaphore in_semaphore_;
266 base::Semaphore out_semaphore_; 280 base::Semaphore out_semaphore_;
267 SerializationDataQueue in_queue_; 281 SerializationDataQueue in_queue_;
268 SerializationDataQueue out_queue_; 282 SerializationDataQueue out_queue_;
269 base::Thread* thread_; 283 base::Thread* thread_;
270 char* script_; 284 char* script_;
271 base::Atomic32 state_; 285 base::Atomic32 state_;
286 base::Atomic32 join_called_;
272 }; 287 };
273 #endif // !V8_SHARED 288 #endif // !V8_SHARED
274 289
275 290
276 class ShellOptions { 291 class ShellOptions {
277 public: 292 public:
278 ShellOptions() 293 ShellOptions()
279 : script_executed(false), 294 : script_executed(false),
280 last_run(true), 295 last_run(true),
281 send_idle_notification(false), 296 send_idle_notification(false),
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 static void RunShell(Isolate* isolate); 492 static void RunShell(Isolate* isolate);
478 static bool SetOptions(int argc, char* argv[]); 493 static bool SetOptions(int argc, char* argv[]);
479 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); 494 static Handle<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
480 }; 495 };
481 496
482 497
483 } // namespace v8 498 } // namespace v8
484 499
485 500
486 #endif // V8_D8_H_ 501 #endif // V8_D8_H_
OLDNEW
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698