+#ifdef HAVE_LIBLTTNG_UST_CTL
+struct event_notifier_counter {
+ pthread_mutex_t lock;
+ long count;
+};
+
+static struct event_notifier_counter the_event_notifier_counter;
+
+static void free_ust_error_accounting_entry(struct rcu_head *head)
+{
+ int i;
+ struct ust_error_accounting_entry *entry =
+ caa_container_of(head, typeof(*entry), rcu_head);
+
+ for (i = 0; i < entry->nr_counter_cpu_fds; i++) {
+ lttng_ust_ctl_release_object(-1, entry->cpu_counters[i]);
+ free(entry->cpu_counters[i]);
+ }
+
+ free(entry->cpu_counters);
+
+ lttng_ust_ctl_release_object(-1, entry->counter);
+ free(entry->counter);
+
+ lttng_ust_ctl_destroy_counter(entry->daemon_counter);
+
+ free(entry);
+}
+
+static
+bool ust_error_accounting_entry_get(struct ust_error_accounting_entry *entry)
+{
+ return urcu_ref_get_unless_zero(&entry->ref);
+}
+
+static
+void ust_error_accounting_entry_release(struct urcu_ref *entry_ref)
+{
+ struct ust_error_accounting_entry *entry =
+ container_of(entry_ref, typeof(*entry), ref);
+
+ rcu_read_lock();
+ cds_lfht_del(error_counter_uid_ht->ht, &entry->node.node);
+ call_rcu(&entry->rcu_head, free_ust_error_accounting_entry);
+ rcu_read_unlock();
+}
+
+
+static
+void ust_error_accounting_entry_put(struct ust_error_accounting_entry *entry)
+{
+ if (!entry) {
+ return;
+ }
+
+ urcu_ref_put(&entry->ref, ust_error_accounting_entry_release);
+}
+
+/*
+ * Put one reference to every UID entries.
+ */
+static
+void put_ref_all_ust_error_accounting_entry(void)
+{
+ struct lttng_ht_iter iter;
+ struct ust_error_accounting_entry *uid_entry;
+
+ ASSERT_LOCKED(the_event_notifier_counter.lock);
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(error_counter_uid_ht->ht, &iter.iter,
+ uid_entry, node.node) {
+ ust_error_accounting_entry_put(uid_entry);
+ }
+
+ rcu_read_unlock();
+}
+
+/*
+ * Get one reference to every UID entries.
+ */
+static
+void get_ref_all_ust_error_accounting_entry(void)
+{
+ struct lttng_ht_iter iter;
+ struct ust_error_accounting_entry *uid_entry;
+
+ ASSERT_LOCKED(the_event_notifier_counter.lock);
+
+ rcu_read_lock();
+ cds_lfht_for_each_entry(error_counter_uid_ht->ht, &iter.iter,
+ uid_entry, node.node) {
+ ust_error_accounting_entry_get(uid_entry);
+ }
+
+ rcu_read_unlock();
+}
+
+#endif /* HAVE_LIBLTTNG_UST_CTL */
+
+static