OLD | NEW |
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 <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // libevent's event_base_loop(). | 241 // libevent's event_base_loop(). |
242 TEST_F(MessagePumpLibeventTest, QuitWatcher) { | 242 TEST_F(MessagePumpLibeventTest, QuitWatcher) { |
243 // Delete the old MessageLoop so that we can manage our own one here. | 243 // Delete the old MessageLoop so that we can manage our own one here. |
244 ui_loop_.reset(); | 244 ui_loop_.reset(); |
245 | 245 |
246 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. | 246 MessagePumpLibevent* pump = new MessagePumpLibevent; // owned by |loop|. |
247 MessageLoop loop(WrapUnique(pump)); | 247 MessageLoop loop(WrapUnique(pump)); |
248 RunLoop run_loop; | 248 RunLoop run_loop; |
249 MessagePumpLibevent::FileDescriptorWatcher controller; | 249 MessagePumpLibevent::FileDescriptorWatcher controller; |
250 QuitWatcher delegate(&controller, &run_loop); | 250 QuitWatcher delegate(&controller, &run_loop); |
251 WaitableEvent event(false /* manual_reset */, false /* initially_signaled */); | 251 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 252 WaitableEvent::InitialState::NOT_SIGNALED); |
252 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); | 253 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); |
253 | 254 |
254 // Tell the pump to watch the pipe. | 255 // Tell the pump to watch the pipe. |
255 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, | 256 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, |
256 &controller, &delegate); | 257 &controller, &delegate); |
257 | 258 |
258 // Make the IO thread wait for |event| before writing to pipefds[1]. | 259 // Make the IO thread wait for |event| before writing to pipefds[1]. |
259 const char buf = 0; | 260 const char buf = 0; |
260 const WaitableEventWatcher::EventCallback write_fd_task = | 261 const WaitableEventWatcher::EventCallback write_fd_task = |
261 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); | 262 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); |
262 io_loop()->PostTask(FROM_HERE, | 263 io_loop()->PostTask(FROM_HERE, |
263 Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), | 264 Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), |
264 Unretained(watcher.get()), &event, write_fd_task)); | 265 Unretained(watcher.get()), &event, write_fd_task)); |
265 | 266 |
266 // Queue |event| to signal on |loop|. | 267 // Queue |event| to signal on |loop|. |
267 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); | 268 loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); |
268 | 269 |
269 // Now run the MessageLoop. | 270 // Now run the MessageLoop. |
270 run_loop.Run(); | 271 run_loop.Run(); |
271 | 272 |
272 // StartWatching can move |watcher| to IO thread. Release on IO thread. | 273 // StartWatching can move |watcher| to IO thread. Release on IO thread. |
273 io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching, | 274 io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching, |
274 Owned(watcher.release()))); | 275 Owned(watcher.release()))); |
275 } | 276 } |
276 | 277 |
277 } // namespace | 278 } // namespace |
278 | 279 |
279 } // namespace base | 280 } // namespace base |
OLD | NEW |