diff options
author | Thomas Graf <tgraf@suug.ch> | 2012-11-16 00:11:55 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2012-11-16 00:11:55 (GMT) |
commit | 00132b46968fff7975eb8d20a307c626dfefe2f1 (patch) | |
tree | e2d6ea3d7535358435ea136019e03c35c22c19ba /lib/cache_mngt.c | |
parent | 23c4ef67c735813fd41f66f6722b996d1ad7314a (diff) | |
download | libnl-00132b46968fff7975eb8d20a307c626dfefe2f1.zip libnl-00132b46968fff7975eb8d20a307c626dfefe2f1.tar.gz libnl-00132b46968fff7975eb8d20a307c626dfefe2f1.tar.bz2 |
cache: provide safe variant of nl_cache_mngt_require() and use it
This makes runtime removal of cache operations possible if non-safe
API is not in use by application. The non-safe API will be removed
in the next major version.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Diffstat (limited to 'lib/cache_mngt.c')
-rw-r--r-- | lib/cache_mngt.c | 32 |
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; +} + /** @} */ /** @} */ |