| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium 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 // ExecutorsManager implementation. | 5 // ExecutorsManager implementation. |
| 6 | 6 |
| 7 #include "ceee/ie/broker/executors_manager.h" | 7 #include "ceee/ie/broker/executors_manager.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ceee/ie/broker/broker_module_util.h" | 10 #include "ceee/ie/broker/broker_module_util.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 CHandle thread_handle(::OpenThread(SYNCHRONIZE, FALSE, thread_id)); | 80 CHandle thread_handle(::OpenThread(SYNCHRONIZE, FALSE, thread_id)); |
| 81 if (thread_handle == NULL) { | 81 if (thread_handle == NULL) { |
| 82 DCHECK(false) << "Can't Open thread: " << thread_id; | 82 DCHECK(false) << "Can't Open thread: " << thread_id; |
| 83 return E_UNEXPECTED; | 83 return E_UNEXPECTED; |
| 84 } | 84 } |
| 85 ExecutorInfo& new_executor_info = executors_[thread_id]; | 85 ExecutorInfo& new_executor_info = executors_[thread_id]; |
| 86 new_executor_info.executor = executor; | 86 new_executor_info.executor = executor; |
| 87 new_executor_info.thread_handle = thread_handle; | 87 new_executor_info.thread_handle = thread_handle; |
| 88 } // End of lock. | 88 } // End of lock. |
| 89 | 89 |
| 90 if (map_was_empty) { | |
| 91 // We go from empty to not empty, | |
| 92 // so lock the module to make sure we stay alive. | |
| 93 ceee_module_util::LockModule(); | |
| 94 } | |
| 95 return S_OK; | 90 return S_OK; |
| 96 } | 91 } |
| 97 | 92 |
| 98 HRESULT ExecutorsManager::RegisterWindowExecutor(ThreadId thread_id, | 93 HRESULT ExecutorsManager::RegisterWindowExecutor(ThreadId thread_id, |
| 99 IUnknown* executor) { | 94 IUnknown* executor) { |
| 100 // We need to fetch the event handle associated to this thread ID from | 95 // We need to fetch the event handle associated to this thread ID from |
| 101 // our map in a thread safe way... | 96 // our map in a thread safe way... |
| 102 CHandle executor_registration_gate; | 97 CHandle executor_registration_gate; |
| 103 { | 98 { |
| 104 AutoLock lock(lock_); | 99 AutoLock lock(lock_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 { | 135 { |
| 141 AutoLock lock(lock_); | 136 AutoLock lock(lock_); |
| 142 map_was_empty = executors_.empty(); | 137 map_was_empty = executors_.empty(); |
| 143 // We should not get here if we already have an executor for that thread. | 138 // We should not get here if we already have an executor for that thread. |
| 144 DCHECK(executors_.find(thread_id) == executors_.end()); | 139 DCHECK(executors_.find(thread_id) == executors_.end()); |
| 145 ExecutorInfo& new_executor_info = executors_[thread_id]; | 140 ExecutorInfo& new_executor_info = executors_[thread_id]; |
| 146 new_executor_info.executor = executor; | 141 new_executor_info.executor = executor; |
| 147 new_executor_info.thread_handle = thread_handle; | 142 new_executor_info.thread_handle = thread_handle; |
| 148 } // End of lock. | 143 } // End of lock. |
| 149 | 144 |
| 150 if (map_was_empty) { | |
| 151 // We go from empty to not empty, | |
| 152 // so lock the module to make sure we stay alive. | |
| 153 ceee_module_util::LockModule(); | |
| 154 } | |
| 155 | |
| 156 // Update the list of handles that our thread is waiting on. | |
| 157 BOOL success = ::SetEvent(update_threads_list_gate_); | 145 BOOL success = ::SetEvent(update_threads_list_gate_); |
| 158 DCHECK(success); | 146 DCHECK(success); |
| 159 return S_OK; | 147 return S_OK; |
| 160 } | 148 } |
| 161 | 149 |
| 162 HRESULT ExecutorsManager::GetExecutor(ThreadId thread_id, HWND window, | 150 HRESULT ExecutorsManager::GetExecutor(ThreadId thread_id, HWND window, |
| 163 REFIID riid, void** executor) { | 151 REFIID riid, void** executor) { |
| 164 DCHECK(executor != NULL); | 152 DCHECK(executor != NULL); |
| 165 // We may need to wait for either a currently pending | 153 // We may need to wait for either a currently pending |
| 166 // or own newly created registration of a new executor. | 154 // or own newly created registration of a new executor. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 ExecutorsMap::iterator iter = executors_.find(thread_id); | 247 ExecutorsMap::iterator iter = executors_.find(thread_id); |
| 260 if (iter == executors_.end()) { | 248 if (iter == executors_.end()) { |
| 261 return S_FALSE; | 249 return S_FALSE; |
| 262 } | 250 } |
| 263 | 251 |
| 264 dead_executor.Attach(iter->second.executor.Detach()); | 252 dead_executor.Attach(iter->second.executor.Detach()); |
| 265 executors_.erase(iter); | 253 executors_.erase(iter); |
| 266 map_is_empty = executors_.empty(); | 254 map_is_empty = executors_.empty(); |
| 267 } // End of lock. | 255 } // End of lock. |
| 268 | 256 |
| 269 if (map_is_empty) { | |
| 270 // We go from not empty to empty, | |
| 271 // so unlock the module it can leave in peace. | |
| 272 ceee_module_util::UnlockModule(); | |
| 273 } | |
| 274 return S_OK; | 257 return S_OK; |
| 275 } | 258 } |
| 276 | 259 |
| 277 HRESULT ExecutorsManager::Terminate() { | 260 HRESULT ExecutorsManager::Terminate() { |
| 278 if (thread_ != NULL) { | 261 if (thread_ != NULL) { |
| 279 // Ask our thread to quit and wait for it to be done. | 262 // Ask our thread to quit and wait for it to be done. |
| 280 DWORD result = ::SignalObjectAndWait(termination_gate_, thread_, kTimeOut, | 263 DWORD result = ::SignalObjectAndWait(termination_gate_, thread_, kTimeOut, |
| 281 FALSE); | 264 FALSE); |
| 282 DCHECK(result == WAIT_OBJECT_0); | 265 DCHECK(result == WAIT_OBJECT_0); |
| 283 thread_.Close(); | 266 thread_.Close(); |
| 284 } | 267 } |
| 285 if (!executors_.empty()) { | 268 if (!executors_.empty()) { |
| 286 // TODO(mad@chromium.org): Can this happen??? | 269 // TODO(mad@chromium.org): Can this happen??? |
| 287 NOTREACHED(); | 270 NOTREACHED(); |
| 288 ceee_module_util::UnlockModule(); | |
| 289 } | 271 } |
| 290 | 272 |
| 291 executors_.clear(); | 273 executors_.clear(); |
| 292 update_threads_list_gate_.Close(); | 274 update_threads_list_gate_.Close(); |
| 293 termination_gate_.Close(); | 275 termination_gate_.Close(); |
| 294 | 276 |
| 295 return S_OK; | 277 return S_OK; |
| 296 } | 278 } |
| 297 | 279 |
| 298 void ExecutorsManager::SetTabIdForHandle(long tab_id, HWND handle) { | 280 void ExecutorsManager::SetTabIdForHandle(long tab_id, HWND handle) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } else { | 426 } else { |
| 445 DCHECK(result == WAIT_FAILED); | 427 DCHECK(result == WAIT_FAILED); |
| 446 LOG(ERROR) << "ExecutorsManager::ThreadProc " << com::LogWe(); | 428 LOG(ERROR) << "ExecutorsManager::ThreadProc " << com::LogWe(); |
| 447 break; | 429 break; |
| 448 } | 430 } |
| 449 } | 431 } |
| 450 // Merci... Bonsoir... | 432 // Merci... Bonsoir... |
| 451 ::CoUninitialize(); | 433 ::CoUninitialize(); |
| 452 return 1; | 434 return 1; |
| 453 } | 435 } |
| OLD | NEW |