core: Provide a way to store per loader info in cus and an exit function

So that loaders such as the DWARF one can store there the DWARF handler
(Dwfl) that needs to stay live while tools use the core tags (struct
class, struct union, struct tag, etc) because they point to strings that
are managed by Dwfl, so we have to defer dwfl_end() to after tools are
done processing the core tags.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-07-06 15:02:09 -03:00
parent 5365c45177
commit 35845e7e41
2 changed files with 28 additions and 1 deletions

View File

@ -393,6 +393,8 @@ struct cus {
uint32_t nr_entries;
struct list_head cus;
pthread_mutex_t mutex;
void (*loader_exit)(struct cus *cus);
void *priv; // Used in dwarf_loader__exit()
};
void cus__lock(struct cus *cus)
@ -2349,7 +2351,9 @@ struct cus *cus__new(void)
struct cus *cus = malloc(sizeof(*cus));
if (cus != NULL) {
cus->nr_entries = 0;
cus->nr_entries = 0;
cus->priv = NULL;
cus->loader_exit = NULL;
INIT_LIST_HEAD(&cus->cus);
pthread_mutex_init(&cus->mutex, NULL);
}
@ -2371,11 +2375,29 @@ void cus__delete(struct cus *cus)
cu__delete(pos);
}
if (cus->loader_exit)
cus->loader_exit(cus);
cus__unlock(cus);
free(cus);
}
void cus__set_priv(struct cus *cus, void *priv)
{
cus->priv = priv;
}
void *cus__priv(struct cus *cus)
{
return cus->priv;
}
void cus__set_loader_exit(struct cus *cus, void (*loader_exit)(struct cus *cus))
{
cus->loader_exit = loader_exit;
}
void dwarves__fprintf_init(uint16_t user_cacheline_size);
int dwarves__init(uint16_t user_cacheline_size)

View File

@ -148,6 +148,11 @@ uint32_t cus__nr_entries(const struct cus *cus);
void cus__lock(struct cus *cus);
void cus__unlock(struct cus *cus);
void *cus__priv(struct cus *cus);
void cus__set_priv(struct cus *cus, void *priv);
void cus__set_loader_exit(struct cus *cus, void (*loader_exit)(struct cus *cus));
struct ptr_table {
void **entries;
uint32_t nr_entries;