Chromium Code Reviews| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, | 249 WaitableEvent event(WaitableEvent::ResetPolicy::AUTOMATIC, |
| 250 WaitableEvent::InitialState::NOT_SIGNALED); | 250 WaitableEvent::InitialState::NOT_SIGNALED); |
| 251 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); | 251 std::unique_ptr<WaitableEventWatcher> watcher(new WaitableEventWatcher); |
| 252 | 252 |
| 253 // Tell the pump to watch the pipe. | 253 // Tell the pump to watch the pipe. |
| 254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, | 254 pump->WatchFileDescriptor(pipefds_[0], false, MessagePumpLibevent::WATCH_READ, |
| 255 &controller, &delegate); | 255 &controller, &delegate); |
| 256 | 256 |
| 257 // Make the IO thread wait for |event| before writing to pipefds[1]. | 257 // Make the IO thread wait for |event| before writing to pipefds[1]. |
| 258 const char buf = 0; | 258 const char buf = 0; |
| 259 const WaitableEventWatcher::EventCallback write_fd_task = | 259 WaitableEventWatcher::EventCallback write_fd_task = |
| 260 Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); | 260 BindOnce(&WriteFDWrapper, pipefds_[1], &buf, 1); |
| 261 io_loop()->task_runner()->PostTask( | 261 io_loop()->task_runner()->PostTask( |
| 262 FROM_HERE, BindOnce(IgnoreResult(&WaitableEventWatcher::StartWatching), | 262 FROM_HERE, |
| 263 Unretained(watcher.get()), &event, write_fd_task)); | 263 BindOnce(IgnoreResult(&WaitableEventWatcher::StartWatching), |
| 264 Unretained(watcher.get()), &event, std::move(write_fd_task))); | |
|
dcheng
2017/04/14 21:56:58
Nit: #include <utility>
tzik
2017/04/17 08:28:33
Done.
| |
| 264 | 265 |
| 265 // Queue |event| to signal on |loop|. | 266 // Queue |event| to signal on |loop|. |
| 266 loop.task_runner()->PostTask( | 267 loop.task_runner()->PostTask( |
| 267 FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&event))); | 268 FROM_HERE, BindOnce(&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()->task_runner()->PostTask( | 274 io_loop()->task_runner()->PostTask( |
| 274 FROM_HERE, | 275 FROM_HERE, |
| 275 BindOnce(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); | 276 BindOnce(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); |
| 276 } | 277 } |
| 277 | 278 |
| 278 } // namespace | 279 } // namespace |
| 279 | 280 |
| 280 } // namespace base | 281 } // namespace base |
| OLD | NEW |