blob: bf918d9b9dd853aab567338ae3f1270a5895c7bc [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[email protected]b2e97292008-09-02 18:20:342// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]59e69e742013-06-18 20:27:525#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_
6#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_
[email protected]b2e97292008-09-02 18:20:347
[email protected]32857c02014-06-25 17:40:578#include "base/base_export.h"
[email protected]59e69e742013-06-18 20:27:529#include "base/message_loop/message_pump.h"
[email protected]9bf0b362013-06-14 23:15:3210#include "base/synchronization/waitable_event.h"
[email protected]99084f62013-06-28 00:49:0711#include "base/time/time.h"
Robert Sesekd5ebd4b2017-09-22 23:09:0712#include "build/build_config.h"
[email protected]b2e97292008-09-02 18:20:3413
14namespace base {
15
[email protected]32857c02014-06-25 17:40:5716class BASE_EXPORT MessagePumpDefault : public MessagePump {
[email protected]b2e97292008-09-02 18:20:3417 public:
18 MessagePumpDefault();
Peter Boström7319bbd2021-09-15 22:59:3819
20 MessagePumpDefault(const MessagePumpDefault&) = delete;
21 MessagePumpDefault& operator=(const MessagePumpDefault&) = delete;
22
dcheng56488182014-10-21 10:54:5123 ~MessagePumpDefault() override;
[email protected]b2e97292008-09-02 18:20:3424
25 // MessagePump methods:
dcheng56488182014-10-21 10:54:5126 void Run(Delegate* delegate) override;
27 void Quit() override;
28 void ScheduleWork() override;
Etienne Pierre-dorayf2f8e13b2022-03-10 12:42:3329 void ScheduleDelayedWork(
30 const Delegate::NextWorkInfo& next_work_info) override;
[email protected]b2e97292008-09-02 18:20:3431
Benoît Lizé82990262025-01-15 00:04:5532 // Visible for testing.
33 void RecordWaitTime(base::TimeDelta wait_time);
34 bool ShouldBusyLoop() const;
35
[email protected]b2e97292008-09-02 18:20:3436 private:
Benoît Lizé82990262025-01-15 00:04:5537 // Returns whether the event was signaled.
38 bool BusyWaitOnEvent(base::TimeTicks before);
39
[email protected]b2e97292008-09-02 18:20:3440 // 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é82990262025-01-15 00:04:5545
46 base::TimeDelta last_wait_time_;
47 base::TimeDelta wait_time_exponential_moving_average_;
[email protected]b2e97292008-09-02 18:20:3448};
49
50} // namespace base
51
danakj0a448602015-03-10 00:31:1652#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_