summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-07-29 14:32:31 +0200
committerMichael Adam <obnox@samba.org>2009-07-29 16:26:24 +0200
commit14c2bc91b9ccf85f82d56f4b0dbe8346a06bfe7e (patch)
treea61b41d65cc1cd6b49487f2768b0007fdaea2f73
parent6abcdaad28162204fb9e9cc482ee03b4d4d6fe0a (diff)
downloadsamba-14c2bc91b9ccf85f82d56f4b0dbe8346a06bfe7e.tar.gz
samba-14c2bc91b9ccf85f82d56f4b0dbe8346a06bfe7e.tar.bz2
samba-14c2bc91b9ccf85f82d56f4b0dbe8346a06bfe7e.zip
s3:dbwrap: export logic of dbwrap_change_uint32_atomic into an action function
to prepare for adding a transaction wrapper to dbwrap_change_uint32_atomic() Michael
-rw-r--r--source3/lib/dbwrap_util.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c
index fe3060c89a..118d681eb9 100644
--- a/source3/lib/dbwrap_util.c
+++ b/source3/lib/dbwrap_util.c
@@ -106,30 +106,40 @@ int dbwrap_store_uint32(struct db_context *db, const char *keystr, uint32_t v)
* return old value in *oldval.
* store *oldval + change_val to db.
*/
-NTSTATUS dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
- uint32_t *oldval, uint32_t change_val)
+
+struct dbwrap_change_uint32_atomic_context {
+ const char *keystr;
+ uint32_t *oldval;
+ uint32_t change_val;
+};
+
+static NTSTATUS dbwrap_change_uint32_atomic_action(struct db_context *db,
+ void *private_data)
{
struct db_record *rec;
uint32 val = -1;
TDB_DATA data;
NTSTATUS ret;
+ struct dbwrap_change_uint32_atomic_context *state;
- rec = db->fetch_locked(db, NULL, string_term_tdb_data(keystr));
+ state = (struct dbwrap_change_uint32_atomic_context *)private_data;
+
+ rec = db->fetch_locked(db, NULL, string_term_tdb_data(state->keystr));
if (!rec) {
return NT_STATUS_UNSUCCESSFUL;
}
if (rec->value.dptr == NULL) {
- val = *oldval;
+ val = *(state->oldval);
} else if (rec->value.dsize == sizeof(val)) {
val = IVAL(rec->value.dptr, 0);
- *oldval = val;
+ *(state->oldval) = val;
} else {
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- val += change_val;
+ val += state->change_val;
data.dsize = sizeof(val);
data.dptr = (uint8 *)&val;
@@ -141,6 +151,21 @@ done:
return ret;
}
+NTSTATUS dbwrap_change_uint32_atomic(struct db_context *db, const char *keystr,
+ uint32_t *oldval, uint32_t change_val)
+{
+ NTSTATUS ret;
+ struct dbwrap_change_uint32_atomic_context state;
+
+ state.keystr = keystr;
+ state.oldval = oldval;
+ state.change_val = change_val;
+
+ ret = dbwrap_change_uint32_atomic_action(db, &state);
+
+ return ret;
+}
+
/**
* Atomic integer change (addition):
*