| 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_flutter_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 179 of file fl_task_runner.cc.

179 {
180 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
181 (void)locker; // unused variable
182
183 g_return_if_fail(self->blocking_main_thread == FALSE);
184
185 g_object_ref(self);
186
187 self->blocking_main_thread = true;
188 while (self->blocking_main_thread) {
189 g_cond_wait_until(&self->cond, &self->mutex,
190 fl_task_runner_next_task_expiration_time_locked(self));
191 fl_task_runner_process_expired_tasks_locked(self);
192 }
193
194 // Tasks might have changed in the meanwhile, reschedule timeout
195 fl_task_runner_tasks_did_change_locked(self);
196
197 g_object_unref(self);
198 }
g_autoptr
g_autoptr(GMutexLocker) locker
self
g_cond_signal & self
Definition: fl_compositor_software.cc:67
fl_task_runner_process_expired_tasks_locked
static void fl_task_runner_process_expired_tasks_locked(FlTaskRunner *self)
Definition: fl_task_runner.cc:37
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:97
fl_task_runner_tasks_did_change_locked
static void fl_task_runner_tasks_did_change_locked(FlTaskRunner *self)
Definition: fl_task_runner.cc:109

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

## ◆ 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 157 of file fl_task_runner.cc.

157 {
158 FlTaskRunner* self =
159 FL_TASK_RUNNER(g_object_new(fl_task_runner_get_type(), nullptr));
160 g_weak_ref_init(&self->engine, G_OBJECT(engine));
161 return self;
162 }

References self.

Referenced by fl_engine_init().

## ◆ fl_task_runner_post_flutter_task()

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

fl_task_runner_post_flutter_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 164 of file fl_task_runner.cc.

166 {
167 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
168 (void)locker; // unused variable
169
170 FlTaskRunnerTask* runner_task = g_new0(FlTaskRunnerTask, 1);
171 runner_task->task = task;
172 runner_task->task_time_micros =
173 target_time_nanos / kMicrosecondsPerNanosecond;
174
175 self->pending_tasks = g_list_append(self->pending_tasks, runner_task);
176 fl_task_runner_tasks_did_change_locked(self);
177 }
kMicrosecondsPerNanosecond
static constexpr int kMicrosecondsPerNanosecond
Definition: fl_task_runner.cc:8
_FlTaskRunnerTask
Definition: fl_task_runner.cc:24
_FlTaskRunnerTask::task
FlutterTask task
Definition: fl_task_runner.cc:30
_FlTaskRunnerTask::task_time_micros
gint64 task_time_micros
Definition: fl_task_runner.cc:26

References fl_task_runner_tasks_did_change_locked(), g_autoptr(), kMicrosecondsPerNanosecond, self, _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 200 of file fl_task_runner.cc.

200 {
201 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
202 (void)locker; // unused variable
203
204 g_return_if_fail(self->blocking_main_thread == TRUE);
205
206 self->blocking_main_thread = FALSE;
207 g_cond_signal(&self->cond);
208 }
TRUE
return TRUE
Definition: fl_compositor_software.cc:69

References g_autoptr(), self, and TRUE.

## ◆ G_DECLARE_FINAL_TYPE()

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