static gboolean on_timer_source_ready (GObject *stream, GoaAlarm *self) { gint64 number_of_fires; gssize bytes_read; gboolean run_again = FALSE; g_return_val_if_fail (GOA_IS_ALARM (self), FALSE); g_return_val_if_fail (self->priv->type == GOA_ALARM_TYPE_TIMER, FALSE); g_rec_mutex_lock (&self->priv->lock); if (g_cancellable_is_cancelled (self->priv->cancellable)) goto out; bytes_read = g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (stream), &number_of_fires, sizeof (gint64), NULL, NULL); if (bytes_read == sizeof (gint64)) { if (number_of_fires < 0 || number_of_fires > 1) { goa_warning ("GoaAlarm: expected timerfd to report firing once," "but it reported firing %ld times\n", (long) number_of_fires); } } fire_or_rearm_alarm (self); run_again = TRUE; out: g_rec_mutex_unlock (&self->priv->lock); return run_again; }
static gboolean on_immediate_wakeup_source_ready (GoaAlarm *self) { g_return_val_if_fail (self->priv->type != GOA_ALARM_TYPE_UNSCHEDULED, FALSE); g_rec_mutex_lock (&self->priv->lock); fire_or_rearm_alarm (self); g_rec_mutex_unlock (&self->priv->lock); return FALSE; }
static gboolean on_timer_source_ready (GObject *stream, GoaAlarm *self) { gint64 number_of_fires; gssize bytes_read; gboolean run_again = FALSE; GError *error = NULL; g_return_val_if_fail (GOA_IS_ALARM (self), FALSE); g_rec_mutex_lock (&self->priv->lock); if (self->priv->type != GOA_ALARM_TYPE_TIMER) { g_warning ("GoaAlarm: timer source ready callback called " "when timer source isn't supposed to be used. " "Current timer type is %u", self->priv->type); goto out; } bytes_read = g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (stream), &number_of_fires, sizeof (gint64), NULL, &error); if (bytes_read < 0) { g_warning ("GoaAlarm: failed to read from timer fd: %s\n", error->message); g_error_free (error); goto out; } if (bytes_read == sizeof (gint64)) { if (number_of_fires < 0 || number_of_fires > 1) { g_warning ("GoaAlarm: expected timerfd to report firing once," "but it reported firing %ld times\n", (long) number_of_fires); } } fire_or_rearm_alarm (self); run_again = TRUE; out: g_rec_mutex_unlock (&self->priv->lock); return run_again; }
static gboolean on_timeout_source_ready (GoaAlarm *self) { g_return_val_if_fail (GOA_IS_ALARM (self), FALSE); g_rec_mutex_lock (&self->priv->lock); if (self->priv->type == GOA_ALARM_TYPE_UNSCHEDULED) goto out; fire_or_rearm_alarm (self); schedule_wakeups_with_timeout_source (self); out: g_rec_mutex_unlock (&self->priv->lock); return FALSE; }