From 31067e703d8961e46658d06777c6aeef4296ade9 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Wed, 12 Jan 2000 21:30:13 +0000 Subject: [PATCH] Added `_priv_module' pointer (type glibtop_backend_module). Made the 2000-01-12 Martin Baulig * include/glibtop/backend.h (glibtop_backend): Added `_priv_module' pointer (type glibtop_backend_module). Made the `info' field const since this now points to gmodule loaded memory (glibtop_backend_entry): Made the `info' field const since it points to gmodule loaded memory. * lib/close.c (glibtop_close_r): Close all currently opened backends. --- ChangeLog | 10 ++++++++++ include/glibtop/backend.h | 11 +++++++++-- lib/close.c | 28 ++++++++++++++++++++++++++++ lib/open-backend.c | 7 ++++--- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc0c5efc..06a13369 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-01-12 Martin Baulig + + * include/glibtop/backend.h (glibtop_backend): Added `_priv_module' + pointer (type glibtop_backend_module). Made the `info' field const + since this now points to gmodule loaded memory + (glibtop_backend_entry): Made the `info' field const since it points + to gmodule loaded memory. + + * lib/close.c (glibtop_close_r): Close all currently opened backends. + 2000-01-12 Martin Baulig * include/glibtop/backend.h (glibtop_backend_entry): New type. diff --git a/include/glibtop/backend.h b/include/glibtop/backend.h index f4e94326..4829ef4a 100644 --- a/include/glibtop/backend.h +++ b/include/glibtop/backend.h @@ -73,14 +73,21 @@ struct _glibtop_backend_entry char *libtool_name; char *shlib_name; - glibtop_backend_info *info; + /* This is const since you must not attempt to + * write into gmodule loaded memory. */ + const glibtop_backend_info *info; + + /* private pointer */ glibtop_backend_module *_priv; }; struct _glibtop_backend { - glibtop_backend_info *info; + const glibtop_backend_info *info; + + /* private pointers */ glibtop_backend_private *_priv; + glibtop_backend_module *_priv_module; }; long diff --git a/lib/close.c b/lib/close.c index 14a9f372..b6f84cde 100644 --- a/lib/close.c +++ b/lib/close.c @@ -27,9 +27,37 @@ #include #include +#include + /* Closes server. */ +static void +close_backend (gpointer value, gpointer user_data) +{ + glibtop_backend *backend = (glibtop_backend *) value; + glibtop *server = (glibtop *) user_data; + + /* should not happen ... */ + if (!backend || !backend->_priv_module) + return; + + if (backend->info && backend->info->close) + backend->info->close (server, backend); + + /* Note that two or more servers may open the same backend. */ + backend->_priv_module->refcount--; + if (!backend->_priv_module->refcount) { + g_module_close (backend->_priv_module->module); + g_free (backend->_priv_module); + } + + g_free (backend); +} + void glibtop_close_r (glibtop *server) { + g_slist_foreach (server->_priv->backend_list, close_backend, server); + g_slist_free (server->_priv->backend_list); + server->_priv->backend_list = NULL; } diff --git a/lib/open-backend.c b/lib/open-backend.c index fb54a0a5..17d1e901 100644 --- a/lib/open-backend.c +++ b/lib/open-backend.c @@ -35,8 +35,8 @@ int glibtop_open_backend_l (glibtop *server, const char *backend_name, u_int64_t features, const char **backend_args) { + const glibtop_backend_info *info; glibtop_backend_entry *entry; - glibtop_backend_info *info; glibtop_backend *backend; entry = glibtop_backend_by_name (backend_name); @@ -67,14 +67,15 @@ glibtop_open_backend_l (glibtop *server, const char *backend_name, return -GLIBTOP_ERROR_NO_SUCH_BACKEND; } - - entry->_priv->refcount++; } + entry->_priv->refcount++; + info = entry->info; if (!info) return -GLIBTOP_ERROR_NO_SUCH_BACKEND; backend = glibtop_calloc_r (server, 1, sizeof (glibtop_backend)); + backend->_priv_module = entry->_priv; backend->info = info; if (info->open) {