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

Side by Side Diff: base/message_loop/message_pump_libevent.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_loop/message_pump_libevent.h" 5 #include "base/message_loop/message_pump_libevent.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <memory>
11
10 #include "base/auto_reset.h" 12 #include "base/auto_reset.h"
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
12 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
13 #include "base/logging.h" 15 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h" 16 #include "base/observer_list.h"
16 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
17 #include "base/third_party/libevent/event.h" 18 #include "base/third_party/libevent/event.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 22
22 #if defined(OS_MACOSX) 23 #if defined(OS_MACOSX)
23 #include "base/mac/scoped_nsautorelease_pool.h" 24 #include "base/mac/scoped_nsautorelease_pool.h"
24 #endif 25 #endif
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread()); 147 DCHECK(watch_file_descriptor_caller_checker_.CalledOnValidThread());
147 148
148 int event_mask = persistent ? EV_PERSIST : 0; 149 int event_mask = persistent ? EV_PERSIST : 0;
149 if (mode & WATCH_READ) { 150 if (mode & WATCH_READ) {
150 event_mask |= EV_READ; 151 event_mask |= EV_READ;
151 } 152 }
152 if (mode & WATCH_WRITE) { 153 if (mode & WATCH_WRITE) {
153 event_mask |= EV_WRITE; 154 event_mask |= EV_WRITE;
154 } 155 }
155 156
156 scoped_ptr<event> evt(controller->ReleaseEvent()); 157 std::unique_ptr<event> evt(controller->ReleaseEvent());
157 if (evt.get() == NULL) { 158 if (evt.get() == NULL) {
158 // Ownership is transferred to the controller. 159 // Ownership is transferred to the controller.
159 evt.reset(new event); 160 evt.reset(new event);
160 } else { 161 } else {
161 // Make sure we don't pick up any funky internal libevent masks. 162 // Make sure we don't pick up any funky internal libevent masks.
162 int old_interest_mask = evt.get()->ev_events & 163 int old_interest_mask = evt.get()->ev_events &
163 (EV_READ | EV_WRITE | EV_PERSIST); 164 (EV_READ | EV_WRITE | EV_PERSIST);
164 165
165 // Combine old/new event masks. 166 // Combine old/new event masks.
166 event_mask |= old_interest_mask; 167 event_mask |= old_interest_mask;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 event_base_loopbreak((struct event_base *)context); 213 event_base_loopbreak((struct event_base *)context);
213 } 214 }
214 215
215 // Reentrant! 216 // Reentrant!
216 void MessagePumpLibevent::Run(Delegate* delegate) { 217 void MessagePumpLibevent::Run(Delegate* delegate) {
217 AutoReset<bool> auto_reset_keep_running(&keep_running_, true); 218 AutoReset<bool> auto_reset_keep_running(&keep_running_, true);
218 AutoReset<bool> auto_reset_in_run(&in_run_, true); 219 AutoReset<bool> auto_reset_in_run(&in_run_, true);
219 220
220 // event_base_loopexit() + EVLOOP_ONCE is leaky, see http://crbug.com/25641. 221 // event_base_loopexit() + EVLOOP_ONCE is leaky, see http://crbug.com/25641.
221 // Instead, make our own timer and reuse it on each call to event_base_loop(). 222 // Instead, make our own timer and reuse it on each call to event_base_loop().
222 scoped_ptr<event> timer_event(new event); 223 std::unique_ptr<event> timer_event(new event);
223 224
224 for (;;) { 225 for (;;) {
225 #if defined(OS_MACOSX) 226 #if defined(OS_MACOSX)
226 mac::ScopedNSAutoreleasePool autorelease_pool; 227 mac::ScopedNSAutoreleasePool autorelease_pool;
227 #endif 228 #endif
228 229
229 bool did_work = delegate->DoWork(); 230 bool did_work = delegate->DoWork();
230 if (!keep_running_) 231 if (!keep_running_)
231 break; 232 break;
232 233
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // Remove and discard the wakeup byte. 375 // Remove and discard the wakeup byte.
375 char buf; 376 char buf;
376 int nread = HANDLE_EINTR(read(socket, &buf, 1)); 377 int nread = HANDLE_EINTR(read(socket, &buf, 1));
377 DCHECK_EQ(nread, 1); 378 DCHECK_EQ(nread, 1);
378 that->processed_io_events_ = true; 379 that->processed_io_events_ = true;
379 // Tell libevent to break out of inner loop. 380 // Tell libevent to break out of inner loop.
380 event_base_loopbreak(that->event_base_); 381 event_base_loopbreak(that->event_base_);
381 } 382 }
382 383
383 } // namespace base 384 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_io_ios_unittest.cc ('k') | base/message_loop/message_pump_libevent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698