| 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_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <math.h> | 8 #include <math.h> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 s.run_depth = state_ ? state_->run_depth + 1 : 1; | 46 s.run_depth = state_ ? state_->run_depth + 1 : 1; |
| 47 | 47 |
| 48 RunState* previous_state = state_; | 48 RunState* previous_state = state_; |
| 49 state_ = &s; | 49 state_ = &s; |
| 50 | 50 |
| 51 DoRunLoop(); | 51 DoRunLoop(); |
| 52 | 52 |
| 53 state_ = previous_state; | 53 state_ = previous_state; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void MessagePumpWin::Run(Delegate* delegate) { |
| 57 RunWithDispatcher(delegate, NULL); |
| 58 } |
| 59 |
| 56 void MessagePumpWin::Quit() { | 60 void MessagePumpWin::Quit() { |
| 57 DCHECK(state_); | 61 DCHECK(state_); |
| 58 state_->should_quit = true; | 62 state_->should_quit = true; |
| 59 } | 63 } |
| 60 | 64 |
| 61 //----------------------------------------------------------------------------- | 65 //----------------------------------------------------------------------------- |
| 62 // MessagePumpWin protected: | 66 // MessagePumpWin protected: |
| 63 | 67 |
| 64 int MessagePumpWin::GetCurrentDelay() const { | 68 int MessagePumpWin::GetCurrentDelay() const { |
| 65 if (delayed_work_time_.is_null()) | 69 if (delayed_work_time_.is_null()) |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 469 } |
| 466 | 470 |
| 467 //----------------------------------------------------------------------------- | 471 //----------------------------------------------------------------------------- |
| 468 // MessagePumpForIO public: | 472 // MessagePumpForIO public: |
| 469 | 473 |
| 470 MessagePumpForIO::MessagePumpForIO() { | 474 MessagePumpForIO::MessagePumpForIO() { |
| 471 port_.Set(CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1)); | 475 port_.Set(CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1)); |
| 472 DCHECK(port_.IsValid()); | 476 DCHECK(port_.IsValid()); |
| 473 } | 477 } |
| 474 | 478 |
| 479 MessagePumpForIO::~MessagePumpForIO() { |
| 480 } |
| 481 |
| 475 void MessagePumpForIO::ScheduleWork() { | 482 void MessagePumpForIO::ScheduleWork() { |
| 476 if (InterlockedExchange(&have_work_, 1)) | 483 if (InterlockedExchange(&have_work_, 1)) |
| 477 return; // Someone else continued the pumping. | 484 return; // Someone else continued the pumping. |
| 478 | 485 |
| 479 // Make sure the MessagePump does some work for us. | 486 // Make sure the MessagePump does some work for us. |
| 480 BOOL ret = PostQueuedCompletionStatus(port_.Get(), 0, | 487 BOOL ret = PostQueuedCompletionStatus(port_.Get(), 0, |
| 481 reinterpret_cast<ULONG_PTR>(this), | 488 reinterpret_cast<ULONG_PTR>(this), |
| 482 reinterpret_cast<OVERLAPPED*>(this)); | 489 reinterpret_cast<OVERLAPPED*>(this)); |
| 483 if (ret) | 490 if (ret) |
| 484 return; // Post worked perfectly. | 491 return; // Post worked perfectly. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 690 |
| 684 // static | 691 // static |
| 685 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 692 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
| 686 ULONG_PTR key, | 693 ULONG_PTR key, |
| 687 bool* has_valid_io_context) { | 694 bool* has_valid_io_context) { |
| 688 *has_valid_io_context = ((key & 1) == 0); | 695 *has_valid_io_context = ((key & 1) == 0); |
| 689 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 696 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
| 690 } | 697 } |
| 691 | 698 |
| 692 } // namespace base | 699 } // namespace base |
| OLD | NEW |