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) {
125 FlTaskRunner*
self = FL_TASK_RUNNER(
user_data);
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);
211 self->blocking_main_thread = FALSE;
212 g_cond_signal(&self->cond);