+/* Add the given operation to the barrier. The barrier will not complete until
+ * all operations added to it have completed. */
+void bluesky_store_add_barrier(BlueSkyStoreAsync *barrier,
+ BlueSkyStoreAsync *async)
+{
+ g_return_if_fail(barrier->op == STORE_OP_BARRIER);
+
+ g_mutex_lock(barrier->lock);
+ barrier->store_private
+ = GINT_TO_POINTER(GPOINTER_TO_INT(barrier->store_private) + 1);
+ g_mutex_unlock(barrier->lock);
+
+ g_mutex_lock(async->lock);
+ if (async->barrier == NULL) {
+ async->barrier = barrier;
+ } else {
+ g_warning("Adding async to more than one barrier!\n");
+ bluesky_store_async_add_notifier(async, op_complete, barrier);
+ }
+ g_mutex_unlock(async->lock);
+}
+
+static void notifier_task(gpointer n, gpointer s)
+{
+ struct BlueSkyNotifierList *notifier = (struct BlueSkyNotifierList *)n;
+
+ notifier->func(notifier->async, notifier->user_data);
+ if (g_atomic_int_dec_and_test(¬ifier->async->notifier_count)) {
+ g_mutex_lock(notifier->async->lock);
+ if (notifier->async->barrier != NULL)
+ op_complete(notifier->async, notifier->async->barrier);
+ g_cond_broadcast(notifier->async->completion_cond);
+ g_mutex_unlock(notifier->async->lock);
+ }
+ bluesky_store_async_unref(notifier->async);
+ g_free(notifier);
+}
+