diff options
author | Andrew Bartlett <abartlet@samba.org> | 2002-04-13 03:23:08 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2002-04-13 03:23:08 +0000 |
commit | a4594d9efeca1f67dea57be8323fb4bd986318ce (patch) | |
tree | 24c5c3b5b3f392be6aa10dc9d69a23fd0ca15758 | |
parent | a9895fcb30cdcb572cd254b0d370d79f95c7214d (diff) | |
download | samba-a4594d9efeca1f67dea57be8323fb4bd986318ce.tar.gz samba-a4594d9efeca1f67dea57be8323fb4bd986318ce.tar.xz samba-a4594d9efeca1f67dea57be8323fb4bd986318ce.zip |
Make our atomic increment code actually do this during its first/second run.
The previous code would return the same value for both the initial and second
call, only incrementing on later calls.
Andrew Bartlett
-rw-r--r-- | source/tdb/tdbutil.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/source/tdb/tdbutil.c b/source/tdb/tdbutil.c index 3e16a030474..bc39082f63e 100644 --- a/source/tdb/tdbutil.c +++ b/source/tdb/tdbutil.c @@ -219,15 +219,22 @@ int32 tdb_change_int32_atomic(TDB_CONTEXT *tdb, char *keystr, int32 *oldval, int return -1; if ((val = tdb_fetch_int32(tdb, keystr)) == -1) { - if (tdb_error(tdb) != TDB_ERR_NOEXIST) + /* The lookup failed */ + if (tdb_error(tdb) != TDB_ERR_NOEXIST) { + /* but not becouse it didn't exist */ goto err_out; - + } + + /* Start with 'old' value */ val = *oldval; } else { + /* It worked, set return value (oldval) to tdb data */ *oldval = val; - val += change_val; } + + /* Increment value for storage and return next time */ + val += change_val; if (tdb_store_int32(tdb, keystr, val) == -1) goto err_out; @@ -253,15 +260,23 @@ BOOL tdb_change_uint32_atomic(TDB_CONTEXT *tdb, char *keystr, uint32 *oldval, ui return False; if (!tdb_fetch_uint32(tdb, keystr, &val)) { - if (tdb_error(tdb) != TDB_ERR_NOEXIST) + /* It failed */ + if (tdb_error(tdb) != TDB_ERR_NOEXIST) { + /* and not becouse it didn't exist */ goto err_out; + } + /* Start with 'old' value */ val = *oldval; } else { + /* it worked, set return value (oldval) to tdb data */ *oldval = val; - val += change_val; + } + + /* get a new value to store */ + val += change_val; if (!tdb_store_uint32(tdb, keystr, val)) goto err_out; |