diff options
author | Jeremy Allison <jra@samba.org> | 2002-01-09 01:53:19 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-01-09 01:53:19 +0000 |
commit | af85c2f06242928eacacfe301493686452807cb8 (patch) | |
tree | 300a025f6ae44ce2cb7428f58fb302f9184ba66f /source3 | |
parent | b6f4f3465f977cf9f8d2700a37abd76fab659260 (diff) | |
download | samba-af85c2f06242928eacacfe301493686452807cb8.tar.gz samba-af85c2f06242928eacacfe301493686452807cb8.tar.bz2 samba-af85c2f06242928eacacfe301493686452807cb8.zip |
Added int32 version of "atomic" update.
Jeremy.
(This used to be commit 1233b553e78b8d7580b9ea4f1bba62c78b4cd186)
Diffstat (limited to 'source3')
-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. ****************************************************************************/ |