diff options
-rw-r--r-- | source3/tdb/tdbutil.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c index 34c0967b72..ac3c5336f1 100644 --- a/source3/tdb/tdbutil.c +++ b/source3/tdb/tdbutil.c @@ -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) @@ -238,6 +239,40 @@ int tdb_change_int_atomic(TDB_CONTEXT *tdb, char *keystr, int *oldval, int chang } /**************************************************************************** + 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. ****************************************************************************/ |