| 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) |
| 17 #include "base/message_pump_mac.h" |
| 18 #endif |
| 16 #if defined(OS_POSIX) | 19 #if defined(OS_POSIX) |
| 17 #include "base/message_pump_libevent.h" | 20 #include "base/message_pump_libevent.h" |
| 18 #endif | 21 #endif |
| 19 | 22 |
| 20 // A lazily created thread local storage for quick access to a thread's message | 23 // A lazily created thread local storage for quick access to a thread's message |
| 21 // loop, if one exists. This should be safe and free of static constructors. | 24 // loop, if one exists. This should be safe and free of static constructors. |
| 22 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( | 25 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( |
| 23 base::LINKER_INITIALIZED); | 26 base::LINKER_INITIALIZED); |
| 24 | 27 |
| 25 //------------------------------------------------------------------------------ | 28 //------------------------------------------------------------------------------ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 lazy_tls_ptr.Pointer()->Set(this); | 79 lazy_tls_ptr.Pointer()->Set(this); |
| 77 | 80 |
| 78 // TODO(darin): Choose the pump based on the requested type. | 81 // TODO(darin): Choose the pump based on the requested type. |
| 79 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
| 80 if (type_ == TYPE_DEFAULT) { | 83 if (type_ == TYPE_DEFAULT) { |
| 81 pump_ = new base::MessagePumpDefault(); | 84 pump_ = new base::MessagePumpDefault(); |
| 82 } else { | 85 } else { |
| 83 pump_ = new base::MessagePumpWin(); | 86 pump_ = new base::MessagePumpWin(); |
| 84 } | 87 } |
| 85 #elif defined(OS_POSIX) | 88 #elif defined(OS_POSIX) |
| 89 #if defined(OS_MACOSX) |
| 90 if (type_ == TYPE_UI) { |
| 91 pump_ = base::MessagePumpMac::Create(); |
| 92 } else |
| 93 #endif // OS_MACOSX |
| 86 if (type_ == TYPE_IO) { | 94 if (type_ == TYPE_IO) { |
| 87 pump_ = new base::MessagePumpLibevent(); | 95 pump_ = new base::MessagePumpLibevent(); |
| 88 } else { | 96 } else { |
| 89 pump_ = new base::MessagePumpDefault(); | 97 pump_ = new base::MessagePumpDefault(); |
| 90 } | 98 } |
| 91 #else | 99 #else // OS_POSIX |
| 92 pump_ = new base::MessagePumpDefault(); | 100 pump_ = new base::MessagePumpDefault(); |
| 93 #endif | 101 #endif // OS_POSIX |
| 94 } | 102 } |
| 95 | 103 |
| 96 MessageLoop::~MessageLoop() { | 104 MessageLoop::~MessageLoop() { |
| 97 DCHECK(this == current()); | 105 DCHECK(this == current()); |
| 98 | 106 |
| 99 // Let interested parties have one last shot at accessing this. | 107 // Let interested parties have one last shot at accessing this. |
| 100 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, | 108 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
| 101 WillDestroyCurrentMessageLoop()); | 109 WillDestroyCurrentMessageLoop()); |
| 102 | 110 |
| 103 DCHECK(!state_); | 111 DCHECK(!state_); |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 583 |
| 576 void MessageLoopForIO::WatchSocket(int socket, short interest_mask, | 584 void MessageLoopForIO::WatchSocket(int socket, short interest_mask, |
| 577 struct event* e, Watcher* watcher) { | 585 struct event* e, Watcher* watcher) { |
| 578 pump_libevent()->WatchSocket(socket, interest_mask, e, watcher); | 586 pump_libevent()->WatchSocket(socket, interest_mask, e, watcher); |
| 579 } | 587 } |
| 580 | 588 |
| 581 void MessageLoopForIO::UnwatchSocket(struct event* e) { | 589 void MessageLoopForIO::UnwatchSocket(struct event* e) { |
| 582 pump_libevent()->UnwatchSocket(e); | 590 pump_libevent()->UnwatchSocket(e); |
| 583 } | 591 } |
| 584 #endif | 592 #endif |
| OLD | NEW |