OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_pump_libevent.h" | 5 #include "base/message_loop/message_pump_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 25 matching lines...) Expand all Loading... |
36 // | 36 // |
37 // TODO(dkegel): | 37 // TODO(dkegel): |
38 // At the moment bad things happen if a FileDescriptorWatcher | 38 // At the moment bad things happen if a FileDescriptorWatcher |
39 // is active after its MessagePumpLibevent has been destroyed. | 39 // is active after its MessagePumpLibevent has been destroyed. |
40 // See MessageLoopTest.FileDescriptorWatcherOutlivesMessageLoop | 40 // See MessageLoopTest.FileDescriptorWatcherOutlivesMessageLoop |
41 // Not clear yet whether that situation occurs in practice, | 41 // Not clear yet whether that situation occurs in practice, |
42 // but if it does, we need to fix it. | 42 // but if it does, we need to fix it. |
43 | 43 |
44 namespace base { | 44 namespace base { |
45 | 45 |
46 MessagePumpLibevent::FileDescriptorWatcher::FileDescriptorWatcher() | 46 MessagePumpLibevent::FileDescriptorWatcher::FileDescriptorWatcher( |
| 47 const tracked_objects::Location& from_here) |
47 : event_(NULL), | 48 : event_(NULL), |
48 pump_(NULL), | 49 pump_(NULL), |
49 watcher_(NULL), | 50 watcher_(NULL), |
50 was_destroyed_(NULL) { | 51 was_destroyed_(NULL), |
51 } | 52 created_from_location_(from_here) {} |
52 | 53 |
53 MessagePumpLibevent::FileDescriptorWatcher::~FileDescriptorWatcher() { | 54 MessagePumpLibevent::FileDescriptorWatcher::~FileDescriptorWatcher() { |
54 if (event_) { | 55 if (event_) { |
55 StopWatchingFileDescriptor(); | 56 StopWatchingFileDescriptor(); |
56 } | 57 } |
57 if (was_destroyed_) { | 58 if (was_destroyed_) { |
58 DCHECK(!*was_destroyed_); | 59 DCHECK(!*was_destroyed_); |
59 *was_destroyed_ = true; | 60 *was_destroyed_ = true; |
60 } | 61 } |
61 } | 62 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 return true; | 309 return true; |
309 } | 310 } |
310 | 311 |
311 // static | 312 // static |
312 void MessagePumpLibevent::OnLibeventNotification(int fd, | 313 void MessagePumpLibevent::OnLibeventNotification(int fd, |
313 short flags, | 314 short flags, |
314 void* context) { | 315 void* context) { |
315 FileDescriptorWatcher* controller = | 316 FileDescriptorWatcher* controller = |
316 static_cast<FileDescriptorWatcher*>(context); | 317 static_cast<FileDescriptorWatcher*>(context); |
317 DCHECK(controller); | 318 DCHECK(controller); |
318 TRACE_EVENT1("toplevel", "MessagePumpLibevent::OnLibeventNotification", | 319 TRACE_EVENT2("toplevel", "MessagePumpLibevent::OnLibeventNotification", |
319 "fd", fd); | 320 "src_file", controller->created_from_location().file_name(), |
| 321 "src_func", controller->created_from_location().function_name()); |
| 322 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION heap_profiler_scope( |
| 323 controller->created_from_location().file_name()); |
320 | 324 |
321 MessagePumpLibevent* pump = controller->pump(); | 325 MessagePumpLibevent* pump = controller->pump(); |
322 pump->processed_io_events_ = true; | 326 pump->processed_io_events_ = true; |
323 | 327 |
324 if ((flags & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) { | 328 if ((flags & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) { |
325 // Both callbacks will be called. It is necessary to check that |controller| | 329 // Both callbacks will be called. It is necessary to check that |controller| |
326 // is not destroyed. | 330 // is not destroyed. |
327 bool controller_was_destroyed = false; | 331 bool controller_was_destroyed = false; |
328 controller->was_destroyed_ = &controller_was_destroyed; | 332 controller->was_destroyed_ = &controller_was_destroyed; |
329 controller->OnFileCanWriteWithoutBlocking(fd, pump); | 333 controller->OnFileCanWriteWithoutBlocking(fd, pump); |
(...skipping 17 matching lines...) Expand all Loading... |
347 // Remove and discard the wakeup byte. | 351 // Remove and discard the wakeup byte. |
348 char buf; | 352 char buf; |
349 int nread = HANDLE_EINTR(read(socket, &buf, 1)); | 353 int nread = HANDLE_EINTR(read(socket, &buf, 1)); |
350 DCHECK_EQ(nread, 1); | 354 DCHECK_EQ(nread, 1); |
351 that->processed_io_events_ = true; | 355 that->processed_io_events_ = true; |
352 // Tell libevent to break out of inner loop. | 356 // Tell libevent to break out of inner loop. |
353 event_base_loopbreak(that->event_base_); | 357 event_base_loopbreak(that->event_base_); |
354 } | 358 } |
355 | 359 |
356 } // namespace base | 360 } // namespace base |
OLD | NEW |