+}
+
+/*
+ * Called under ust lock.
+ */
+static
+void fixup_lazy_probes(void)
+{
+ struct lttng_probe_desc *iter, *tmp;
+
+ lazy_nesting++;
+ cds_list_for_each_entry_safe(iter, tmp,
+ &lazy_probe_init, lazy_init_head) {
+ lttng_lazy_probe_register(iter);
+ iter->lazy = 0;
+ cds_list_del(&iter->lazy_init_head);
+ }
+ lazy_nesting--;
+}
+
+/*
+ * Called under ust lock.
+ */
+struct cds_list_head *lttng_get_probe_list_head(void)
+{
+ if (!lazy_nesting && !cds_list_empty(&lazy_probe_init))
+ fixup_lazy_probes();
+ return &_probe_list;
+}
+
+static
+const struct lttng_probe_desc *find_provider(const char *provider)
+{
+ struct lttng_probe_desc *iter;
+ struct cds_list_head *probe_list;
+
+ probe_list = lttng_get_probe_list_head();
+ cds_list_for_each_entry(iter, probe_list, head) {
+ if (!strcmp(iter->provider, provider))
+ return iter;
+ }
+ return NULL;
+}
+
+int lttng_probe_register(struct lttng_probe_desc *desc)
+{
+ int ret = 0;
+
+ ust_lock();
+
+ /*
+ * Check if the provider has already been registered.
+ */
+ if (find_provider(desc->provider)) {
+ ret = -EEXIST;
+ goto end;
+ }
+ cds_list_add(&desc->lazy_init_head, &lazy_probe_init);
+ desc->lazy = 1;
+ DBG("adding probe %s containing %u events to lazy registration list",
+ desc->provider, desc->nr_events);
+ /*
+ * If there is at least one active session, we need to register
+ * the probe immediately, since we cannot delay event
+ * registration because they are needed ASAP.
+ */
+ if (lttng_session_active())
+ fixup_lazy_probes();