From b67acb7e2a7cde01321daa6116c635a565accd27 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 07:20:13 +0930 Subject: tdb2: tdb_foreach() Create an iterator over every open tdb (not internal TDBs). This is useful for re-establishing the tdb1-style active lock for CLEAR_IF_FIRST. Signed-off-by: Rusty Russell (Imported from CCAN commit 1a0c636bc38213bd0322db47529f78f2dc22ffdd) --- lib/tdb2/tdb2.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/tdb2/tdb2.h') diff --git a/lib/tdb2/tdb2.h b/lib/tdb2/tdb2.h index 65f55d41fb..0d7be789db 100644 --- a/lib/tdb2/tdb2.h +++ b/lib/tdb2/tdb2.h @@ -672,6 +672,20 @@ const char *tdb_name(const struct tdb_context *tdb); */ int tdb_fd(const struct tdb_context *tdb); +/** + * tdb_foreach - iterate through every open TDB. + * @fn: the function to call for every TDB + * @p: the pointer to hand to @fn + * + * TDB internally keeps track of all open TDBs; this function allows you to + * iterate through them. If @fn returns non-zero, traversal stops. + */ +#define tdb_foreach(fn, p) \ + tdb_foreach_(typesafe_cb_preargs(int, void *, (fn), (p), \ + struct tdb_context *), (p)) + +void tdb_foreach_(int (*fn)(struct tdb_context *, void *), void *p); + /** * struct tdb_attribute_base - common fields for all tdb attributes. */ -- cgit