Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_default.h" | 5 #include "base/message_loop/message_pump_default.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 10 | 12 |
| 11 #if defined(OS_MACOSX) | 13 #if defined(OS_MACOSX) |
| 12 #include "base/mac/scoped_nsautorelease_pool.h" | 14 #include "base/mac/scoped_nsautorelease_pool.h" |
| 13 #endif | 15 #endif |
| 14 | 16 |
| 15 namespace base { | 17 namespace base { |
| 16 | 18 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 47 | 49 |
| 48 if (did_work) | 50 if (did_work) |
| 49 continue; | 51 continue; |
| 50 | 52 |
| 51 ThreadRestrictions::ScopedAllowWait allow_wait; | 53 ThreadRestrictions::ScopedAllowWait allow_wait; |
| 52 if (delayed_work_time_.is_null()) { | 54 if (delayed_work_time_.is_null()) { |
| 53 event_.Wait(); | 55 event_.Wait(); |
| 54 } else { | 56 } else { |
| 55 TimeDelta delay = delayed_work_time_ - TimeTicks::Now(); | 57 TimeDelta delay = delayed_work_time_ - TimeTicks::Now(); |
| 56 if (delay > TimeDelta()) { | 58 if (delay > TimeDelta()) { |
| 59 #if defined(OS_WIN) | |
| 60 // crbug.com/487724: on Windows, waiting for less than 1 ms results in | |
| 61 // returning from TimedWait promptly and spinning the loop. | |
| 62 TimeDelta min_delay = TimeDelta::FromMilliseconds(1); | |
|
brucedawson
2016/06/21 21:35:11
This should be const to make the intent clearer.
stanisc
2016/06/22 01:28:07
Done.
| |
| 63 do { | |
| 64 delay = std::max(delay, min_delay); | |
| 65 if (event_.TimedWait(delay)) | |
| 66 break; | |
| 67 | |
| 68 // TimedWait can time out earlier than the specified |delay| on | |
| 69 // Windows. It doesn't make sense to run the outer loop in that case | |
| 70 // because there isn't going to be any new work. It is less overhead | |
| 71 // go just go back to wait. | |
| 72 // In practice this inner wait loop might have up to 3 iterations. | |
| 73 delay = delayed_work_time_ - TimeTicks::Now(); | |
| 74 } while (delay > TimeDelta()); | |
| 75 #else | |
| 57 event_.TimedWait(delay); | 76 event_.TimedWait(delay); |
| 77 #endif | |
| 58 } else { | 78 } else { |
| 59 // It looks like delayed_work_time_ indicates a time in the past, so we | 79 // It looks like delayed_work_time_ indicates a time in the past, so we |
| 60 // need to call DoDelayedWork now. | 80 // need to call DoDelayedWork now. |
| 61 delayed_work_time_ = TimeTicks(); | 81 delayed_work_time_ = TimeTicks(); |
| 62 } | 82 } |
| 63 } | 83 } |
| 64 // Since event_ is auto-reset, we don't need to do anything special here | 84 // Since event_ is auto-reset, we don't need to do anything special here |
| 65 // other than service each delegate method. | 85 // other than service each delegate method. |
| 66 } | 86 } |
| 67 | 87 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 80 | 100 |
| 81 void MessagePumpDefault::ScheduleDelayedWork( | 101 void MessagePumpDefault::ScheduleDelayedWork( |
| 82 const TimeTicks& delayed_work_time) { | 102 const TimeTicks& delayed_work_time) { |
| 83 // We know that we can't be blocked on Wait right now since this method can | 103 // We know that we can't be blocked on Wait right now since this method can |
| 84 // only be called on the same thread as Run, so we only need to update our | 104 // only be called on the same thread as Run, so we only need to update our |
| 85 // record of how long to sleep when we do sleep. | 105 // record of how long to sleep when we do sleep. |
| 86 delayed_work_time_ = delayed_work_time; | 106 delayed_work_time_ = delayed_work_time; |
| 87 } | 107 } |
| 88 | 108 |
| 89 } // namespace base | 109 } // namespace base |
| OLD | NEW |