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

Side by Side Diff: src/debug.cc

Issue 21087012: Simplify implementation of Mutex. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix unit test. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/debug.h ('k') | src/debug-agent.h » ('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 // 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 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 event_listener_(Handle<Object>()), 2598 event_listener_(Handle<Object>()),
2599 event_listener_data_(Handle<Object>()), 2599 event_listener_data_(Handle<Object>()),
2600 compiling_natives_(false), 2600 compiling_natives_(false),
2601 is_loading_debugger_(false), 2601 is_loading_debugger_(false),
2602 live_edit_enabled_(true), 2602 live_edit_enabled_(true),
2603 never_unload_debugger_(false), 2603 never_unload_debugger_(false),
2604 force_debugger_active_(false), 2604 force_debugger_active_(false),
2605 message_handler_(NULL), 2605 message_handler_(NULL),
2606 debugger_unload_pending_(false), 2606 debugger_unload_pending_(false),
2607 host_dispatch_handler_(NULL), 2607 host_dispatch_handler_(NULL),
2608 dispatch_handler_access_(OS::CreateMutex()),
2609 debug_message_dispatch_handler_(NULL), 2608 debug_message_dispatch_handler_(NULL),
2610 message_dispatch_helper_thread_(NULL), 2609 message_dispatch_helper_thread_(NULL),
2611 host_dispatch_micros_(100 * 1000), 2610 host_dispatch_micros_(100 * 1000),
2612 agent_(NULL), 2611 agent_(NULL),
2613 command_queue_(isolate->logger(), kQueueInitialSize), 2612 command_queue_(isolate->logger(), kQueueInitialSize),
2614 command_received_(OS::CreateSemaphore(0)), 2613 command_received_(OS::CreateSemaphore(0)),
2615 event_command_queue_(isolate->logger(), kQueueInitialSize), 2614 event_command_queue_(isolate->logger(), kQueueInitialSize),
2616 isolate_(isolate) { 2615 isolate_(isolate) {
2617 } 2616 }
2618 2617
2619 2618
2620 Debugger::~Debugger() { 2619 Debugger::~Debugger() {
2621 delete dispatch_handler_access_;
2622 dispatch_handler_access_ = 0;
2623 delete command_received_; 2620 delete command_received_;
2624 command_received_ = 0; 2621 command_received_ = 0;
2625 } 2622 }
2626 2623
2627 2624
2628 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, 2625 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name,
2629 int argc, 2626 int argc,
2630 Handle<Object> argv[], 2627 Handle<Object> argv[],
2631 bool* caught_exception) { 2628 bool* caught_exception) {
2632 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); 2629 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 3292
3296 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, 3293 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
3297 int period) { 3294 int period) {
3298 host_dispatch_handler_ = handler; 3295 host_dispatch_handler_ = handler;
3299 host_dispatch_micros_ = period * 1000; 3296 host_dispatch_micros_ = period * 1000;
3300 } 3297 }
3301 3298
3302 3299
3303 void Debugger::SetDebugMessageDispatchHandler( 3300 void Debugger::SetDebugMessageDispatchHandler(
3304 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { 3301 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) {
3305 ScopedLock with(dispatch_handler_access_); 3302 ScopedLock with(&dispatch_handler_access_);
3306 debug_message_dispatch_handler_ = handler; 3303 debug_message_dispatch_handler_ = handler;
3307 3304
3308 if (provide_locker && message_dispatch_helper_thread_ == NULL) { 3305 if (provide_locker && message_dispatch_helper_thread_ == NULL) {
3309 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); 3306 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_);
3310 message_dispatch_helper_thread_->Start(); 3307 message_dispatch_helper_thread_->Start();
3311 } 3308 }
3312 } 3309 }
3313 3310
3314 3311
3315 // Calls the registered debug message handler. This callback is part of the 3312 // Calls the registered debug message handler. This callback is part of the
(...skipping 22 matching lines...) Expand all
3338 command_queue_.Put(message); 3335 command_queue_.Put(message);
3339 command_received_->Signal(); 3336 command_received_->Signal();
3340 3337
3341 // Set the debug command break flag to have the command processed. 3338 // Set the debug command break flag to have the command processed.
3342 if (!isolate_->debug()->InDebugger()) { 3339 if (!isolate_->debug()->InDebugger()) {
3343 isolate_->stack_guard()->DebugCommand(); 3340 isolate_->stack_guard()->DebugCommand();
3344 } 3341 }
3345 3342
3346 MessageDispatchHelperThread* dispatch_thread; 3343 MessageDispatchHelperThread* dispatch_thread;
3347 { 3344 {
3348 ScopedLock with(dispatch_handler_access_); 3345 ScopedLock with(&dispatch_handler_access_);
3349 dispatch_thread = message_dispatch_helper_thread_; 3346 dispatch_thread = message_dispatch_helper_thread_;
3350 } 3347 }
3351 3348
3352 if (dispatch_thread == NULL) { 3349 if (dispatch_thread == NULL) {
3353 CallMessageDispatchHandler(); 3350 CallMessageDispatchHandler();
3354 } else { 3351 } else {
3355 dispatch_thread->Schedule(); 3352 dispatch_thread->Schedule();
3356 } 3353 }
3357 } 3354 }
3358 3355
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3458 void Debugger::WaitForAgent() { 3455 void Debugger::WaitForAgent() {
3459 ASSERT(Isolate::Current() == isolate_); 3456 ASSERT(Isolate::Current() == isolate_);
3460 if (agent_ != NULL) 3457 if (agent_ != NULL)
3461 agent_->WaitUntilListening(); 3458 agent_->WaitUntilListening();
3462 } 3459 }
3463 3460
3464 3461
3465 void Debugger::CallMessageDispatchHandler() { 3462 void Debugger::CallMessageDispatchHandler() {
3466 v8::Debug::DebugMessageDispatchHandler handler; 3463 v8::Debug::DebugMessageDispatchHandler handler;
3467 { 3464 {
3468 ScopedLock with(dispatch_handler_access_); 3465 ScopedLock with(&dispatch_handler_access_);
3469 handler = Debugger::debug_message_dispatch_handler_; 3466 handler = Debugger::debug_message_dispatch_handler_;
3470 } 3467 }
3471 if (handler != NULL) { 3468 if (handler != NULL) {
3472 handler(); 3469 handler();
3473 } 3470 }
3474 } 3471 }
3475 3472
3476 3473
3477 EnterDebugger::EnterDebugger() 3474 EnterDebugger::EnterDebugger()
3478 : isolate_(Isolate::Current()), 3475 : isolate_(Isolate::Current()),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
3779 CommandMessage* array_to_free = messages_; 3776 CommandMessage* array_to_free = messages_;
3780 *this = new_queue; 3777 *this = new_queue;
3781 new_queue.messages_ = array_to_free; 3778 new_queue.messages_ = array_to_free;
3782 // Make the new_queue empty so that it doesn't call Dispose on any messages. 3779 // Make the new_queue empty so that it doesn't call Dispose on any messages.
3783 new_queue.start_ = new_queue.end_; 3780 new_queue.start_ = new_queue.end_;
3784 // Automatic destructor called on new_queue, freeing array_to_free. 3781 // Automatic destructor called on new_queue, freeing array_to_free.
3785 } 3782 }
3786 3783
3787 3784
3788 LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size) 3785 LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size)
3789 : logger_(logger), queue_(size) { 3786 : logger_(logger), queue_(size) {}
3790 lock_ = OS::CreateMutex();
3791 }
3792 3787
3793 3788
3794 LockingCommandMessageQueue::~LockingCommandMessageQueue() { 3789 LockingCommandMessageQueue::~LockingCommandMessageQueue() {}
3795 delete lock_;
3796 }
3797 3790
3798 3791
3799 bool LockingCommandMessageQueue::IsEmpty() const { 3792 bool LockingCommandMessageQueue::IsEmpty() {
3800 ScopedLock sl(lock_); 3793 ScopedLock sl(&lock_);
3801 return queue_.IsEmpty(); 3794 return queue_.IsEmpty();
3802 } 3795 }
3803 3796
3804 3797
3805 CommandMessage LockingCommandMessageQueue::Get() { 3798 CommandMessage LockingCommandMessageQueue::Get() {
3806 ScopedLock sl(lock_); 3799 ScopedLock sl(&lock_);
3807 CommandMessage result = queue_.Get(); 3800 CommandMessage result = queue_.Get();
3808 logger_->DebugEvent("Get", result.text()); 3801 logger_->DebugEvent("Get", result.text());
3809 return result; 3802 return result;
3810 } 3803 }
3811 3804
3812 3805
3813 void LockingCommandMessageQueue::Put(const CommandMessage& message) { 3806 void LockingCommandMessageQueue::Put(const CommandMessage& message) {
3814 ScopedLock sl(lock_); 3807 ScopedLock sl(&lock_);
3815 queue_.Put(message); 3808 queue_.Put(message);
3816 logger_->DebugEvent("Put", message.text()); 3809 logger_->DebugEvent("Put", message.text());
3817 } 3810 }
3818 3811
3819 3812
3820 void LockingCommandMessageQueue::Clear() { 3813 void LockingCommandMessageQueue::Clear() {
3821 ScopedLock sl(lock_); 3814 ScopedLock sl(&lock_);
3822 queue_.Clear(); 3815 queue_.Clear();
3823 } 3816 }
3824 3817
3825 3818
3826 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) 3819 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate)
3827 : Thread("v8:MsgDispHelpr"), 3820 : Thread("v8:MsgDispHelpr"),
3828 isolate_(isolate), sem_(OS::CreateSemaphore(0)), 3821 isolate_(isolate), sem_(OS::CreateSemaphore(0)),
3829 mutex_(OS::CreateMutex()), already_signalled_(false) { 3822 already_signalled_(false) {}
3830 }
3831 3823
3832 3824
3833 MessageDispatchHelperThread::~MessageDispatchHelperThread() { 3825 MessageDispatchHelperThread::~MessageDispatchHelperThread() {
3834 delete mutex_;
3835 delete sem_; 3826 delete sem_;
3836 } 3827 }
3837 3828
3838 3829
3839 void MessageDispatchHelperThread::Schedule() { 3830 void MessageDispatchHelperThread::Schedule() {
3840 { 3831 {
3841 ScopedLock lock(mutex_); 3832 ScopedLock lock(&mutex_);
3842 if (already_signalled_) { 3833 if (already_signalled_) {
3843 return; 3834 return;
3844 } 3835 }
3845 already_signalled_ = true; 3836 already_signalled_ = true;
3846 } 3837 }
3847 sem_->Signal(); 3838 sem_->Signal();
3848 } 3839 }
3849 3840
3850 3841
3851 void MessageDispatchHelperThread::Run() { 3842 void MessageDispatchHelperThread::Run() {
3852 while (true) { 3843 while (true) {
3853 sem_->Wait(); 3844 sem_->Wait();
3854 { 3845 {
3855 ScopedLock lock(mutex_); 3846 ScopedLock lock(&mutex_);
3856 already_signalled_ = false; 3847 already_signalled_ = false;
3857 } 3848 }
3858 { 3849 {
3859 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); 3850 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_));
3860 isolate_->debugger()->CallMessageDispatchHandler(); 3851 isolate_->debugger()->CallMessageDispatchHandler();
3861 } 3852 }
3862 } 3853 }
3863 } 3854 }
3864 3855
3865 #endif // ENABLE_DEBUGGER_SUPPORT 3856 #endif // ENABLE_DEBUGGER_SUPPORT
3866 3857
3867 } } // namespace v8::internal 3858 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.h ('k') | src/debug-agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698