From 49289f0d2e8b5b2fb0295606938c2a4007800e3b Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 18 Jul 2013 07:41:11 -0700 Subject: [PATCH] Add mdb_reader_list() Dump the active slots in the reader table. --- libraries/liblmdb/lmdb.h | 17 +++++++++++++++++ libraries/liblmdb/mdb.c | 35 +++++++++++++++++++++++++++++++++++ libraries/liblmdb/mdb_stat.1 | 9 +++++++++ libraries/liblmdb/mdb_stat.c | 14 +++++++++++--- 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h index c38c7db..af046d1 100644 --- a/libraries/liblmdb/lmdb.h +++ b/libraries/liblmdb/lmdb.h @@ -1298,6 +1298,23 @@ int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b); * @return < 0 if a < b, 0 if a == b, > 0 if a > b */ int mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b); + + /** @brief A callback function used to print a message from the library. + * + * @param[in] msg The string to be printed. + * @param[in] ctx An arbitrary context pointer for the callback. + * @return < 0 on failure, 0 on success. + */ +typedef int (MDB_msg_func)(const char *msg, void *ctx); + + /** @brief Dump the entries in the reader lock table. + * + * @param[in] env An environment handle returned by #mdb_env_create() + * @param[in] func A #MDB_msg_func function + * @param[in] ctx Anything the message function needs + * @return < 0 on failure, 0 on success. + */ +int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx); /** @} */ #ifdef __cplusplus diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index f895c0f..f86ec35 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -7916,4 +7916,39 @@ int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx) return MDB_SUCCESS; } +int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx) +{ + unsigned int i, rdrs; + MDB_reader *mr; + char buf[128]; + int first = 1; + + if (!env || !func) + return -1; + if (!env->me_txns) { + return func("No reader locks\n", ctx); + } + rdrs = env->me_numreaders; + mr = env->me_txns->mti_readers; + for (i=0; i