Skip to content

Commit

Permalink
tdb-compat: Add tdb_chainlock_nonblock
Browse files Browse the repository at this point in the history
  • Loading branch information
vlendec committed Apr 17, 2012
1 parent 4460ba5 commit 6235b76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/tdb_compat/tdb_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb)
return ecode;
}

enum TDB_ERROR tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
{
union tdb_attribute locking, orig;
enum TDB_ERROR ecode;

orig.base.attr = TDB_ATTRIBUTE_FLOCK;
ecode = tdb_get_attribute(tdb, &orig);
if (ecode != TDB_SUCCESS)
return ecode;

/* Replace locking function with our own. */
locking = orig;
locking.flock.data = &orig;
locking.flock.lock = lock_nonblock;

ecode = tdb_set_attribute(tdb, &locking);
if (ecode != TDB_SUCCESS)
return ecode;

ecode = tdb_chainlock(tdb, key);
tdb_unset_attribute(tdb, TDB_ATTRIBUTE_FLOCK);
return ecode;
}

/* For TDB1 tdbs, read traverse vs normal matters: write traverse
locks the entire thing! */
int64_t tdb_traverse_read_(struct tdb_context *tdb,
Expand Down
2 changes: 2 additions & 0 deletions lib/tdb_compat/tdb_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ int tdb_reopen_all(int parent_longlived);

/* tdb2 does nonblocking functions via attibutes. */
enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb);
enum TDB_ERROR tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);


/* Convenient (typesafe) wrapper for tdb open with logging */
#define tdb_open_compat(name, hsize, tdb_fl, open_fl, mode, log_fn, log_data) \
Expand Down

0 comments on commit 6235b76

Please sign in to comment.