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 <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 MessagePumpForIO::MessagePumpForIO() { | 414 MessagePumpForIO::MessagePumpForIO() { |
415 port_.Set(CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1)); | 415 port_.Set(CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1)); |
416 DCHECK(port_.IsValid()); | 416 DCHECK(port_.IsValid()); |
417 } | 417 } |
418 | 418 |
419 void MessagePumpForIO::ScheduleWork() { | 419 void MessagePumpForIO::ScheduleWork() { |
420 if (InterlockedExchange(&have_work_, 1)) | 420 if (InterlockedExchange(&have_work_, 1)) |
421 return; // Someone else continued the pumping. | 421 return; // Someone else continued the pumping. |
422 | 422 |
423 // Make sure the MessagePump does some work for us. | 423 // Make sure the MessagePump does some work for us. |
424 BOOL ret = PostQueuedCompletionStatus(port_, 0, | 424 BOOL ret = PostQueuedCompletionStatus(port_.Get(), 0, |
425 reinterpret_cast<ULONG_PTR>(this), | 425 reinterpret_cast<ULONG_PTR>(this), |
426 reinterpret_cast<OVERLAPPED*>(this)); | 426 reinterpret_cast<OVERLAPPED*>(this)); |
427 if (ret) | 427 if (ret) |
428 return; // Post worked perfectly. | 428 return; // Post worked perfectly. |
429 | 429 |
430 // See comment in MessagePumpForUI::ScheduleWork() for this error recovery. | 430 // See comment in MessagePumpForUI::ScheduleWork() for this error recovery. |
431 InterlockedExchange(&have_work_, 0); // Clarify that we didn't succeed. | 431 InterlockedExchange(&have_work_, 0); // Clarify that we didn't succeed. |
432 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", COMPLETION_POST_ERROR, | 432 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", COMPLETION_POST_ERROR, |
433 MESSAGE_LOOP_PROBLEM_MAX); | 433 MESSAGE_LOOP_PROBLEM_MAX); |
434 } | 434 } |
435 | 435 |
436 void MessagePumpForIO::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { | 436 void MessagePumpForIO::ScheduleDelayedWork(const TimeTicks& delayed_work_time) { |
437 // We know that we can't be blocked right now since this method can only be | 437 // We know that we can't be blocked right now since this method can only be |
438 // called on the same thread as Run, so we only need to update our record of | 438 // called on the same thread as Run, so we only need to update our record of |
439 // how long to sleep when we do sleep. | 439 // how long to sleep when we do sleep. |
440 delayed_work_time_ = delayed_work_time; | 440 delayed_work_time_ = delayed_work_time; |
441 } | 441 } |
442 | 442 |
443 void MessagePumpForIO::RegisterIOHandler(HANDLE file_handle, | 443 void MessagePumpForIO::RegisterIOHandler(HANDLE file_handle, |
444 IOHandler* handler) { | 444 IOHandler* handler) { |
445 ULONG_PTR key = HandlerToKey(handler, true); | 445 ULONG_PTR key = HandlerToKey(handler, true); |
446 HANDLE port = CreateIoCompletionPort(file_handle, port_, key, 1); | 446 HANDLE port = CreateIoCompletionPort(file_handle, port_.Get(), key, 1); |
447 DPCHECK(port); | 447 DPCHECK(port); |
448 } | 448 } |
449 | 449 |
450 bool MessagePumpForIO::RegisterJobObject(HANDLE job_handle, | 450 bool MessagePumpForIO::RegisterJobObject(HANDLE job_handle, |
451 IOHandler* handler) { | 451 IOHandler* handler) { |
452 // Job object notifications use the OVERLAPPED pointer to carry the message | 452 // Job object notifications use the OVERLAPPED pointer to carry the message |
453 // data. Mark the completion key correspondingly, so we will not try to | 453 // data. Mark the completion key correspondingly, so we will not try to |
454 // convert OVERLAPPED* to IOContext*. | 454 // convert OVERLAPPED* to IOContext*. |
455 ULONG_PTR key = HandlerToKey(handler, false); | 455 ULONG_PTR key = HandlerToKey(handler, false); |
456 JOBOBJECT_ASSOCIATE_COMPLETION_PORT info; | 456 JOBOBJECT_ASSOCIATE_COMPLETION_PORT info; |
457 info.CompletionKey = reinterpret_cast<void*>(key); | 457 info.CompletionKey = reinterpret_cast<void*>(key); |
458 info.CompletionPort = port_; | 458 info.CompletionPort = port_.Get(); |
459 return SetInformationJobObject(job_handle, | 459 return SetInformationJobObject(job_handle, |
460 JobObjectAssociateCompletionPortInformation, | 460 JobObjectAssociateCompletionPortInformation, |
461 &info, | 461 &info, |
462 sizeof(info)) != FALSE; | 462 sizeof(info)) != FALSE; |
463 } | 463 } |
464 | 464 |
465 //----------------------------------------------------------------------------- | 465 //----------------------------------------------------------------------------- |
466 // MessagePumpForIO private: | 466 // MessagePumpForIO private: |
467 | 467 |
468 void MessagePumpForIO::DoRunLoop() { | 468 void MessagePumpForIO::DoRunLoop() { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 627 |
628 // static | 628 // static |
629 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 629 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
630 ULONG_PTR key, | 630 ULONG_PTR key, |
631 bool* has_valid_io_context) { | 631 bool* has_valid_io_context) { |
632 *has_valid_io_context = ((key & 1) == 0); | 632 *has_valid_io_context = ((key & 1) == 0); |
633 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 633 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
634 } | 634 } |
635 | 635 |
636 } // namespace base | 636 } // namespace base |
OLD | NEW |