core/monitor: Assert we're in the right thread
Right now everything works as expected, but this should catch cases where we're running functions on the wrong thread.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#define G_LOG_DOMAIN "GcalCalendarMonitor"
|
||||
|
||||
#include "gcal-calendar-monitor.h"
|
||||
#include "gcal-core-macros.h"
|
||||
#include "gcal-date-time-utils.h"
|
||||
#include "gcal-debug.h"
|
||||
#include "gcal-event.h"
|
||||
@@ -188,6 +189,8 @@ add_events_in_idle (GcalCalendarMonitor *self,
|
||||
{
|
||||
IdleData *idle_data;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
idle_data = g_new0 (IdleData, 1);
|
||||
idle_data->monitor = g_object_ref (self);
|
||||
idle_data->events = g_ptr_array_ref (events);
|
||||
@@ -205,6 +208,8 @@ update_events_in_idle (GcalCalendarMonitor *self,
|
||||
{
|
||||
IdleData *idle_data;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
idle_data = g_new0 (IdleData, 1);
|
||||
idle_data->monitor = g_object_ref (self);
|
||||
idle_data->events = g_ptr_array_ref (events);
|
||||
@@ -222,6 +227,8 @@ remove_events_in_idle (GcalCalendarMonitor *self,
|
||||
{
|
||||
IdleData *idle_data;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
idle_data = g_new0 (IdleData, 1);
|
||||
idle_data->monitor = g_object_ref (self);
|
||||
idle_data->event_ids = g_ptr_array_ref (events);
|
||||
@@ -239,6 +246,8 @@ set_complete_in_idle (GcalCalendarMonitor *self,
|
||||
{
|
||||
IdleData *idle_data;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
idle_data = g_new0 (IdleData, 1);
|
||||
idle_data->monitor = g_object_ref (self);
|
||||
idle_data->complete = complete;
|
||||
@@ -273,6 +282,8 @@ client_instance_generated_cb (ICalComponent *icomponent,
|
||||
data = user_data;
|
||||
self = data->monitor;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
@@ -306,6 +317,8 @@ on_client_view_objects_added_cb (ECalClientView *view,
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
range = get_monitor_ranges (self);
|
||||
|
||||
maybe_init_event_arrays (self);
|
||||
@@ -444,6 +457,8 @@ on_client_view_objects_modified_cb (ECalClientView *view,
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
if (!self->monitor_thread.populated && self->monitor_thread.events_to_add)
|
||||
{
|
||||
g_clear_pointer (&self->monitor_thread.events_to_add, g_ptr_array_unref);
|
||||
@@ -640,6 +655,8 @@ on_client_view_objects_removed_cb (ECalClientView *view,
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
event_ids = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
for (l = objects; l; l = l->next)
|
||||
@@ -701,6 +718,7 @@ on_client_view_complete_cb (ECalClientView *view,
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
g_assert (!self->monitor_thread.populated);
|
||||
|
||||
events_to_add = g_steal_pointer (&self->monitor_thread.events_to_add);
|
||||
@@ -728,6 +746,8 @@ create_view (GcalCalendarMonitor *self)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
reader_locker = g_rw_lock_reader_locker_new (&self->shared.lock);
|
||||
|
||||
g_assert (self->cancellable == NULL);
|
||||
@@ -788,6 +808,8 @@ remove_view (GcalCalendarMonitor *self)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
g_clear_object (&self->cancellable);
|
||||
|
||||
if (!self->monitor_thread.view)
|
||||
@@ -826,6 +848,8 @@ message_queue_source_prepare (GSource *source,
|
||||
queue_source = (MessageQueueSource*) source;
|
||||
self = queue_source->monitor;
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
return g_async_queue_length (self->messages) > 0;
|
||||
}
|
||||
|
||||
@@ -844,6 +868,8 @@ message_queue_source_dispatch (GSource *source,
|
||||
self = queue_source->monitor;
|
||||
event = GPOINTER_TO_INT (g_async_queue_pop (self->messages));
|
||||
|
||||
g_assert (GCAL_IS_THREAD (self->thread));
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case FILTER_UPDATED:
|
||||
@@ -928,6 +954,8 @@ static void
|
||||
notify_view_thread (GcalCalendarMonitor *self,
|
||||
MonitorThreadEvent event)
|
||||
{
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
g_async_queue_push (self->messages, GINT_TO_POINTER (event));
|
||||
g_main_context_wakeup (self->thread_context);
|
||||
}
|
||||
@@ -937,6 +965,8 @@ maybe_spawn_view_thread (GcalCalendarMonitor *self)
|
||||
{
|
||||
g_autofree gchar *thread_name = NULL;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
if (self->thread || !self->shared.range)
|
||||
return;
|
||||
|
||||
@@ -955,6 +985,8 @@ remove_events_outside_range (GcalCalendarMonitor *self,
|
||||
GHashTableIter iter;
|
||||
GcalEvent *event;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
GCAL_TRACE_MSG ("Removing events outside range from monitor");
|
||||
|
||||
writer_locker = g_rw_lock_writer_locker_new (&self->shared.lock);
|
||||
@@ -984,6 +1016,8 @@ remove_all_events (GcalCalendarMonitor *self)
|
||||
g_autoptr (GRWLockWriterLocker) writer_locker = NULL;
|
||||
g_autoptr (GPtrArray) events_to_remove = NULL;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
GCAL_TRACE_MSG ("Removing all events from view");
|
||||
|
||||
writer_locker = g_rw_lock_writer_locker_new (&self->shared.lock);
|
||||
@@ -998,6 +1032,8 @@ static void
|
||||
set_complete (GcalCalendarMonitor *self,
|
||||
gboolean complete)
|
||||
{
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
if (self->complete == complete)
|
||||
return;
|
||||
|
||||
@@ -1023,6 +1059,8 @@ add_events_to_timeline_in_idle_cb (gpointer user_data)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
idle_data = user_data;
|
||||
self = idle_data->monitor;
|
||||
events = idle_data->events;
|
||||
@@ -1064,6 +1102,8 @@ update_events_in_idle_cb (gpointer user_data)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
idle_data = user_data;
|
||||
self = idle_data->monitor;
|
||||
events = g_steal_pointer (&idle_data->events);
|
||||
@@ -1113,6 +1153,8 @@ remove_events_from_timeline_in_idle_cb (gpointer user_data)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
idle_data = user_data;
|
||||
self = idle_data->monitor;
|
||||
event_ids = g_steal_pointer (&idle_data->event_ids);
|
||||
@@ -1168,6 +1210,8 @@ complete_in_idle_cb (gpointer user_data)
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
g_assert (GCAL_IS_MAIN_THREAD ());
|
||||
|
||||
idle_data = user_data;
|
||||
self = idle_data->monitor;
|
||||
g_assert (idle_data->events == NULL);
|
||||
|
||||
Reference in New Issue
Block a user