| Flutter Linux Embedder |

Functions
fl_task_runner.h File Reference
`#include <glib-object.h>`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"`

Go to the source code of this file.

## Functions
G_BEGIN_DECLS | G_DECLARE_FINAL_TYPE (FlTaskRunner, fl_task_runner, FL, TASK_RUNNER, GObject)
FlTaskRunner * | fl_task_runner_new (FlEngine *engine)
void | fl_task_runner_post_task (FlTaskRunner *task_runner, FlutterTask task, uint64_t target_time_nanos)
void | fl_task_runner_block_main_thread (FlTaskRunner *task_runner)
void | fl_task_runner_release_main_thread (FlTaskRunner *self)

## Function Documentation

## ◆ fl_task_runner_block_main_thread()

void fl_task_runner_block_main_thread | ( | FlTaskRunner * | task_runner | ) |

fl_task_runner_block_main_thread: @task_runner: an #FlTaskRunner.

Blocks main thread until fl_task_runner_release_main_thread is called. While main thread is blocked tasks posted to #FlTaskRunner are executed as usual. Must be invoked on main thread.

Definition at line 184 of file fl_task_runner.cc.

184 {
185 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
186 (void)locker; // unused variable
187
188 g_return_if_fail(self->blocking_main_thread == FALSE);
189
190 g_object_ref(self);
191
192 self->blocking_main_thread = true;
193 while (self->blocking_main_thread) {
194 g_cond_wait_until(&self->cond, &self->mutex,
195 fl_task_runner_next_task_expiration_time_locked(self));
196 fl_task_runner_process_expired_tasks_locked(self);
197 }
198
199 // Tasks might have changed in the meanwhile, reschedule timeout
200 fl_task_runner_tasks_did_change_locked(self);
201
202 g_object_unref(self);
203 }

References fl_task_runner_next_task_expiration_time_locked(), fl_task_runner_process_expired_tasks_locked(), and fl_task_runner_tasks_did_change_locked().

Referenced by fl_renderer_wait_for_frame().

## ◆ fl_task_runner_new()

FlTaskRunner* fl_task_runner_new | ( | FlEngine * | engine | ) |

fl_task_runner_new: @engine: the #FlEngine owning the task runner.

Creates new task runner instance.

Returns: an #FlTaskRunner.

Definition at line 161 of file fl_task_runner.cc.

161 {
162 FlTaskRunner* res =
163 FL_TASK_RUNNER(g_object_new(fl_task_runner_get_type(), nullptr));
164 res->engine = engine;
165 g_object_weak_ref(G_OBJECT(engine), engine_weak_notify_cb, res);
166 return res;
167 }

References engine, and engine_weak_notify_cb().

Referenced by fl_engine_start().

## ◆ fl_task_runner_post_task()

void fl_task_runner_post_task | ( | FlTaskRunner * | task_runner,
|  | FlutterTask | task,
|  | uint64_t | target_time_nanos
| ) |  |

fl_task_runner_post_task: @task_runner: an #FlTaskRunner. @task: Flutter task being scheduled @target_time_nanos: absolute time in nanoseconds

Posts a Flutter task to be executed on main thread. This function is thread safe and may be called from any thread.

Definition at line 169 of file fl_task_runner.cc.

171 {
172 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
173 (void)locker; // unused variable
174
175 FlTaskRunnerTask* runner_task = g_new0(FlTaskRunnerTask, 1);
176 runner_task->task = task;
177 runner_task->task_time_micros =
178 target_time_nanos / kMicrosecondsPerNanosecond;
179
180 self->pending_tasks = g_list_append(self->pending_tasks, runner_task);
181 fl_task_runner_tasks_did_change_locked(self);
182 }

References fl_task_runner_tasks_did_change_locked(), kMicrosecondsPerNanosecond, _FlTaskRunnerTask::task, and _FlTaskRunnerTask::task_time_micros.

Referenced by fl_engine_post_task().

## ◆ fl_task_runner_release_main_thread()

void fl_task_runner_release_main_thread | ( | FlTaskRunner * | self | ) |

fl_task_runner_release_main_thread: @task_runner: an #FlTaskRunner.

Unblocks main thread. This will resume normal processing of main loop. Can be invoked from any thread.

Definition at line 205 of file fl_task_runner.cc.

205 {
206 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
207 (void)locker; // unused variable
208
209 g_return_if_fail(self->blocking_main_thread == TRUE);
210
211 self->blocking_main_thread = FALSE;
212 g_cond_signal(&self->cond);
213 }

References TRUE.

Referenced by fl_renderer_unblock_main_thread().

## ◆ G_DECLARE_FINAL_TYPE()

G_BEGIN_DECLS G_DECLARE_FINAL_TYPE | ( | FlTaskRunner | ,
|  | fl_task_runner | ,
|  | FL | ,
|  | TASK_RUNNER | ,
|  | GObject |
| ) |  |

kMicrosecondsPerNanosecond
static constexpr int kMicrosecondsPerNanosecond
Definition: fl_task_runner.cc:8
_FlTaskRunnerTask::task_time_micros
gint64 task_time_micros
Definition: fl_task_runner.cc:26
fl_task_runner_process_expired_tasks_locked
static void fl_task_runner_process_expired_tasks_locked(FlTaskRunner *self)
Definition: fl_task_runner.cc:34
fl_task_runner_next_task_expiration_time_locked
static gint64 fl_task_runner_next_task_expiration_time_locked(FlTaskRunner *self)
Definition: fl_task_runner.cc:91
engine_weak_notify_cb
static void engine_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)
Definition: fl_task_runner.cc:123
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_task_runner_tasks_did_change_locked
static void fl_task_runner_tasks_did_change_locked(FlTaskRunner *self)
Definition: fl_task_runner.cc:103
engine
FlEngine * engine
Definition: fl_view_accessible.cc:26
_FlTaskRunnerTask::task
FlutterTask task
Definition: fl_task_runner.cc:27
_FlTaskRunnerTask
Definition: fl_task_runner.cc:24