summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebarshi Ray <debarshir@gnome.org>2017-09-05 17:17:46 +0200
committerDebarshi Ray <debarshir@gnome.org>2018-07-16 13:27:34 +0200
commit62f24d7409da0fd758484609a363c6cbdf69bd67 (patch)
treedc191d635af26537c72debb31e0e2a3b3647cdb2
parent08c3eeab41f004abd46fa15fe95eb02a64c627de (diff)
downloadgrilo-wip/rishi/sync-async.tar.gz
source: Stop random GSources from being triggered during a sync callwip/rishi/sync-async
https://bugzilla.gnome.org/show_bug.cgi?id=787312
-rw-r--r--src/grl-source.c25
-rw-r--r--src/grl-sync-priv.h1
2 files changed, 23 insertions, 3 deletions
diff --git a/src/grl-source.c b/src/grl-source.c
index 5426f2d..9a9ab4c 100644
--- a/src/grl-source.c
+++ b/src/grl-source.c
@@ -2564,7 +2564,7 @@ resolve_result_async_cb (GrlSource *source,
}
ds->data = media;
- ds->complete = TRUE;
+ g_main_loop_quit (ds->loop);
}
static void
@@ -3397,9 +3397,14 @@ grl_source_resolve_sync (GrlSource *source,
GrlOperationOptions *options,
GError **error)
{
+ GMainContext *context;
GrlDataSync *ds;
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context);
+
ds = g_slice_new0 (GrlDataSync);
+ ds->loop = g_main_loop_new (context, FALSE);
if (grl_source_resolve (source,
media,
@@ -3407,7 +3412,7 @@ grl_source_resolve_sync (GrlSource *source,
options,
resolve_result_async_cb,
ds))
- grl_wait_for_async_operation_complete (ds);
+ g_main_loop_run (ds->loop);
if (ds->error) {
if (error) {
@@ -3417,6 +3422,10 @@ grl_source_resolve_sync (GrlSource *source,
}
}
+ g_main_context_pop_thread_default (context);
+
+ g_main_context_unref (context);
+ g_main_loop_unref (ds->loop);
g_slice_free (GrlDataSync, ds);
return media;
@@ -3655,10 +3664,15 @@ grl_source_get_media_from_uri_sync (GrlSource *source,
GrlOperationOptions *options,
GError **error)
{
+ GMainContext *context;
GrlDataSync *ds;
GrlMedia *result;
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context);
+
ds = g_slice_new0 (GrlDataSync);
+ ds->loop = g_main_loop_new (context, FALSE);
if (grl_source_get_media_from_uri (source,
uri,
@@ -3666,7 +3680,7 @@ grl_source_get_media_from_uri_sync (GrlSource *source,
options,
resolve_result_async_cb,
ds))
- grl_wait_for_async_operation_complete (ds);
+ g_main_loop_run (ds->loop);
if (ds->error) {
if (error) {
@@ -3677,6 +3691,11 @@ grl_source_get_media_from_uri_sync (GrlSource *source,
}
result = (GrlMedia *) ds->data;
+
+ g_main_context_pop_thread_default (context);
+
+ g_main_context_unref (context);
+ g_main_loop_unref (ds->loop);
g_slice_free (GrlDataSync, ds);
return result;
diff --git a/src/grl-sync-priv.h b/src/grl-sync-priv.h
index cf6b1cc..6257995 100644
--- a/src/grl-sync-priv.h
+++ b/src/grl-sync-priv.h
@@ -29,6 +29,7 @@ typedef struct {
gboolean complete;
gpointer data;
GError *error;
+ GMainLoop *loop;
} GrlDataSync;
void