summaryrefslogtreecommitdiff
path: root/lib/cache_mngt.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cache_mngt.c')
-rw-r--r--lib/cache_mngt.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/cache_mngt.c b/lib/cache_mngt.c
index 914ab9b..fbb702f 100644
--- a/lib/cache_mngt.c
+++ b/lib/cache_mngt.c
@@ -390,14 +390,15 @@ struct nl_cache *__nl_cache_mngt_require(const char *name)
}
/**
- * Demand the use of a global cache
- * @arg name name of the required object type
+ * Return cache previously provided via nl_cache_mngt_provide()
+ * @arg name Name of cache to lookup
*
- * Trys to find a cache of the specified type for global
- * use.
+ * @attention This function is not safe, it does not increment the reference
+ * counter. Please use nl_cache_mngt_require_safe().
+ *
+ * @see nl_cache_mngt_require_safe()
*
- * @return A cache provided by another subsystem of the
- * specified type marked to be available.
+ * @return Pointer to cache or NULL if none registered
*/
struct nl_cache *nl_cache_mngt_require(const char *name)
{
@@ -412,6 +413,25 @@ struct nl_cache *nl_cache_mngt_require(const char *name)
return cache;
}
+/**
+ * Return cache previously provided via nl_cache_mngt_provide()
+ * @arg name Name of cache to lookup
+ *
+ * @note The reference counter of the returned cache is incremented
+ * and must be decremented after use with nl_cache_put().
+ *
+ * @return Pointer to cache or NULL if none registered
+ */
+struct nl_cache *nl_cache_mngt_require_safe(const char *name)
+{
+ struct nl_cache *cache;
+
+ if ((cache = nl_cache_mngt_require(name)))
+ nl_cache_get(cache);
+
+ return cache;
+}
+
/** @} */
/** @} */