OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_pump_glib.h" | 5 #include "base/message_pump_glib.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <math.h> | 8 #include <math.h> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // descriptor to it. | 60 // descriptor to it. |
61 int pipe_fd[2]; | 61 int pipe_fd[2]; |
62 CHECK(0 == pipe(pipe_fd)) << "Could not create pipe!"; | 62 CHECK(0 == pipe(pipe_fd)) << "Could not create pipe!"; |
63 write_fd_work_scheduled_ = pipe_fd[1]; | 63 write_fd_work_scheduled_ = pipe_fd[1]; |
64 read_fd_work_scheduled_ = pipe_fd[0]; | 64 read_fd_work_scheduled_ = pipe_fd[0]; |
65 int flags = fcntl(read_fd_work_scheduled_, F_GETFL, 0); | 65 int flags = fcntl(read_fd_work_scheduled_, F_GETFL, 0); |
66 if (-1 == flags) | 66 if (-1 == flags) |
67 flags = 0; | 67 flags = 0; |
68 CHECK(0 == fcntl(read_fd_work_scheduled_, F_SETFL, flags | O_NONBLOCK)) << | 68 CHECK(0 == fcntl(read_fd_work_scheduled_, F_SETFL, flags | O_NONBLOCK)) << |
69 "Could not set file descriptor to non-blocking!"; | 69 "Could not set file descriptor to non-blocking!"; |
70 GPollFD poll_fd; | 70 work_source_poll_info_ = new GPollFD; |
71 poll_fd.fd = read_fd_work_scheduled_; | 71 work_source_poll_info_->fd = read_fd_work_scheduled_; |
72 poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; | 72 work_source_poll_info_->events = G_IO_IN | G_IO_HUP | G_IO_ERR; |
73 work_source_ = AddSource(&WorkSourceFuncs, G_PRIORITY_DEFAULT, &poll_fd); | 73 work_source_ = AddSource(&WorkSourceFuncs, G_PRIORITY_DEFAULT, |
| 74 work_source_poll_info_); |
74 } | 75 } |
75 | 76 |
76 MessagePumpForUI::~MessagePumpForUI() { | 77 MessagePumpForUI::~MessagePumpForUI() { |
77 close(read_fd_work_scheduled_); | 78 close(read_fd_work_scheduled_); |
78 close(write_fd_work_scheduled_); | 79 close(write_fd_work_scheduled_); |
79 g_source_destroy(work_source_); | 80 g_source_destroy(work_source_); |
80 g_source_unref(work_source_); | 81 g_source_unref(work_source_); |
| 82 delete work_source_poll_info_; |
81 } | 83 } |
82 | 84 |
83 struct ThreadIdTraits { | 85 struct ThreadIdTraits { |
84 static void New(void* instance) { | 86 static void New(void* instance) { |
85 int* thread_id = static_cast<int*>(instance); | 87 int* thread_id = static_cast<int*>(instance); |
86 *thread_id = PlatformThread::CurrentId(); | 88 *thread_id = PlatformThread::CurrentId(); |
87 } | 89 } |
88 static void Delete(void* instance) { | 90 static void Delete(void* instance) { |
89 } | 91 } |
90 }; | 92 }; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 static_cast<WorkSource*>(source)->self = this; | 297 static_cast<WorkSource*>(source)->self = this; |
296 | 298 |
297 if (optional_poll_fd) | 299 if (optional_poll_fd) |
298 g_source_add_poll(source, optional_poll_fd); | 300 g_source_add_poll(source, optional_poll_fd); |
299 | 301 |
300 g_source_attach(source, context_); | 302 g_source_attach(source, context_); |
301 return source; | 303 return source; |
302 } | 304 } |
303 | 305 |
304 } // namespace base | 306 } // namespace base |
OLD | NEW |