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_POSIX) |
| 17 #include "base/message_pump_libevent.h" |
| 18 #endif |
| 19 |
16 // A lazily created thread local storage for quick access to a thread's message | 20 // A lazily created thread local storage for quick access to a thread's message |
17 // loop, if one exists. This should be safe and free of static constructors. | 21 // loop, if one exists. This should be safe and free of static constructors. |
18 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( | 22 static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( |
19 base::LINKER_INITIALIZED); | 23 base::LINKER_INITIALIZED); |
20 | 24 |
21 //------------------------------------------------------------------------------ | 25 //------------------------------------------------------------------------------ |
22 | 26 |
23 // Logical events for Histogram profiling. Run with -message-loop-histogrammer | 27 // Logical events for Histogram profiling. Run with -message-loop-histogrammer |
24 // to get an accounting of messages and actions taken on each thread. | 28 // to get an accounting of messages and actions taken on each thread. |
25 static const int kTaskRunEvent = 0x1; | 29 static const int kTaskRunEvent = 0x1; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 DCHECK(!current()) << "should only have one message loop per thread"; | 75 DCHECK(!current()) << "should only have one message loop per thread"; |
72 lazy_tls_ptr.Pointer()->Set(this); | 76 lazy_tls_ptr.Pointer()->Set(this); |
73 | 77 |
74 // TODO(darin): Choose the pump based on the requested type. | 78 // TODO(darin): Choose the pump based on the requested type. |
75 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
76 if (type_ == TYPE_DEFAULT) { | 80 if (type_ == TYPE_DEFAULT) { |
77 pump_ = new base::MessagePumpDefault(); | 81 pump_ = new base::MessagePumpDefault(); |
78 } else { | 82 } else { |
79 pump_ = new base::MessagePumpWin(); | 83 pump_ = new base::MessagePumpWin(); |
80 } | 84 } |
| 85 #elif defined(OS_POSIX) |
| 86 if (type_ == TYPE_IO) { |
| 87 pump_ = new base::MessagePumpLibevent(); |
| 88 } else { |
| 89 pump_ = new base::MessagePumpDefault(); |
| 90 } |
81 #else | 91 #else |
82 pump_ = new base::MessagePumpDefault(); | 92 pump_ = new base::MessagePumpDefault(); |
83 #endif | 93 #endif |
84 } | 94 } |
85 | 95 |
86 MessageLoop::~MessageLoop() { | 96 MessageLoop::~MessageLoop() { |
87 DCHECK(this == current()); | 97 DCHECK(this == current()); |
88 | 98 |
89 // Let interested parties have one last shot at accessing this. | 99 // Let interested parties have one last shot at accessing this. |
90 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, | 100 FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 | 564 |
555 //------------------------------------------------------------------------------ | 565 //------------------------------------------------------------------------------ |
556 // MessageLoopForIO | 566 // MessageLoopForIO |
557 | 567 |
558 #if defined(OS_WIN) | 568 #if defined(OS_WIN) |
559 | 569 |
560 void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) { | 570 void MessageLoopForIO::WatchObject(HANDLE object, Watcher* watcher) { |
561 pump_win()->WatchObject(object, watcher); | 571 pump_win()->WatchObject(object, watcher); |
562 } | 572 } |
563 | 573 |
564 #endif // defined(OS_WIN) | 574 #elif defined(OS_POSIX) |
| 575 |
| 576 void MessageLoopForIO::WatchSocket(int socket, short interest_mask, |
| 577 struct event* e, Watcher* watcher) { |
| 578 pump_libevent()->WatchSocket(socket, interest_mask, e, watcher); |
| 579 } |
| 580 |
| 581 void MessageLoopForIO::UnwatchSocket(struct event* e) { |
| 582 pump_libevent()->UnwatchSocket(e); |
| 583 } |
| 584 #endif |
OLD | NEW |