Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Side by Side Diff: base/message_pump_libevent.cc

Issue 100225: POSIX: Add a macro for handling EINTR. (Closed)
Patch Set: ... Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/message_pump_glib.cc ('k') | base/process_util_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_libevent.h" 5 #include "base/message_pump_libevent.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 9
10 #include "eintr_wrappers.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/scoped_nsautorelease_pool.h" 12 #include "base/scoped_nsautorelease_pool.h"
12 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "third_party/libevent/event.h" 15 #include "third_party/libevent/event.h"
15 16
16 // Lifecycle of struct event 17 // Lifecycle of struct event
17 // Libevent uses two main data structures: 18 // Libevent uses two main data structures:
18 // struct event_base (of which there is one per message pump), and 19 // struct event_base (of which there is one per message pump), and
19 // struct event (of which there is roughly one per socket). 20 // struct event (of which there is roughly one per socket).
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 81 }
81 82
82 // Called if a byte is received on the wakeup pipe. 83 // Called if a byte is received on the wakeup pipe.
83 void MessagePumpLibevent::OnWakeup(int socket, short flags, void* context) { 84 void MessagePumpLibevent::OnWakeup(int socket, short flags, void* context) {
84 base::MessagePumpLibevent* that = 85 base::MessagePumpLibevent* that =
85 static_cast<base::MessagePumpLibevent*>(context); 86 static_cast<base::MessagePumpLibevent*>(context);
86 DCHECK(that->wakeup_pipe_out_ == socket); 87 DCHECK(that->wakeup_pipe_out_ == socket);
87 88
88 // Remove and discard the wakeup byte. 89 // Remove and discard the wakeup byte.
89 char buf; 90 char buf;
90 int nread = read(socket, &buf, 1); 91 int nread = HANDLE_EINTR(read(socket, &buf, 1));
91 DCHECK_EQ(nread, 1); 92 DCHECK_EQ(nread, 1);
92 // Tell libevent to break out of inner loop. 93 // Tell libevent to break out of inner loop.
93 event_base_loopbreak(that->event_base_); 94 event_base_loopbreak(that->event_base_);
94 } 95 }
95 96
96 MessagePumpLibevent::MessagePumpLibevent() 97 MessagePumpLibevent::MessagePumpLibevent()
97 : keep_running_(true), 98 : keep_running_(true),
98 in_run_(false), 99 in_run_(false),
99 event_base_(event_base_new()), 100 event_base_(event_base_new()),
100 wakeup_pipe_in_(-1), 101 wakeup_pipe_in_(-1),
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void MessagePumpLibevent::Quit() { 266 void MessagePumpLibevent::Quit() {
266 DCHECK(in_run_); 267 DCHECK(in_run_);
267 // Tell both libevent and Run that they should break out of their loops. 268 // Tell both libevent and Run that they should break out of their loops.
268 keep_running_ = false; 269 keep_running_ = false;
269 ScheduleWork(); 270 ScheduleWork();
270 } 271 }
271 272
272 void MessagePumpLibevent::ScheduleWork() { 273 void MessagePumpLibevent::ScheduleWork() {
273 // Tell libevent (in a threadsafe way) that it should break out of its loop. 274 // Tell libevent (in a threadsafe way) that it should break out of its loop.
274 char buf = 0; 275 char buf = 0;
275 int nwrite = write(wakeup_pipe_in_, &buf, 1); 276 int nwrite = HANDLE_EINTR(write(wakeup_pipe_in_, &buf, 1));
276 DCHECK(nwrite == 1 || errno == EAGAIN) 277 DCHECK(nwrite == 1 || errno == EAGAIN)
277 << "[nwrite:" << nwrite << "] [errno:" << errno << "]"; 278 << "[nwrite:" << nwrite << "] [errno:" << errno << "]";
278 } 279 }
279 280
280 void MessagePumpLibevent::ScheduleDelayedWork(const Time& delayed_work_time) { 281 void MessagePumpLibevent::ScheduleDelayedWork(const Time& delayed_work_time) {
281 // We know that we can't be blocked on Wait right now since this method can 282 // We know that we can't be blocked on Wait right now since this method can
282 // only be called on the same thread as Run, so we only need to update our 283 // only be called on the same thread as Run, so we only need to update our
283 // record of how long to sleep when we do sleep. 284 // record of how long to sleep when we do sleep.
284 delayed_work_time_ = delayed_work_time; 285 delayed_work_time_ = delayed_work_time;
285 } 286 }
286 287
287 } // namespace base 288 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_glib.cc ('k') | base/process_util_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698