author | Alberto Bertogli
<albertito@gmail.com> 2007-04-29 07:19:55 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-04-29 07:19:55 UTC |
parent | 0258571a717117af2b0a348e6627b249c7275ec0 |
bindings/d/nmdb.d | +38 | -0 |
bindings/d/nmdb_ll.d | +5 | -0 |
diff --git a/bindings/d/nmdb.d b/bindings/d/nmdb.d index 94c6dfe..e31da75 100644 --- a/bindings/d/nmdb.d +++ b/bindings/d/nmdb.d @@ -116,6 +116,28 @@ class DB return res; } + private int do_cas(char[] key, char[] oldval, char[] newval, + int mode) + { + ubyte* k = cast(ubyte *) key.ptr; + ubyte* ov = cast(ubyte *) oldval.ptr; + ubyte* nv = cast(ubyte *) newval.ptr; + int res = 0; + + if (mode == MODE_NORMAL || mode == MODE_SYNC) { + res = nmdb_cas(db, k, key.length, + ov, oldval.length, + nv, newval.length); + } else if (mode == MODE_CACHE) { + res = nmdb_cache_cas(db, k, key.length, + ov, oldval.length, + nv, newval.length); + } else { + throw new Exception("Invalid mode"); + } + return res; + } + char[] get(char[] key) { @@ -175,6 +197,22 @@ class DB } + int cas(char[] key, char[] oldval, char[] newval) + { + return do_cas(key, oldval, newval, mode); + } + + int cas_normal(char[] key, char[] oldval, char[] newval) + { + return do_cas(key, oldval, newval, MODE_NORMAL); + } + + int cache_cas(char[] key, char[] oldval, char[] newval) + { + return do_cas(key, oldval, newval, MODE_CACHE); + } + + char[] opIndex(char[] key) { return get(key); diff --git a/bindings/d/nmdb_ll.d b/bindings/d/nmdb_ll.d index 558f031..39524b1 100644 --- a/bindings/d/nmdb_ll.d +++ b/bindings/d/nmdb_ll.d @@ -56,3 +56,8 @@ extern (C) int nmdb_del(nmdb_t *db, ubyte *key, size_t ksize); extern (C) int nmdb_del_sync(nmdb_t *db, ubyte *key, size_t ksize); extern (C) int nmdb_cache_del(nmdb_t *db, ubyte *key, size_t ksize); +extern (C) int nmdb_cas(nmdb_t *db, ubyte *key, size_t ksize, + ubyte *oldval, size_t ovsize, ubyte *newval, size_t nvsize); +extern (C) int nmdb_cache_cas(nmdb_t *db, ubyte *key, size_t ksize, + ubyte *oldval, size_t ovsize, ubyte *newval, size_t nvsize); +