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);
54 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
55 if (engine !=
nullptr) {
57 while (l !=
nullptr) {
64 g_list_free_full(expired_tasks, g_free);
66 g_mutex_lock(&self->mutex);
74 FlTaskRunner*
self = FL_TASK_RUNNER(data);
76 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
81 self->timeout_source_id = 0;
96 gint64 min_time = G_MAXINT64;
97 GList* l =
self->pending_tasks;
98 while (l !=
nullptr) {
107 if (self->blocking_main_thread) {
109 g_cond_signal(&self->cond);
112 if (self->timeout_source_id != 0) {
113 g_source_remove(self->timeout_source_id);
114 self->timeout_source_id = 0;
117 if (min_time != G_MAXINT64) {
118 gint64 remaining = MAX(min_time - g_get_monotonic_time(), 0);
119 self->timeout_source_id =
127 FlTaskRunner*
self = FL_TASK_RUNNER(
object);
131 g_assert(!self->blocking_main_thread);
133 g_weak_ref_clear(&self->engine);
134 g_mutex_clear(&self->mutex);
135 g_cond_clear(&self->cond);
137 g_list_free_full(self->pending_tasks, g_free);
138 if (self->timeout_source_id != 0) {
139 g_source_remove(self->timeout_source_id);
142 G_OBJECT_CLASS(fl_task_runner_parent_class)->dispose(
object);
150 g_mutex_init(&self->mutex);
151 g_cond_init(&self->cond);
156 FL_TASK_RUNNER(g_object_new(fl_task_runner_get_type(),
nullptr));
157 g_weak_ref_init(&self->engine, G_OBJECT(engine));
163 uint64_t target_time_nanos) {
164 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
168 runner_task->
task = task;
172 self->pending_tasks = g_list_append(self->pending_tasks, runner_task);
177 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
180 g_return_if_fail(self->blocking_main_thread == FALSE);
184 self->blocking_main_thread =
true;
185 while (self->blocking_main_thread) {
186 g_cond_wait_until(&self->cond, &self->mutex,
194 g_object_unref(
self);
198 g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&self->mutex);
201 g_return_if_fail(self->blocking_main_thread ==
TRUE);
203 self->blocking_main_thread = FALSE;
204 g_cond_signal(&self->cond);