Added int32 version of "atomic" update.
authorJeremy Allison <jra@samba.org>
Wed, 9 Jan 2002 01:53:19 +0000 (01:53 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 9 Jan 2002 01:53:19 +0000 (01:53 +0000)
Jeremy.
(This used to be commit 1233b553e78b8d7580b9ea4f1bba62c78b4cd186)

source3/tdb/tdbutil.c

index 34c0967b720a6008c9ecf7acb7d3c242ab13247a..ac3c5336f12f3d2ed53a556ee9527a25e9fdfaab 100644 (file)
@@ -205,6 +205,7 @@ TDB_DATA tdb_fetch_by_string(TDB_CONTEXT *tdb, char *keystr)
 
 /****************************************************************************
  Atomic integer change. Returns old value. To create, set initial value in *oldval. 
+ Deprecated. Use int32 version. JRA.
 ****************************************************************************/
 
 int tdb_change_int_atomic(TDB_CONTEXT *tdb, char *keystr, int *oldval, int change_val)
@@ -237,6 +238,40 @@ int tdb_change_int_atomic(TDB_CONTEXT *tdb, char *keystr, int *oldval, int chang
        return ret;
 }
 
+/****************************************************************************
+ Atomic integer change. Returns old value. To create, set initial value in *oldval. 
+****************************************************************************/
+
+int32 tdb_change_int32_atomic(TDB_CONTEXT *tdb, char *keystr, int32 *oldval, int32 change_val)
+{
+       int32 val;
+       int32 ret = -1;
+
+       if (tdb_lock_bystring(tdb, keystr) == -1)
+               return -1;
+
+       if ((val = tdb_fetch_int32(tdb, keystr)) == -1) {
+               if (tdb_error(tdb) != TDB_ERR_NOEXIST)
+                       goto err_out;
+
+               val = *oldval;
+
+       } else {
+               *oldval = val;
+               val += change_val;
+       }
+               
+       if (tdb_store_int32(tdb, keystr, val) == -1)
+               goto err_out;
+
+       ret = 0;
+
+  err_out:
+
+       tdb_unlock_bystring(tdb, keystr);
+       return ret;
+}
+
 /****************************************************************************
  Useful pair of routines for packing/unpacking data consisting of
  integers and strings.