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

Side by Side Diff: base/message_pump_libevent.cc

Issue 3805: autorelease message pumps (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « base/message_pump_default.cc ('k') | base/message_pump_mac.mm » ('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 <fcntl.h>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_nsautorelease_pool.h"
8 #include "base/time.h" 11 #include "base/time.h"
9 #include "third_party/libevent/event.h" 12 #include "third_party/libevent/event.h"
10 13
11 #include <fcntl.h>
12
13 namespace base { 14 namespace base {
14 15
15 // Return 0 on success 16 // Return 0 on success
16 // Too small a function to bother putting in a library? 17 // Too small a function to bother putting in a library?
17 static int SetNonBlocking(int fd) 18 static int SetNonBlocking(int fd)
18 { 19 {
19 int flags = fcntl(fd, F_GETFL, 0); 20 int flags = fcntl(fd, F_GETFL, 0);
20 if (-1 == flags) 21 if (-1 == flags)
21 flags = 0; 22 flags = 0;
22 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); 23 return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 106 }
106 107
107 // Reentrant! 108 // Reentrant!
108 void MessagePumpLibevent::Run(Delegate* delegate) { 109 void MessagePumpLibevent::Run(Delegate* delegate) {
109 DCHECK(keep_running_) << "Quit must have been called outside of Run!"; 110 DCHECK(keep_running_) << "Quit must have been called outside of Run!";
110 111
111 bool old_in_run = in_run_; 112 bool old_in_run = in_run_;
112 in_run_ = true; 113 in_run_ = true;
113 114
114 for (;;) { 115 for (;;) {
116 ScopedNSAutoreleasePool autorelease_pool;
117
115 bool did_work = delegate->DoWork(); 118 bool did_work = delegate->DoWork();
116 if (!keep_running_) 119 if (!keep_running_)
117 break; 120 break;
118 121
119 did_work |= delegate->DoDelayedWork(&delayed_work_time_); 122 did_work |= delegate->DoDelayedWork(&delayed_work_time_);
120 if (!keep_running_) 123 if (!keep_running_)
121 break; 124 break;
122 125
123 if (did_work) 126 if (did_work)
124 continue; 127 continue;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 173
171 void MessagePumpLibevent::ScheduleDelayedWork(const Time& delayed_work_time) { 174 void MessagePumpLibevent::ScheduleDelayedWork(const Time& delayed_work_time) {
172 // We know that we can't be blocked on Wait right now since this method can 175 // We know that we can't be blocked on Wait right now since this method can
173 // only be called on the same thread as Run, so we only need to update our 176 // only be called on the same thread as Run, so we only need to update our
174 // record of how long to sleep when we do sleep. 177 // record of how long to sleep when we do sleep.
175 delayed_work_time_ = delayed_work_time; 178 delayed_work_time_ = delayed_work_time;
176 } 179 }
177 180
178 } // namespace base 181 } // namespace base
179 182
OLDNEW
« no previous file with comments | « base/message_pump_default.cc ('k') | base/message_pump_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698