Added `_priv_module' pointer (type glibtop_backend_module). Made the

2000-01-12  Martin Baulig  <martin@home-of-linux.org>

	* 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.
This commit is contained in:
Martin Baulig
2000-01-12 21:30:13 +00:00
committed by Martin Baulig
parent 12e32ffc24
commit 31067e703d
4 changed files with 51 additions and 5 deletions

View File

@@ -1,3 +1,13 @@
2000-01-12 Martin Baulig <martin@home-of-linux.org>
* 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 <martin@home-of-linux.org> 2000-01-12 Martin Baulig <martin@home-of-linux.org>
* include/glibtop/backend.h (glibtop_backend_entry): New type. * include/glibtop/backend.h (glibtop_backend_entry): New type.

View File

@@ -73,14 +73,21 @@ struct _glibtop_backend_entry
char *libtool_name; char *libtool_name;
char *shlib_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; glibtop_backend_module *_priv;
}; };
struct _glibtop_backend struct _glibtop_backend
{ {
glibtop_backend_info *info; const glibtop_backend_info *info;
/* private pointers */
glibtop_backend_private *_priv; glibtop_backend_private *_priv;
glibtop_backend_module *_priv_module;
}; };
long long

View File

@@ -27,9 +27,37 @@
#include <glibtop/open.h> #include <glibtop/open.h>
#include <glibtop/close.h> #include <glibtop/close.h>
#include <glibtop/backend.h>
/* Closes server. */ /* 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 void
glibtop_close_r (glibtop *server) 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;
} }

View File

@@ -35,8 +35,8 @@ int
glibtop_open_backend_l (glibtop *server, const char *backend_name, glibtop_open_backend_l (glibtop *server, const char *backend_name,
u_int64_t features, const char **backend_args) u_int64_t features, const char **backend_args)
{ {
const glibtop_backend_info *info;
glibtop_backend_entry *entry; glibtop_backend_entry *entry;
glibtop_backend_info *info;
glibtop_backend *backend; glibtop_backend *backend;
entry = glibtop_backend_by_name (backend_name); 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; return -GLIBTOP_ERROR_NO_SUCH_BACKEND;
} }
entry->_priv->refcount++;
} }
entry->_priv->refcount++;
info = entry->info; info = entry->info;
if (!info) return -GLIBTOP_ERROR_NO_SUCH_BACKEND; if (!info) return -GLIBTOP_ERROR_NO_SUCH_BACKEND;
backend = glibtop_calloc_r (server, 1, sizeof (glibtop_backend)); backend = glibtop_calloc_r (server, 1, sizeof (glibtop_backend));
backend->_priv_module = entry->_priv;
backend->info = info; backend->info = info;
if (info->open) { if (info->open) {