Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 if (data.is_null()) { | 1730 if (data.is_null()) { |
| 1731 data = Factory::undefined_value(); | 1731 data = Factory::undefined_value(); |
| 1732 } | 1732 } |
| 1733 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); | 1733 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 UpdateActiveDebugger(); | 1736 UpdateActiveDebugger(); |
| 1737 } | 1737 } |
| 1738 | 1738 |
| 1739 | 1739 |
| 1740 void Debugger::TearDown() { | |
| 1741 if (message_thread_ != NULL) | |
| 1742 message_thread_->Stop(); | |
|
Søren Thygesen Gjesse
2009/03/26 10:50:09
Please add { }'s
Why don't you have to delete mes
Christian Plesner Hansen
2009/03/27 00:24:26
Done.
Technically it's not a leak as long as ther
| |
| 1743 } | |
| 1744 | |
| 1745 | |
| 1740 void Debugger::SetMessageHandler(v8::DebugMessageHandler handler, void* data) { | 1746 void Debugger::SetMessageHandler(v8::DebugMessageHandler handler, void* data) { |
| 1741 message_handler_ = handler; | 1747 message_handler_ = handler; |
| 1742 message_handler_data_ = data; | 1748 message_handler_data_ = data; |
| 1743 if (!message_thread_) { | 1749 if (!message_thread_) { |
| 1744 message_thread_ = new DebugMessageThread(); | 1750 message_thread_ = new DebugMessageThread(); |
| 1745 message_thread_->Start(); | 1751 message_thread_->Start(); |
| 1746 } | 1752 } |
| 1747 UpdateActiveDebugger(); | 1753 UpdateActiveDebugger(); |
| 1748 } | 1754 } |
| 1749 | 1755 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1845 agent_->Join(); | 1851 agent_->Join(); |
| 1846 delete agent_; | 1852 delete agent_; |
| 1847 agent_ = NULL; | 1853 agent_ = NULL; |
| 1848 } | 1854 } |
| 1849 } | 1855 } |
| 1850 | 1856 |
| 1851 | 1857 |
| 1852 DebugMessageThread::DebugMessageThread() | 1858 DebugMessageThread::DebugMessageThread() |
| 1853 : host_running_(true), | 1859 : host_running_(true), |
| 1854 command_queue_(kQueueInitialSize), | 1860 command_queue_(kQueueInitialSize), |
| 1855 message_queue_(kQueueInitialSize) { | 1861 message_queue_(kQueueInitialSize), |
| 1862 keep_running_(true) { | |
| 1856 command_received_ = OS::CreateSemaphore(0); | 1863 command_received_ = OS::CreateSemaphore(0); |
| 1857 message_received_ = OS::CreateSemaphore(0); | 1864 message_received_ = OS::CreateSemaphore(0); |
| 1858 } | 1865 } |
| 1859 | 1866 |
| 1860 // Does not free resources held by DebugMessageThread | 1867 // Should only be done after the thread is done running. |
| 1861 // because this cannot be done thread-safely. | |
| 1862 DebugMessageThread::~DebugMessageThread() { | 1868 DebugMessageThread::~DebugMessageThread() { |
| 1869 delete command_received_; | |
| 1870 delete message_received_; | |
| 1863 } | 1871 } |
| 1864 | 1872 |
| 1873 void DebugMessageThread::Stop() { | |
| 1874 keep_running_ = false; | |
| 1875 SendMessage(Vector<uint16_t>(NULL, 0)); | |
| 1876 Join(); | |
| 1877 } | |
| 1865 | 1878 |
| 1866 // Puts an event coming from V8 on the queue. Creates | 1879 // Puts an event coming from V8 on the queue. Creates |
| 1867 // a copy of the JSON formatted event string managed by the V8. | 1880 // a copy of the JSON formatted event string managed by the V8. |
| 1868 // Called by the V8 thread. | 1881 // Called by the V8 thread. |
| 1869 // The new copy of the event string is destroyed in Run(). | 1882 // The new copy of the event string is destroyed in Run(). |
| 1870 void DebugMessageThread::SendMessage(Vector<uint16_t> message) { | 1883 void DebugMessageThread::SendMessage(Vector<uint16_t> message) { |
| 1871 Vector<uint16_t> message_copy = message.Clone(); | 1884 Vector<uint16_t> message_copy = message.Clone(); |
| 1872 Logger::DebugTag("Put message on event message_queue."); | 1885 Logger::DebugTag("Put message on event message_queue."); |
| 1873 message_queue_.Put(message_copy); | 1886 message_queue_.Put(message_copy); |
| 1874 message_received_->Signal(); | 1887 message_received_->Signal(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1902 } else { | 1915 } else { |
| 1903 PrintLn(try_catch.Exception()); | 1916 PrintLn(try_catch.Exception()); |
| 1904 return false; | 1917 return false; |
| 1905 } | 1918 } |
| 1906 return true; | 1919 return true; |
| 1907 } | 1920 } |
| 1908 | 1921 |
| 1909 | 1922 |
| 1910 void DebugMessageThread::Run() { | 1923 void DebugMessageThread::Run() { |
| 1911 // Sends debug events to an installed debugger message callback. | 1924 // Sends debug events to an installed debugger message callback. |
| 1912 while (true) { | 1925 while (keep_running_) { |
| 1913 // Wait and Get are paired so that semaphore count equals queue length. | 1926 // Wait and Get are paired so that semaphore count equals queue length. |
| 1914 message_received_->Wait(); | 1927 message_received_->Wait(); |
| 1915 Logger::DebugTag("Get message from event message_queue."); | 1928 Logger::DebugTag("Get message from event message_queue."); |
| 1916 Vector<uint16_t> message = message_queue_.Get(); | 1929 Vector<uint16_t> message = message_queue_.Get(); |
| 1917 if (message.length() > 0) { | 1930 if (message.length() > 0) { |
| 1918 Debugger::SendMessage(message); | 1931 Debugger::SendMessage(message); |
| 1919 } | 1932 } |
| 1920 } | 1933 } |
| 1921 } | 1934 } |
| 1922 | 1935 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2181 } | 2194 } |
| 2182 | 2195 |
| 2183 | 2196 |
| 2184 void LockingMessageQueue::Clear() { | 2197 void LockingMessageQueue::Clear() { |
| 2185 ScopedLock sl(lock_); | 2198 ScopedLock sl(lock_); |
| 2186 queue_.Clear(); | 2199 queue_.Clear(); |
| 2187 } | 2200 } |
| 2188 | 2201 |
| 2189 | 2202 |
| 2190 } } // namespace v8::internal | 2203 } } // namespace v8::internal |
| OLD | NEW |