+ return BRIDGE_PROCESSOR_INVALID;
+ }
+}
+
+static gboolean
+bridge_processor_started ()
+{
+ return bridge_processor.reset_data != NULL;
+}
+
+// Initialize a single bridge processor
+static void
+init_bridge_processor (SgenBridgeProcessor *processor, BridgeProcessorSelection selection)
+{
+ memset (processor, 0, sizeof (SgenBridgeProcessor));
+
+ switch (selection) {
+ case BRIDGE_PROCESSOR_OLD:
+ sgen_old_bridge_init (processor);
+ break;
+ case BRIDGE_PROCESSOR_NEW:
+ sgen_new_bridge_init (processor);
+ break;
+ case BRIDGE_PROCESSOR_TARJAN:
+ sgen_tarjan_bridge_init (processor);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+/*
+ * Initializing the sgen bridge consists of setting the bridge callbacks,
+ * and initializing the bridge processor. Init should follow these rules:
+ *
+ * - Init happens only after sgen is initialized (because we don't
+ * know which bridge processor to initialize until then, and also
+ * to allow bridge processor init to interact with sgen if it wants)
+ *
+ * - Init happens only after mono_gc_register_bridge_callbacks is called
+ *
+ * - Init should not happen concurrently with a GC (because a GC will
+ * call sgen_need_bridge_processing at various times)
+ *
+ * - Initializing the bridge processor should happen only once
+ *
+ * We call sgen_init_bridge when the callbacks are set, and also when sgen
+ * is done initing. Actual initialization then only occurs if it is ready.
+ */
+void
+sgen_init_bridge ()
+{
+ if (sgen_gc_initialized ()) {
+ // This lock is not initialized until the GC is
+ sgen_gc_lock ();
+
+ bridge_callbacks = pending_bridge_callbacks;
+
+ // If a bridge was registered but there is no bridge processor yet
+ if (bridge_callbacks.cross_references && !bridge_processor_started ()) {
+ init_bridge_processor (&bridge_processor, bridge_processor_selection);
+
+ if (bridge_processor.set_config)
+ bridge_processor.set_config (&bridge_processor_config);
+
+ // Config is no longer needed so free its memory
+ free (bridge_processor_config.dump_prefix);
+ bridge_processor_config.dump_prefix = NULL;
+ }
+
+ sgen_gc_unlock ();