| 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/eintr_wrappers.h" |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/platform_thread.h" | 13 #include "base/platform_thread.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // We send a byte across a pipe to wakeup the event loop. | 17 // We send a byte across a pipe to wakeup the event loop. |
| 17 const char kWorkScheduled = '\0'; | 18 const char kWorkScheduled = '\0'; |
| 18 | 19 |
| 19 // Return a timeout suitable for the glib loop, -1 to block forever, | 20 // Return a timeout suitable for the glib loop, -1 to block forever, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // longer than the next time we need to run delayed work. | 171 // longer than the next time we need to run delayed work. |
| 171 return GetTimeIntervalMilliseconds(delayed_work_time_); | 172 return GetTimeIntervalMilliseconds(delayed_work_time_); |
| 172 } | 173 } |
| 173 | 174 |
| 174 void MessagePumpForUI::HandleDispatch() { | 175 void MessagePumpForUI::HandleDispatch() { |
| 175 // We should only ever have a single message on the wakeup pipe, since we | 176 // We should only ever have a single message on the wakeup pipe, since we |
| 176 // are only signaled when the queue went from empty to non-empty. The glib | 177 // are only signaled when the queue went from empty to non-empty. The glib |
| 177 // poll will tell us whether there was data, so this read shouldn't block. | 178 // poll will tell us whether there was data, so this read shouldn't block. |
| 178 if (wakeup_gpollfd_.revents & G_IO_IN) { | 179 if (wakeup_gpollfd_.revents & G_IO_IN) { |
| 179 char msg; | 180 char msg; |
| 180 if (read(wakeup_pipe_read_, &msg, 1) != 1 || msg != '!') { | 181 if (HANDLE_EINTR(read(wakeup_pipe_read_, &msg, 1)) != 1 || msg != '!') { |
| 181 NOTREACHED() << "Error reading from the wakeup pipe."; | 182 NOTREACHED() << "Error reading from the wakeup pipe."; |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 185 if (state_->should_quit) | 186 if (state_->should_quit) |
| 186 return; | 187 return; |
| 187 | 188 |
| 188 state_->more_work_is_plausible = false; | 189 state_->more_work_is_plausible = false; |
| 189 | 190 |
| 190 if (state_->delegate->DoWork()) | 191 if (state_->delegate->DoWork()) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 215 } else { | 216 } else { |
| 216 NOTREACHED() << "Quit called outside Run!"; | 217 NOTREACHED() << "Quit called outside Run!"; |
| 217 } | 218 } |
| 218 } | 219 } |
| 219 | 220 |
| 220 void MessagePumpForUI::ScheduleWork() { | 221 void MessagePumpForUI::ScheduleWork() { |
| 221 // This can be called on any thread, so we don't want to touch any state | 222 // This can be called on any thread, so we don't want to touch any state |
| 222 // variables as we would then need locks all over. This ensures that if | 223 // variables as we would then need locks all over. This ensures that if |
| 223 // we are sleeping in a poll that we will wake up. | 224 // we are sleeping in a poll that we will wake up. |
| 224 char msg = '!'; | 225 char msg = '!'; |
| 225 if (write(wakeup_pipe_write_, &msg, 1) != 1) { | 226 if (HANDLE_EINTR(write(wakeup_pipe_write_, &msg, 1)) != 1) { |
| 226 NOTREACHED() << "Could not write to the UI message loop wakeup pipe!"; | 227 NOTREACHED() << "Could not write to the UI message loop wakeup pipe!"; |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 | 230 |
| 230 void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) { | 231 void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) { |
| 231 // We need to wake up the loop in case the poll timeout needs to be | 232 // We need to wake up the loop in case the poll timeout needs to be |
| 232 // adjusted. This will cause us to try to do work, but that's ok. | 233 // adjusted. This will cause us to try to do work, but that's ok. |
| 233 delayed_work_time_ = delayed_work_time; | 234 delayed_work_time_ = delayed_work_time; |
| 234 ScheduleWork(); | 235 ScheduleWork(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 } // namespace base | 238 } // namespace base |
| OLD | NEW |