[gnome-builder/gnome-builder-41] flatpak: dont use IdeObject for flatpak client
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-41] flatpak: dont use IdeObject for flatpak client
- Date: Fri, 19 Nov 2021 05:50:14 +0000 (UTC)
commit 74da786849dc42eb4e9dced266134c2ad1b99223
Author: Christian Hergert <chergert redhat com>
Date: Thu Nov 18 18:40:40 2021 -0800
flatpak: dont use IdeObject for flatpak client
Our client helper (which spawns the worker process) does not need to be
connected to the IdeObject tree for the project. This also helps ensure
that we do not run multiple copies of the gnome-builder-flatpak daemon
per Builder process.
Furthermore, it will allow us to spin up the process sooner at startup
so that there is less slowdown once opening a project.
src/plugins/flatpak/gbp-flatpak-client.c | 97 +++++++++++++---------
src/plugins/flatpak/gbp-flatpak-client.h | 10 +--
src/plugins/flatpak/gbp-flatpak-config-provider.c | 2 +-
src/plugins/flatpak/gbp-flatpak-manifest.c | 5 +-
src/plugins/flatpak/gbp-flatpak-runtime-provider.c | 8 +-
src/plugins/flatpak/gbp-flatpak-sdk-stage.c | 2 +-
src/plugins/flatpak/gbp-flatpak-util.c | 2 +-
7 files changed, 66 insertions(+), 60 deletions(-)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-client.c b/src/plugins/flatpak/gbp-flatpak-client.c
index 6bd0e0478..319d9a8d4 100644
--- a/src/plugins/flatpak/gbp-flatpak-client.c
+++ b/src/plugins/flatpak/gbp-flatpak-client.c
@@ -32,12 +32,14 @@
struct _GbpFlatpakClient
{
- IdeObject parent_instance;
+ GObject parent_instance;
IdeSubprocessSupervisor *supervisor;
GDBusConnection *connection;
IpcFlatpakService *service;
+ GMutex mutex;
GQueue get_service;
- gint state;
+ int state;
+ guint disposed : 1;
};
enum {
@@ -47,7 +49,7 @@ enum {
STATE_SHUTDOWN,
};
-G_DEFINE_FINAL_TYPE (GbpFlatpakClient, gbp_flatpak_client, IDE_TYPE_OBJECT)
+G_DEFINE_FINAL_TYPE (GbpFlatpakClient, gbp_flatpak_client, G_TYPE_OBJECT)
static void
gbp_flatpak_client_reset (GbpFlatpakClient *self)
@@ -122,10 +124,10 @@ gbp_flatpak_client_reset (GbpFlatpakClient *self)
g_set_object (&self->connection, service_connection);
- ide_object_lock (IDE_OBJECT (self));
+ g_mutex_lock (&self->mutex);
if (self->supervisor != NULL)
ide_subprocess_supervisor_set_launcher (self->supervisor, launcher);
- ide_object_unlock (IDE_OBJECT (self));
+ g_mutex_unlock (&self->mutex);
handle_error:
if (error != NULL)
@@ -152,7 +154,7 @@ gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient *self,
g_assert (IDE_IS_SUBPROCESS (subprocess));
g_assert (IDE_IS_SUBPROCESS_SUPERVISOR (supervisor));
- ide_object_lock (IDE_OBJECT (self));
+ g_mutex_lock (&self->mutex);
g_assert (self->service == NULL);
g_assert (self->connection != NULL);
@@ -189,7 +191,7 @@ gbp_flatpak_client_subprocess_spawned (GbpFlatpakClient *self,
g_list_free_full (queued, g_object_unref);
- ide_object_unlock (IDE_OBJECT (self));
+ g_mutex_unlock (&self->mutex);
IDE_EXIT;
}
@@ -205,49 +207,59 @@ gbp_flatpak_client_subprocess_exited (GbpFlatpakClient *self,
g_assert (IDE_IS_SUBPROCESS (subprocess));
g_assert (IDE_IS_SUBPROCESS_SUPERVISOR (supervisor));
- ide_object_lock (IDE_OBJECT (self));
+ g_mutex_lock (&self->mutex);
if (self->state == STATE_RUNNING)
self->state = STATE_SPAWNING;
g_clear_object (&self->connection);
g_clear_object (&self->service);
- ide_object_unlock (IDE_OBJECT (self));
+ g_mutex_unlock (&self->mutex);
- if (!ide_object_in_destruction (IDE_OBJECT (self)))
+ if (!self->disposed)
gbp_flatpak_client_reset (self);
IDE_EXIT;
}
static void
-gbp_flatpak_client_destroy (IdeObject *object)
+gbp_flatpak_client_dispose (GObject *object)
{
GbpFlatpakClient *self = (GbpFlatpakClient *)object;
g_autoptr(IdeSubprocessSupervisor) supervisor = g_steal_pointer (&self->supervisor);
+ self->disposed = TRUE;
+
if (supervisor != NULL)
ide_subprocess_supervisor_stop (supervisor);
+ g_mutex_lock (&self->mutex);
g_clear_object (&self->connection);
g_clear_object (&self->service);
+ g_mutex_unlock (&self->mutex);
- IDE_OBJECT_CLASS (gbp_flatpak_client_parent_class)->destroy (object);
+ G_OBJECT_CLASS (gbp_flatpak_client_parent_class)->dispose (object);
}
static void
-gbp_flatpak_client_parent_set (IdeObject *object,
- IdeObject *parent)
+gbp_flatpak_client_finalize (GObject *object)
+{
+ GbpFlatpakClient *self = (GbpFlatpakClient *)object;
+
+ g_mutex_clear (&self->mutex);
+
+ G_OBJECT_CLASS (gbp_flatpak_client_parent_class)->finalize (object);
+}
+
+static void
+gbp_flatpak_client_constructed (GObject *object)
{
GbpFlatpakClient *self = (GbpFlatpakClient *)object;
IDE_ENTRY;
g_assert (GBP_IS_FLATPAK_CLIENT (self));
- g_assert (!parent || IDE_IS_OBJECT (parent));
- if (parent == NULL)
- IDE_EXIT;
+ G_OBJECT_CLASS (gbp_flatpak_client_parent_class)->constructed (object);
- ide_object_lock (IDE_OBJECT (self));
self->supervisor = ide_subprocess_supervisor_new ();
g_signal_connect_object (self->supervisor,
"spawned",
@@ -259,7 +271,6 @@ gbp_flatpak_client_parent_set (IdeObject *object,
G_CALLBACK (gbp_flatpak_client_subprocess_exited),
self,
G_CONNECT_SWAPPED);
- ide_object_unlock (IDE_OBJECT (self));
gbp_flatpak_client_reset (self);
@@ -269,34 +280,34 @@ gbp_flatpak_client_parent_set (IdeObject *object,
static void
gbp_flatpak_client_class_init (GbpFlatpakClientClass *klass)
{
- IdeObjectClass *i_object_class = IDE_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- i_object_class->destroy = gbp_flatpak_client_destroy;
- i_object_class->parent_set = gbp_flatpak_client_parent_set;
+ object_class->constructed = gbp_flatpak_client_constructed;
+ object_class->dispose = gbp_flatpak_client_dispose;
+ object_class->finalize = gbp_flatpak_client_finalize;
}
static void
gbp_flatpak_client_init (GbpFlatpakClient *self)
{
+ g_mutex_init (&self->mutex);
}
GbpFlatpakClient *
-gbp_flatpak_client_from_context (IdeContext *context)
+gbp_flatpak_client_get_default (void)
{
- GbpFlatpakClient *ret;
-
- g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL);
- g_return_val_if_fail (!ide_object_in_destruction (IDE_OBJECT (context)), NULL);
+ static GbpFlatpakClient *instance;
- if (!(ret = ide_context_peek_child_typed (context, GBP_TYPE_FLATPAK_CLIENT)))
+ if (g_once_init_enter (&instance))
{
- g_autoptr(GbpFlatpakClient) client = NULL;
+ GbpFlatpakClient *client;
- client = ide_object_ensure_child_typed (IDE_OBJECT (context), GBP_TYPE_FLATPAK_CLIENT);
- ret = ide_context_peek_child_typed (context, GBP_TYPE_FLATPAK_CLIENT);
+ client = g_object_new (GBP_TYPE_FLATPAK_CLIENT, NULL);
+ gbp_flatpak_client_get_service_async (client, NULL, NULL, NULL);
+ g_once_init_leave (&instance, client);
}
- return ret;
+ return instance;
}
static void
@@ -331,10 +342,10 @@ gbp_flatpak_client_get_service (GbpFlatpakClient *self,
g_assert (GBP_IS_FLATPAK_CLIENT (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
- ide_object_lock (IDE_OBJECT (self));
+ g_mutex_lock (&self->mutex);
if (self->service != NULL)
ret = g_object_ref (self->service);
- ide_object_unlock (IDE_OBJECT (self));
+ g_mutex_unlock (&self->mutex);
if (ret != NULL)
return g_steal_pointer (&ret);
@@ -366,7 +377,7 @@ gbp_flatpak_client_get_service_async (GbpFlatpakClient *self,
g_assert (GBP_IS_FLATPAK_CLIENT (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
- ide_object_lock (IDE_OBJECT (self));
+ g_mutex_lock (&self->mutex);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, gbp_flatpak_client_get_service_async);
@@ -374,10 +385,15 @@ gbp_flatpak_client_get_service_async (GbpFlatpakClient *self,
switch (self->state)
{
case STATE_INITIAL:
- self->state = STATE_SPAWNING;
- g_queue_push_tail (&self->get_service, g_steal_pointer (&task));
- ide_subprocess_supervisor_start (self->supervisor);
- break;
+ {
+ g_autoptr(IdeSubprocessSupervisor) supervisor = g_object_ref (self->supervisor);
+
+ self->state = STATE_SPAWNING;
+ g_queue_push_tail (&self->get_service, g_steal_pointer (&task));
+ g_mutex_unlock (&self->mutex);
+ ide_subprocess_supervisor_start (supervisor);
+ return;
+ }
case STATE_SPAWNING:
g_queue_push_tail (&self->get_service, g_steal_pointer (&task));
@@ -396,10 +412,9 @@ gbp_flatpak_client_get_service_async (GbpFlatpakClient *self,
default:
g_assert_not_reached ();
- break;
}
- ide_object_unlock (IDE_OBJECT (self));
+ g_mutex_unlock (&self->mutex);
}
IpcFlatpakService *
diff --git a/src/plugins/flatpak/gbp-flatpak-client.h b/src/plugins/flatpak/gbp-flatpak-client.h
index 786df5349..5f50740e8 100644
--- a/src/plugins/flatpak/gbp-flatpak-client.h
+++ b/src/plugins/flatpak/gbp-flatpak-client.h
@@ -28,9 +28,9 @@ G_BEGIN_DECLS
#define GBP_TYPE_FLATPAK_CLIENT (gbp_flatpak_client_get_type())
-G_DECLARE_FINAL_TYPE (GbpFlatpakClient, gbp_flatpak_client, GBP, FLATPAK_CLIENT, IdeObject)
+G_DECLARE_FINAL_TYPE (GbpFlatpakClient, gbp_flatpak_client, GBP, FLATPAK_CLIENT, GObject)
-GbpFlatpakClient *gbp_flatpak_client_from_context (IdeContext *context);
+GbpFlatpakClient *gbp_flatpak_client_get_default (void);
IpcFlatpakService *gbp_flatpak_client_get_service (GbpFlatpakClient *self,
GCancellable *cancellable,
GError **error);
@@ -43,10 +43,4 @@ IpcFlatpakService *gbp_flatpak_client_get_service_finish (GbpFlatpakClient *
GError **error);
void gbp_flatpak_client_force_exit (GbpFlatpakClient *self);
-static inline GbpFlatpakClient *
-gbp_flatpak_client_ensure (IdeContext *context)
-{
- return ide_object_ensure_child_typed (IDE_OBJECT (context), GBP_TYPE_FLATPAK_CLIENT);
-}
-
G_END_DECLS
diff --git a/src/plugins/flatpak/gbp-flatpak-config-provider.c
b/src/plugins/flatpak/gbp-flatpak-config-provider.c
index 62bd3e22e..1721fe2f6 100644
--- a/src/plugins/flatpak/gbp-flatpak-config-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-config-provider.c
@@ -481,7 +481,7 @@ gbp_flatpak_config_provider_load_async (IdeConfigProvider *provider,
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
context = ide_object_get_context (IDE_OBJECT (self));
- client = gbp_flatpak_client_from_context (context);
+ client = gbp_flatpak_client_get_default ();
service = gbp_flatpak_client_get_service (client, NULL, NULL);
vcs = ide_vcs_from_context (context);
workdir = ide_vcs_get_workdir (vcs);
diff --git a/src/plugins/flatpak/gbp-flatpak-manifest.c b/src/plugins/flatpak/gbp-flatpak-manifest.c
index bd166026f..a2a1f6f9d 100644
--- a/src/plugins/flatpak/gbp-flatpak-manifest.c
+++ b/src/plugins/flatpak/gbp-flatpak-manifest.c
@@ -572,16 +572,13 @@ find_extension (GbpFlatpakManifest *self,
g_autoptr(GVariant) info = NULL;
g_autoptr(GError) error = NULL;
GbpFlatpakClient *client;
- IdeContext *context;
IDE_ENTRY;
g_assert (GBP_IS_FLATPAK_MANIFEST (self));
g_assert (runtime_id != NULL);
- context = ide_object_get_context (IDE_OBJECT (self));
-
- if ((client = gbp_flatpak_client_from_context (context)) &&
+ if ((client = gbp_flatpak_client_get_default ()) &&
(service = gbp_flatpak_client_get_service (client, NULL, &error)) &&
ipc_flatpak_service_call_get_runtime_sync (service, runtime_id, &info, NULL, &error))
{
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index 9e607f645..b9bdca77c 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -160,15 +160,15 @@ static void
gbp_flatpak_runtime_provider_load (IdeRuntimeProvider *provider,
IdeRuntimeManager *manager)
{
- g_autoptr(GbpFlatpakClient) client = NULL;
g_autoptr(IpcFlatpakService) service = NULL;
g_autoptr(IdeContext) context = NULL;
+ GbpFlatpakClient *client;
g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (provider));
g_assert (IDE_IS_RUNTIME_MANAGER (manager));
if ((context = ide_object_ref_context (IDE_OBJECT (provider))) &&
- (client = gbp_flatpak_client_ensure (context)) &&
+ (client = gbp_flatpak_client_get_default ()) &&
(service = gbp_flatpak_client_get_service (client, NULL, NULL)))
{
g_signal_connect_object (service,
@@ -346,12 +346,12 @@ gbp_flatpak_runtime_provider_bootstrap (IdeTask *task,
GCancellable *cancellable)
{
g_autoptr(IdeContext) context = NULL;
- g_autoptr(GbpFlatpakClient) client = NULL;
g_autoptr(IpcFlatpakService) service = NULL;
g_autoptr(IpcFlatpakTransfer) transfer = NULL;
g_autoptr(IdeNotification) notif = NULL;
Bootstrap *state = task_data;
g_autoptr(GString) debug_install = NULL;
+ GbpFlatpakClient *client;
IDE_ENTRY;
@@ -362,7 +362,7 @@ gbp_flatpak_runtime_provider_bootstrap (IdeTask *task,
g_assert (state->to_install->len > 0);
if (!(context = ide_object_ref_context (source_object)) ||
- !(client = gbp_flatpak_client_ensure (context)) ||
+ !(client = gbp_flatpak_client_get_default ()) ||
!(service = gbp_flatpak_client_get_service (client, NULL, NULL)))
{
ide_task_return_new_error (task,
diff --git a/src/plugins/flatpak/gbp-flatpak-sdk-stage.c b/src/plugins/flatpak/gbp-flatpak-sdk-stage.c
index 4975e94d1..79ea5d8aa 100644
--- a/src/plugins/flatpak/gbp-flatpak-sdk-stage.c
+++ b/src/plugins/flatpak/gbp-flatpak-sdk-stage.c
@@ -94,7 +94,7 @@ gbp_flatpak_sdk_stage_build_async (IdePipelineStage *stage,
ide_task_set_source_tag (task, gbp_flatpak_sdk_stage_build_async);
context = ide_object_get_context (IDE_OBJECT (pipeline));
- client = gbp_flatpak_client_from_context (context);
+ client = gbp_flatpak_client_get_default ();
if (!(service = gbp_flatpak_client_get_service (client, cancellable, &error)))
{
diff --git a/src/plugins/flatpak/gbp-flatpak-util.c b/src/plugins/flatpak/gbp-flatpak-util.c
index 2ab10aa73..9662abac1 100644
--- a/src/plugins/flatpak/gbp-flatpak-util.c
+++ b/src/plugins/flatpak/gbp-flatpak-util.c
@@ -154,7 +154,7 @@ _gbp_flatpak_get_default_arch (IdeObject *object)
if (context != NULL)
{
- g_autoptr(GbpFlatpakClient) client = gbp_flatpak_client_ensure (context);
+ GbpFlatpakClient *client = gbp_flatpak_client_get_default ();
IpcFlatpakService *service = gbp_flatpak_client_get_service (client, NULL, NULL);
if (service != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]