| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_pump_default.h" | 12 #include "base/message_pump_default.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/thread_local.h" | 14 #include "base/thread_local.h" |
| 15 | 15 |
| 16 #if defined(OS_MACOSX) | 16 #if defined(OS_MACOSX) |
| 17 #include "base/message_pump_mac.h" | 17 #include "base/message_pump_mac.h" |
| 18 #endif | 18 #endif |
| 19 #if defined(OS_POSIX) | 19 #if defined(OS_POSIX) |
| 20 #include "base/message_pump_libevent.h" | 20 #include "base/message_pump_libevent.h" |
| 21 #endif | 21 #endif |
| 22 #if defined(OS_LINUX) |
| 23 #include "base/message_pump_glib.h" |
| 24 #endif |
| 22 | 25 |
| 23 // A lazily created thread local storage for quick access to a thread's message | 26 // A lazily created thread local storage for quick access to a thread's message |
| 24 // loop, if one exists. This should be safe and free of static constructors. | 27 // loop, if one exists. This should be safe and free of static constructors. |
| 25 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( | 28 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( |
| 26 base::LINKER_INITIALIZED); | 29 base::LINKER_INITIALIZED); |
| 27 | 30 |
| 28 //------------------------------------------------------------------------------ | 31 //------------------------------------------------------------------------------ |
| 29 | 32 |
| 30 // Logical events for Histogram profiling. Run with -message-loop-histogrammer | 33 // Logical events for Histogram profiling. Run with -message-loop-histogrammer |
| 31 // to get an accounting of messages and actions taken on each thread. | 34 // to get an accounting of messages and actions taken on each thread. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // TODO(rvargas): Get rid of the OS guards. | 85 // TODO(rvargas): Get rid of the OS guards. |
| 83 if (type_ == TYPE_DEFAULT) { | 86 if (type_ == TYPE_DEFAULT) { |
| 84 pump_ = new base::MessagePumpDefault(); | 87 pump_ = new base::MessagePumpDefault(); |
| 85 } else if (type_ == TYPE_IO) { | 88 } else if (type_ == TYPE_IO) { |
| 86 pump_ = new base::MessagePumpForIO(); | 89 pump_ = new base::MessagePumpForIO(); |
| 87 } else { | 90 } else { |
| 88 DCHECK(type_ == TYPE_UI); | 91 DCHECK(type_ == TYPE_UI); |
| 89 pump_ = new base::MessagePumpForUI(); | 92 pump_ = new base::MessagePumpForUI(); |
| 90 } | 93 } |
| 91 #elif defined(OS_POSIX) | 94 #elif defined(OS_POSIX) |
| 95 if (type_ == TYPE_UI) { |
| 92 #if defined(OS_MACOSX) | 96 #if defined(OS_MACOSX) |
| 93 if (type_ == TYPE_UI) { | |
| 94 pump_ = base::MessagePumpMac::Create(); | 97 pump_ = base::MessagePumpMac::Create(); |
| 95 } else | 98 #elif defined(OS_LINUX) |
| 96 #endif // OS_MACOSX | 99 pump_ = new base::MessagePumpForUI(); |
| 97 if (type_ == TYPE_IO) { | 100 #endif // OS_LINUX |
| 101 } else if (type_ == TYPE_IO) { |
| 98 pump_ = new base::MessagePumpLibevent(); | 102 pump_ = new base::MessagePumpLibevent(); |
| 99 } else { | 103 } else { |
| 100 pump_ = new base::MessagePumpDefault(); | 104 pump_ = new base::MessagePumpDefault(); |
| 101 } | 105 } |
| 102 #else // OS_POSIX | |
| 103 pump_ = new base::MessagePumpDefault(); | |
| 104 #endif // OS_POSIX | 106 #endif // OS_POSIX |
| 105 } | 107 } |
| 106 | 108 |
| 107 MessageLoop::~MessageLoop() { | 109 MessageLoop::~MessageLoop() { |
| 108 DCHECK(this == current()); | 110 DCHECK(this == current()); |
| 109 | 111 |
| 110 // Let interested parties have one last shot at accessing this. | 112 // Let interested parties have one last shot at accessing this. |
| 111 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, | 113 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
| 112 WillDestroyCurrentMessageLoop()); | 114 WillDestroyCurrentMessageLoop()); |
| 113 | 115 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 588 |
| 587 void MessageLoopForIO::WatchSocket(int socket, short interest_mask, | 589 void MessageLoopForIO::WatchSocket(int socket, short interest_mask, |
| 588 struct event* e, Watcher* watcher) { | 590 struct event* e, Watcher* watcher) { |
| 589 pump_libevent()->WatchSocket(socket, interest_mask, e, watcher); | 591 pump_libevent()->WatchSocket(socket, interest_mask, e, watcher); |
| 590 } | 592 } |
| 591 | 593 |
| 592 void MessageLoopForIO::UnwatchSocket(struct event* e) { | 594 void MessageLoopForIO::UnwatchSocket(struct event* e) { |
| 593 pump_libevent()->UnwatchSocket(e); | 595 pump_libevent()->UnwatchSocket(e); |
| 594 } | 596 } |
| 595 #endif | 597 #endif |
| OLD | NEW |