OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <glib.h> | 10 #include <glib.h> |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // we get it, we keep that state here to stay consistent. | 138 // we get it, we keep that state here to stay consistent. |
139 bool has_work; | 139 bool has_work; |
140 }; | 140 }; |
141 | 141 |
142 MessagePumpGlib::MessagePumpGlib() | 142 MessagePumpGlib::MessagePumpGlib() |
143 : state_(NULL), | 143 : state_(NULL), |
144 context_(g_main_context_default()), | 144 context_(g_main_context_default()), |
145 wakeup_gpollfd_(new GPollFD) { | 145 wakeup_gpollfd_(new GPollFD) { |
146 // Create our wakeup pipe, which is used to flag when work was scheduled. | 146 // Create our wakeup pipe, which is used to flag when work was scheduled. |
147 int fds[2]; | 147 int fds[2]; |
148 CHECK_EQ(pipe(fds), 0); | 148 int ret = pipe(fds); |
| 149 DCHECK_EQ(ret, 0); |
| 150 (void)ret; // Prevent warning in release mode. |
| 151 |
149 wakeup_pipe_read_ = fds[0]; | 152 wakeup_pipe_read_ = fds[0]; |
150 wakeup_pipe_write_ = fds[1]; | 153 wakeup_pipe_write_ = fds[1]; |
151 wakeup_gpollfd_->fd = wakeup_pipe_read_; | 154 wakeup_gpollfd_->fd = wakeup_pipe_read_; |
152 wakeup_gpollfd_->events = G_IO_IN; | 155 wakeup_gpollfd_->events = G_IO_IN; |
153 | 156 |
154 work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); | 157 work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); |
155 static_cast<WorkSource*>(work_source_)->pump = this; | 158 static_cast<WorkSource*>(work_source_)->pump = this; |
156 g_source_add_poll(work_source_, wakeup_gpollfd_.get()); | 159 g_source_add_poll(work_source_, wakeup_gpollfd_.get()); |
157 // Use a low priority so that we let other events in the queue go first. | 160 // Use a low priority so that we let other events in the queue go first. |
158 g_source_set_priority(work_source_, G_PRIORITY_DEFAULT_IDLE); | 161 g_source_set_priority(work_source_, G_PRIORITY_DEFAULT_IDLE); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // adjusted. This will cause us to try to do work, but that's ok. | 324 // adjusted. This will cause us to try to do work, but that's ok. |
322 delayed_work_time_ = delayed_work_time; | 325 delayed_work_time_ = delayed_work_time; |
323 ScheduleWork(); | 326 ScheduleWork(); |
324 } | 327 } |
325 | 328 |
326 MessagePumpDispatcher* MessagePumpGlib::GetDispatcher() { | 329 MessagePumpDispatcher* MessagePumpGlib::GetDispatcher() { |
327 return state_ ? state_->dispatcher : NULL; | 330 return state_ ? state_->dispatcher : NULL; |
328 } | 331 } |
329 | 332 |
330 } // namespace base | 333 } // namespace base |
OLD | NEW |