| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #endif | 83 #endif |
| 84 } | 84 } |
| 85 | 85 |
| 86 MessageLoop::~MessageLoop() { | 86 MessageLoop::~MessageLoop() { |
| 87 DCHECK(this == current()); | 87 DCHECK(this == current()); |
| 88 | 88 |
| 89 // Let interested parties have one last shot at accessing this. | 89 // Let interested parties have one last shot at accessing this. |
| 90 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, | 90 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
| 91 WillDestroyCurrentMessageLoop()); | 91 WillDestroyCurrentMessageLoop()); |
| 92 | 92 |
| 93 // OK, now make it so that no one can find us. | |
| 94 lazy_tls_ptr.Pointer()->Set(NULL); | |
| 95 | |
| 96 DCHECK(!state_); | 93 DCHECK(!state_); |
| 97 | 94 |
| 98 // Clean up any unprocessed tasks, but take care: deleting a task could | 95 // Clean up any unprocessed tasks, but take care: deleting a task could |
| 99 // result in the addition of more tasks (e.g., via DeleteSoon). We set a | 96 // result in the addition of more tasks (e.g., via DeleteSoon). We set a |
| 100 // limit on the number of times we will allow a deleted task to generate more | 97 // limit on the number of times we will allow a deleted task to generate more |
| 101 // tasks. Normally, we should only pass through this loop once or twice. If | 98 // tasks. Normally, we should only pass through this loop once or twice. If |
| 102 // we end up hitting the loop limit, then it is probably due to one task that | 99 // we end up hitting the loop limit, then it is probably due to one task that |
| 103 // is being stubborn. Inspect the queues to see who is left. | 100 // is being stubborn. Inspect the queues to see who is left. |
| 104 bool did_work; | 101 bool did_work; |
| 105 for (int i = 0; i < 100; ++i) { | 102 for (int i = 0; i < 100; ++i) { |
| 106 DeletePendingTasks(); | 103 DeletePendingTasks(); |
| 107 ReloadWorkQueue(); | 104 ReloadWorkQueue(); |
| 108 // If we end up with empty queues, then break out of the loop. | 105 // If we end up with empty queues, then break out of the loop. |
| 109 did_work = DeletePendingTasks(); | 106 did_work = DeletePendingTasks(); |
| 110 if (!did_work) | 107 if (!did_work) |
| 111 break; | 108 break; |
| 112 } | 109 } |
| 113 DCHECK(!did_work); | 110 DCHECK(!did_work); |
| 114 | 111 |
| 115 // OK, now make it so that no one can find us. | 112 // OK, now make it so that no one can find us. |
| 116 tls_index_.Set(NULL); | 113 lazy_tls_ptr.Pointer()->Set(NULL); |
| 117 } | 114 } |
| 118 | 115 |
| 119 void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { | 116 void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { |
| 120 DCHECK(this == current()); | 117 DCHECK(this == current()); |
| 121 destruction_observers_.AddObserver(obs); | 118 destruction_observers_.AddObserver(obs); |
| 122 } | 119 } |
| 123 | 120 |
| 124 void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { | 121 void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { |
| 125 DCHECK(this == current()); | 122 DCHECK(this == current()); |
| 126 destruction_observers_.RemoveObserver(obs); | 123 destruction_observers_.RemoveObserver(obs); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 //------------------------------------------------------------------------------ | 555 //------------------------------------------------------------------------------ |
| 559 // MessageLoopForIO | 556 // MessageLoopForIO |
| 560 | 557 |
| 561 #if defined(OS_WIN) | 558 #if defined(OS_WIN) |
| 562 | 559 |
| 563 void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) { | 560 void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) { |
| 564 pump_win()->WatchObject(object, watcher); | 561 pump_win()->WatchObject(object, watcher); |
| 565 } | 562 } |
| 566 | 563 |
| 567 #endif // defined(OS_WIN) | 564 #endif // defined(OS_WIN) |
| OLD | NEW |