diff --git a/ChangeLog b/ChangeLog index be3c5c23..6f1df29b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 1999-12-05 Martin Baulig + * glibtop.h (glibtop): Added `refcount' field. + * lib/init.c (glibtop_server_ref, glibtop_server_unref): New + functions to deal with refcounts. + * structures.def: New file. This is used by the language bindings code to get the definitions of some of LibGTop's structures. diff --git a/glibtop.h b/glibtop.h index 0d861d36..2a251108 100644 --- a/glibtop.h +++ b/glibtop.h @@ -44,6 +44,7 @@ typedef struct _glibtop glibtop; struct _glibtop { + int refcount; /* Reference count */ unsigned flags; unsigned method; /* Server Method */ unsigned error_method; /* Error Method */ @@ -86,6 +87,12 @@ glibtop_init_s (glibtop **server_ptr, unsigned long features, unsigned flags); +void +glibtop_server_ref (glibtop *server); + +void +glibtop_server_unref (glibtop *server); + #ifdef GLIBTOP_GUILE /* You need to link with -lgtop_guile to get this stuff here. */ diff --git a/lib/init.c b/lib/init.c index 9050598a..5864119c 100644 --- a/lib/init.c +++ b/lib/init.c @@ -154,6 +154,30 @@ _init_server (glibtop *server, const unsigned features) glibtop_free_r (server, command); } +void +glibtop_server_ref (glibtop *server) +{ + if (server == NULL) + return; + + server->refcount++; +} + +void +glibtop_server_unref (glibtop *server) +{ + if (server == NULL) + return; + + if (!server->refcount) { + glibtop_warn_r (server, "Attempted to unref server " + "which refcount == 0"); + return; + } + + server->refcount--; +} + glibtop * glibtop_init_r (glibtop **server_ptr, unsigned long features, unsigned flags) {