2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2017-03-20 13:41:41 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
#ifndef FLUTTER_FML_MESSAGE_LOOP_IMPL_H_
|
|
|
|
|
#define FLUTTER_FML_MESSAGE_LOOP_IMPL_H_
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <deque>
|
2018-04-13 13:48:15 -07:00
|
|
|
#include <map>
|
2018-03-09 11:19:23 -08:00
|
|
|
#include <mutex>
|
2017-03-20 13:41:41 -07:00
|
|
|
#include <queue>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2018-07-26 12:49:34 -07:00
|
|
|
#include "flutter/fml/closure.h"
|
2019-06-11 18:33:04 -07:00
|
|
|
#include "flutter/fml/delayed_task.h"
|
2018-04-21 20:50:03 -07:00
|
|
|
#include "flutter/fml/macros.h"
|
2018-07-26 12:49:34 -07:00
|
|
|
#include "flutter/fml/memory/ref_counted.h"
|
2017-03-20 13:41:41 -07:00
|
|
|
#include "flutter/fml/message_loop.h"
|
2019-06-19 14:03:14 -07:00
|
|
|
#include "flutter/fml/message_loop_task_queues.h"
|
2018-07-26 12:49:34 -07:00
|
|
|
#include "flutter/fml/time/time_point.h"
|
2019-06-13 17:44:44 -07:00
|
|
|
#include "flutter/fml/wakeable.h"
|
2017-03-20 13:41:41 -07:00
|
|
|
|
|
|
|
|
namespace fml {
|
|
|
|
|
|
2019-06-13 17:44:44 -07:00
|
|
|
class MessageLoopImpl : public Wakeable,
|
|
|
|
|
public fml::RefCountedThreadSafe<MessageLoopImpl> {
|
2017-03-20 13:41:41 -07:00
|
|
|
public:
|
2018-07-26 12:49:34 -07:00
|
|
|
static fml::RefPtr<MessageLoopImpl> Create();
|
2017-03-20 13:41:41 -07:00
|
|
|
|
|
|
|
|
virtual ~MessageLoopImpl();
|
|
|
|
|
|
|
|
|
|
virtual void Run() = 0;
|
|
|
|
|
|
|
|
|
|
virtual void Terminate() = 0;
|
|
|
|
|
|
2019-11-22 12:20:02 -08:00
|
|
|
void PostTask(const fml::closure& task, fml::TimePoint target_time);
|
2017-03-20 13:41:41 -07:00
|
|
|
|
2019-11-22 12:20:02 -08:00
|
|
|
void AddTaskObserver(intptr_t key, const fml::closure& callback);
|
2017-03-23 15:29:33 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
void RemoveTaskObserver(intptr_t key);
|
2017-03-20 13:41:41 -07:00
|
|
|
|
|
|
|
|
void DoRun();
|
|
|
|
|
|
|
|
|
|
void DoTerminate();
|
|
|
|
|
|
2019-07-12 16:55:33 -07:00
|
|
|
virtual TaskQueueId GetTaskQueueId() const;
|
|
|
|
|
|
2019-04-09 17:03:41 -07:00
|
|
|
protected:
|
2018-01-17 16:59:36 -08:00
|
|
|
// Exposed for the embedder shell which allows clients to poll for events
|
|
|
|
|
// instead of dedicating a thread to the message loop.
|
2019-04-09 17:03:41 -07:00
|
|
|
friend class MessageLoop;
|
|
|
|
|
|
2018-01-17 16:59:36 -08:00
|
|
|
void RunExpiredTasksNow();
|
|
|
|
|
|
2019-04-09 17:03:41 -07:00
|
|
|
void RunSingleExpiredTaskNow();
|
|
|
|
|
|
2017-03-20 13:41:41 -07:00
|
|
|
protected:
|
|
|
|
|
MessageLoopImpl();
|
|
|
|
|
|
|
|
|
|
private:
|
2019-06-19 14:03:14 -07:00
|
|
|
fml::RefPtr<MessageLoopTaskQueues> task_queue_;
|
|
|
|
|
TaskQueueId queue_id_;
|
|
|
|
|
|
2017-03-20 13:41:41 -07:00
|
|
|
std::atomic_bool terminated_;
|
|
|
|
|
|
2019-04-09 17:03:41 -07:00
|
|
|
void FlushTasks(FlushType type);
|
2017-03-20 13:41:41 -07:00
|
|
|
|
2018-04-21 20:50:03 -07:00
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(MessageLoopImpl);
|
2017-03-20 13:41:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace fml
|
|
|
|
|
|
|
|
|
|
#endif // FLUTTER_FML_MESSAGE_LOOP_IMPL_H_
|