2013-02-25 23:36:09 +00:00
|
|
|
/*
|
|
|
|
* cache.c
|
|
|
|
* package object cache
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 pkgconf authors (see AUTHORS).
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
2017-09-18 04:38:25 +00:00
|
|
|
#include <libpkgconf/stdinc.h>
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2013-02-25 23:36:09 +00:00
|
|
|
|
|
|
|
/*
|
2016-12-11 01:40:51 +00:00
|
|
|
* !doc
|
2013-02-25 23:36:09 +00:00
|
|
|
*
|
2016-12-11 01:40:51 +00:00
|
|
|
* libpkgconf `cache` module
|
|
|
|
* =========================
|
|
|
|
*
|
|
|
|
* The libpkgconf `cache` module manages a package/module object cache, allowing it to
|
|
|
|
* avoid loading duplicate copies of a package/module.
|
|
|
|
*
|
|
|
|
* A cache is tied to a specific pkgconf client object, so package objects should not
|
|
|
|
* be shared across threads.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_cache_lookup(const pkgconf_client_t *client, const char *id)
|
|
|
|
*
|
|
|
|
* Looks up a package in the cache given an `id` atom,
|
|
|
|
* such as ``gtk+-3.0`` and returns the already loaded version
|
|
|
|
* if present.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client object to access.
|
|
|
|
* :param char* id: The package atom to look up in the client object's cache.
|
|
|
|
* :return: A package object if present, else ``NULL``.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
2013-02-25 23:36:09 +00:00
|
|
|
*/
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *
|
2017-12-05 23:32:00 +00:00
|
|
|
pkgconf_cache_lookup(pkgconf_client_t *client, const char *id)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node;
|
2013-02-25 23:36:09 +00:00
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(client->pkg_cache.head, node)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = node->data;
|
2013-03-01 16:14:20 +00:00
|
|
|
|
2013-02-25 23:36:09 +00:00
|
|
|
if (!strcmp(pkg->id, id))
|
2017-02-05 02:01:41 +00:00
|
|
|
{
|
|
|
|
PKGCONF_TRACE(client, "found: %s @%p", id, pkg);
|
2016-12-02 06:29:33 +00:00
|
|
|
return pkgconf_pkg_ref(client, pkg);
|
2017-02-05 02:01:41 +00:00
|
|
|
}
|
2013-02-25 23:36:09 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 02:01:41 +00:00
|
|
|
PKGCONF_TRACE(client, "miss: %s", id);
|
2013-02-25 23:36:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-12-11 01:40:51 +00:00
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
*
|
2016-12-11 01:40:51 +00:00
|
|
|
* Adds an entry for the package to the package cache.
|
|
|
|
* The cache entry must be removed if the package is freed.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client object to modify.
|
|
|
|
* :param pkgconf_pkg_t* pkg: The package object to add to the client object's cache.
|
|
|
|
* :return: nothing
|
2013-02-25 23:36:09 +00:00
|
|
|
*/
|
|
|
|
void
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2013-03-15 21:50:30 +00:00
|
|
|
if (pkg == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_ref(client, pkg);
|
|
|
|
pkgconf_node_insert(&pkg->cache_iter, pkg, &client->pkg_cache);
|
2017-02-05 02:01:41 +00:00
|
|
|
|
|
|
|
PKGCONF_TRACE(client, "added @%p to cache", pkg);
|
2017-09-13 19:41:00 +00:00
|
|
|
|
|
|
|
/* mark package as cached */
|
|
|
|
pkg->flags |= PKGCONF_PKG_PROPF_CACHED;
|
2013-02-25 23:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-12-11 01:40:51 +00:00
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
*
|
2016-12-11 01:40:51 +00:00
|
|
|
* Deletes a package from the client object's package cache.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client object to modify.
|
|
|
|
* :param pkgconf_pkg_t* pkg: The package object to remove from the client object's cache.
|
|
|
|
* :return: nothing
|
2013-02-25 23:36:09 +00:00
|
|
|
*/
|
|
|
|
void
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2013-02-25 23:36:09 +00:00
|
|
|
{
|
2013-03-15 21:50:30 +00:00
|
|
|
if (pkg == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-09-13 19:41:00 +00:00
|
|
|
if (!(pkg->flags & PKGCONF_PKG_PROPF_CACHED))
|
|
|
|
return;
|
|
|
|
|
2017-02-05 02:01:41 +00:00
|
|
|
PKGCONF_TRACE(client, "removed @%p from cache", pkg);
|
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_node_delete(&pkg->cache_iter, &client->pkg_cache);
|
2013-02-25 23:36:09 +00:00
|
|
|
}
|
2013-02-26 05:29:57 +00:00
|
|
|
|
2016-12-11 01:40:51 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_cache_free(pkgconf_client_t *client)
|
|
|
|
*
|
|
|
|
* Releases all resources related to a client object's package cache.
|
|
|
|
* This function should only be called to clear a client object's package cache,
|
|
|
|
* as it may release any package in the cache.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client object to modify.
|
|
|
|
*/
|
2013-02-26 05:29:57 +00:00
|
|
|
void
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_cache_free(pkgconf_client_t *client)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *iter, *iter2;
|
2013-02-26 05:29:57 +00:00
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(client->pkg_cache.head, iter2, iter)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = iter->data;
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_free(client, pkg);
|
2013-02-26 05:29:57 +00:00
|
|
|
}
|
2016-12-02 06:29:33 +00:00
|
|
|
|
|
|
|
memset(&client->pkg_cache, 0, sizeof client->pkg_cache);
|
2017-02-05 02:01:41 +00:00
|
|
|
|
|
|
|
PKGCONF_TRACE(client, "cleared package cache");
|
2013-02-26 05:29:57 +00:00
|
|
|
}
|