5#include "flutter/shell/platform/linux/fl_task_runner.h"
6#include "flutter/shell/platform/linux/fl_engine_private.h"
35 GList* expired_tasks =
nullptr;
37 gint64 current_time = g_get_monotonic_time();
39 GList* l =
self->pending_tasks;
40 while (l !=
nullptr) {
45 self->pending_tasks = g_list_remove_link(
self->pending_tasks,
link);
46 expired_tasks = g_list_concat(expired_tasks,
link);
52 g_mutex_unlock(&
self->mutex);
55 while (l !=
nullptr &&
self->engine) {
61 g_list_free_full(expired_tasks, g_free);
63 g_mutex_lock(&
self->mutex);
71 FlTaskRunner*
self = FL_TASK_RUNNER(
data);
73 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&
self->mutex);
78 self->timeout_source_id = 0;
93 gint64 min_time = G_MAXINT64;
94 GList* l =
self->pending_tasks;
95 while (l !=
nullptr) {
104 if (
self->blocking_main_thread) {
106 g_cond_signal(&
self->cond);
109 if (
self->timeout_source_id != 0) {
110 g_source_remove(
self->timeout_source_id);
111 self->timeout_source_id = 0;
114 if (min_time != G_MAXINT64) {
115 gint64 remaining =
MAX(min_time - g_get_monotonic_time(), 0);
116 self->timeout_source_id =
124 GObject* where_the_object_was) {
126 self->engine =
nullptr;
130 FlTaskRunner*
self = FL_TASK_RUNNER(
object);
134 g_assert(!
self->blocking_main_thread);
136 if (
self->engine !=
nullptr) {
138 self->engine =
nullptr;
141 g_mutex_clear(&
self->mutex);
142 g_cond_clear(&
self->cond);
144 g_list_free_full(
self->pending_tasks, g_free);
145 if (
self->timeout_source_id != 0) {
146 g_source_remove(
self->timeout_source_id);
149 G_OBJECT_CLASS(fl_task_runner_parent_class)->dispose(
object);
157 g_mutex_init(&
self->mutex);
158 g_cond_init(&
self->cond);
163 FL_TASK_RUNNER(g_object_new(fl_task_runner_get_type(),
nullptr));
171 uint64_t target_time_nanos) {
172 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&
self->mutex);
176 runner_task->
task = task;
180 self->pending_tasks = g_list_append(
self->pending_tasks, runner_task);
185 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&
self->mutex);
188 g_return_if_fail(
self->blocking_main_thread ==
FALSE);
192 self->blocking_main_thread =
true;
193 while (
self->blocking_main_thread) {
194 g_cond_wait_until(&
self->cond, &
self->mutex,
202 g_object_unref(
self);
206 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&
self->mutex);
209 g_return_if_fail(
self->blocking_main_thread ==
TRUE);
212 g_cond_signal(&
self->cond);
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
void fl_engine_execute_task(FlEngine *self, FlutterTask *task)
FlTaskRunner * fl_task_runner_new(FlEngine *engine)
void fl_task_runner_dispose(GObject *object)
static void fl_task_runner_process_expired_tasks_locked(FlTaskRunner *self)
static void engine_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)
struct _FlTaskRunnerTask FlTaskRunnerTask
static gint64 fl_task_runner_next_task_expiration_time_locked(FlTaskRunner *self)
void fl_task_runner_release_main_thread(FlTaskRunner *self)
static constexpr int kMillisecondsPerMicrosecond
static void fl_task_runner_class_init(FlTaskRunnerClass *klass)
static void fl_task_runner_tasks_did_change_locked(FlTaskRunner *self)
void fl_task_runner_block_main_thread(FlTaskRunner *self)
static gboolean fl_task_runner_on_expired_timeout(gpointer data)
void fl_task_runner_post_task(FlTaskRunner *self, FlutterTask task, uint64_t target_time_nanos)
static constexpr int kMicrosecondsPerNanosecond
static void fl_task_runner_init(FlTaskRunner *self)
def link(from_root, to_root)
gboolean blocking_main_thread
std::shared_ptr< const fml::Mapping > data