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 | 2248a889099b3b9452b74eeaa7350d4e0ea82d6a (patch) | |
tree | 71b663672300ec26344ec527f959bf94759e5638 /source3/tdb/tdbutil.c | |
parent | 5c2dfd959c0facc299bca62356d1221bcea653bf (diff) | |
download | samba-2248a889099b3b9452b74eeaa7350d4e0ea82d6a.tar.gz samba-2248a889099b3b9452b74eeaa7350d4e0ea82d6a.tar.bz2 samba-2248a889099b3b9452b74eeaa7350d4e0ea82d6a.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
(This used to be commit a4594d9efeca1f67dea57be8323fb4bd986318ce)
Diffstat (limited to 'source3/tdb/tdbutil.c')
-rw-r--r-- | source3/tdb/tdbutil.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c index 3e16a03047..bc39082f63 100644 --- a/source3/tdb/tdbutil.c +++ b/source3/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; |