Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 5 | #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_ |
6 | #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_ | ||||
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 7 | |
[email protected] | 32857c0 | 2014-06-25 17:40:57 | [diff] [blame] | 8 | #include "base/base_export.h" |
[email protected] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 9 | #include "base/message_loop/message_pump.h" |
[email protected] | 9bf0b36 | 2013-06-14 23:15:32 | [diff] [blame] | 10 | #include "base/synchronization/waitable_event.h" |
[email protected] | 99084f6 | 2013-06-28 00:49:07 | [diff] [blame] | 11 | #include "base/time/time.h" |
Robert Sesek | d5ebd4b | 2017-09-22 23:09:07 | [diff] [blame] | 12 | #include "build/build_config.h" |
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 13 | |
14 | namespace base { | ||||
15 | |||||
[email protected] | 32857c0 | 2014-06-25 17:40:57 | [diff] [blame] | 16 | class BASE_EXPORT MessagePumpDefault : public MessagePump { |
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 17 | public: |
18 | MessagePumpDefault(); | ||||
Peter Boström | 7319bbd | 2021-09-15 22:59:38 | [diff] [blame] | 19 | |
20 | MessagePumpDefault(const MessagePumpDefault&) = delete; | ||||
21 | MessagePumpDefault& operator=(const MessagePumpDefault&) = delete; | ||||
22 | |||||
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 23 | ~MessagePumpDefault() override; |
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 24 | |
25 | // MessagePump methods: | ||||
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 26 | void Run(Delegate* delegate) override; |
27 | void Quit() override; | ||||
28 | void ScheduleWork() override; | ||||
Etienne Pierre-doray | f2f8e13b | 2022-03-10 12:42:33 | [diff] [blame] | 29 | void ScheduleDelayedWork( |
30 | const Delegate::NextWorkInfo& next_work_info) override; | ||||
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 31 | |
Benoît Lizé | 8299026 | 2025-01-15 00:04:55 | [diff] [blame] | 32 | // Visible for testing. |
33 | void RecordWaitTime(base::TimeDelta wait_time); | ||||
34 | bool ShouldBusyLoop() const; | ||||
35 | |||||
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 36 | private: |
Benoît Lizé | 8299026 | 2025-01-15 00:04:55 | [diff] [blame] | 37 | // Returns whether the event was signaled. |
38 | bool BusyWaitOnEvent(base::TimeTicks before); | ||||
39 | |||||
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 40 | // This flag is set to false when Run should return. |
41 | bool keep_running_; | ||||
42 | |||||
43 | // Used to sleep until there is more work to do. | ||||
44 | WaitableEvent event_; | ||||
Benoît Lizé | 8299026 | 2025-01-15 00:04:55 | [diff] [blame] | 45 | |
46 | base::TimeDelta last_wait_time_; | ||||
47 | base::TimeDelta wait_time_exponential_moving_average_; | ||||
[email protected] | b2e9729 | 2008-09-02 18:20:34 | [diff] [blame] | 48 | }; |
49 | |||||
50 | } // namespace base | ||||
51 | |||||
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 52 | #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_ |