[PATCH 03/14] tdb: Introduce tdb_chainlock_read_nonblock()

Kirill Smelkov kirr at landau.phys.spbu.ru
Sat Oct 2 07:43:42 MDT 2010


This (read+nonblock) case was missing...

But for consistency with other variants of chain locking, and also for
cases when it's ok for readers to delay actual reads to minimize latency
and use slightly outdated in-memory cache until next
chainlock_read_nonblock() succeeds.

Cc: Rusty Russell <rusty at rustcorp.com.au>
Signed-off-by: Kirill Smelkov <kirr at landau.phys.spbu.ru>
---
 lib/tdb/common/lock.c  |    7 +++++++
 lib/tdb/include/tdb.h  |    1 +
 lib/tdb/tdb.exports    |    1 +
 lib/tdb/tdb.signatures |    1 +
 4 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c
index 803feee..a7bdfee 100644
--- a/lib/tdb/common/lock.c
+++ b/lib/tdb/common/lock.c
@@ -751,6 +751,13 @@ int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key)
 	return ret;
 }
 
+int tdb_chainlock_read_nonblock(struct tdb_context *tdb, TDB_DATA key)
+{
+	int ret = tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK);
+	tdb_trace_1rec(tdb, "tdb_chainlock_read_nonblock", key);
+	return ret;
+}
+
 int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key)
 {
 	tdb_trace_1rec(tdb, "tdb_chainunlock_read", key);
diff --git a/lib/tdb/include/tdb.h b/lib/tdb/include/tdb.h
index 96fc157..6fb75c6 100644
--- a/lib/tdb/include/tdb.h
+++ b/lib/tdb/include/tdb.h
@@ -153,6 +153,7 @@ _PUBLIC_ int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
+_PUBLIC_ int tdb_chainlock_read_nonblock(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key);
 _PUBLIC_ int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key);
diff --git a/lib/tdb/tdb.exports b/lib/tdb/tdb.exports
index 73b8fd6..dd3c9c3 100644
--- a/lib/tdb/tdb.exports
+++ b/lib/tdb/tdb.exports
@@ -6,6 +6,7 @@
            tdb_chainlock_mark;
            tdb_chainlock_nonblock;
            tdb_chainlock_read;
+           tdb_chainlock_read_nonblock;
            tdb_chainlock_unmark;
            tdb_chainunlock;
            tdb_chainunlock_read;
diff --git a/lib/tdb/tdb.signatures b/lib/tdb/tdb.signatures
index 7706d18..f7a03e0 100644
--- a/lib/tdb/tdb.signatures
+++ b/lib/tdb/tdb.signatures
@@ -5,6 +5,7 @@ int tdb_append (struct tdb_context *, TDB_DATA, TDB_DATA);
 int tdb_chainlock_mark (struct tdb_context *, TDB_DATA);
 int tdb_chainlock_nonblock (struct tdb_context *, TDB_DATA);
 int tdb_chainlock_read (struct tdb_context *, TDB_DATA);
+int tdb_chainlock_read_nonblock (struct tdb_context *, TDB_DATA);
 int tdb_chainlock (struct tdb_context *, TDB_DATA);
 int tdb_chainlock_unmark (struct tdb_context *, TDB_DATA);
 int tdb_chainunlock_read (struct tdb_context *, TDB_DATA);
-- 
1.7.3.1.50.g1e633


More information about the samba-technical mailing list