+BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store)
+{
+ BlueSkyStoreAsync *async;
+
+ async = g_new(BlueSkyStoreAsync, 1);
+ async->store = store;
+ async->lock = g_mutex_new();
+ async->completion_cond = g_cond_new();
+ async->status = ASYNC_NEW;
+ async->op = STORE_OP_NONE;
+ async->key = NULL;
+ async->data = NULL;
+ async->result = -1;
+ async->store_private = NULL;
+
+ return async;
+}
+
+/* Block until the given operation has completed. */
+void bluesky_store_async_wait(BlueSkyStoreAsync *async)
+{
+ g_return_if_fail(async != NULL);
+ g_mutex_lock(async->lock);
+
+ if (async->status == ASYNC_NEW) {
+ g_error("bluesky_store_async_wait on a new async object!\n");
+ g_mutex_unlock(async->lock);
+ return;
+ }
+
+ while (async->status != ASYNC_COMPLETE) {
+ g_cond_wait(async->completion_cond, async->lock);
+ }
+}
+
+/* Mark an asynchronous operation as complete. This should only be called by
+ * the store implementations. The lock must be held when calling this
+ * function. */
+void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async)
+{
+ async->status = ASYNC_COMPLETE;
+ g_cond_broadcast(async->completion_cond);
+}
+
+/* Convenience wrappers that perform a single operation synchronously. */