static void
ensure_required_types (void)
{
- g_assert (ensured_classes == NULL);
+ if (ensured_classes != NULL)
+ return;
ensured_classes = g_ptr_array_new ();
+
/* Generally in this list, you should initialize types which are used as
* properties first, then the class which has them. For example, GDBusProxy
* has a type of GDBusConnection, so we initialize GDBusConnection first.
return NULL;
}
+/* See `ensure_required_types` for rationale. Doing this in a library constructor
+ * is to ensure extra hard that it happens before there are any extra threads that
+ * could produce a deadlock. */
+static void __attribute__ ((constructor)) ensure_required_types_constructor (void)
+{
+ /* No thread safety (e.g. `g_init_once`) should be needed, as
+ * constructors run at library load, before other threads can use
+ * the library or even before other threads are even spawned. */
+ g_assert (ensured_classes == NULL);
+ ensure_required_types();
+}
+
/* ---------------------------------------------------------------------------------------------------- */
static SharedThreadData *