- if (g_atomic_int_dec_and_test(&string->refcount)) {
- /* There are no other shared copies, so return this one. */
- g_atomic_int_inc(&string->refcount);
- return string;
- } else {
- return bluesky_string_new(g_memdup(string->data, string->len),
- string->len);
- }
+void bluesky_store_async_submit(BlueSkyStoreAsync *async)
+{
+ BlueSkyStore *store = async->store;
+
+ store->impl->submit(store->handle, async);
+}
+
+/* Convenience wrappers that perform a single operation synchronously. */
+BlueSkyRCStr *bluesky_store_get(BlueSkyStore *store, const gchar *key)
+{
+ BlueSkyStoreAsync *async = bluesky_store_async_new(store);
+ async->op = STORE_OP_GET;
+ async->key = g_strdup(key);
+ bluesky_store_async_submit(async);
+
+ bluesky_store_async_wait(async);
+
+ BlueSkyRCStr *data = async->data;
+ bluesky_string_ref(data);
+ bluesky_store_async_unref(async);
+ return data;
+}
+
+void bluesky_store_put(BlueSkyStore *store,
+ const gchar *key, BlueSkyRCStr *val)
+{
+ BlueSkyStoreAsync *async = bluesky_store_async_new(store);
+ async->op = STORE_OP_PUT;
+ async->key = g_strdup(key);
+ bluesky_string_ref(val);
+ async->data = val;
+ bluesky_store_async_submit(async);
+
+ bluesky_store_async_wait(async);
+ bluesky_store_async_unref(async);