summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2008-10-01 06:59:59 -0700
committerDan Nicholson <dbn.lists@gmail.com>2008-11-02 09:49:00 -0800
commit4cead4059f4971c2be63bde5b0b4ab500e493186 (patch)
tree7af1d5a7a5de1811bc924131facd5263defce36a
parent29ed87c7a77549400da3a59490d5f996ffea5da2 (diff)
Add reference count to initd type
Since we can now have an arbitrary number of nodes pointing to the same initd type, a reference count is added so that the initd is only destroyed when there are no references left.
-rw-r--r--lib/initd-types.h2
-rw-r--r--lib/initd.c13
-rw-r--r--lib/initd.h2
3 files changed, 14 insertions, 3 deletions
diff --git a/lib/initd-types.h b/lib/initd-types.h
index 2b604d9..262979d 100644
--- a/lib/initd-types.h
+++ b/lib/initd-types.h
@@ -101,6 +101,8 @@ typedef struct initd {
char *sdesc; /* Short-Description */
char *desc; /* Description */
+
+ unsigned int count; /* Reference count */
} initd_t;
/* The initd node type */
diff --git a/lib/initd.c b/lib/initd.c
index 2a2f07e..6a1d648 100644
--- a/lib/initd.c
+++ b/lib/initd.c
@@ -35,11 +35,17 @@ initd_t *initd_new(const char *name) {
ip->sdesc = ip->desc = NULL;
+ ip->count = 0;
+
return ip;
}
void initd_free(initd_t *ip)
{
+ /* Decrement the reference count and free members if last */
+ if ((--ip->count) > 0)
+ return;
+
/* free the dependencies */
dep_free(ip->rstart);
dep_free(ip->rstop);
@@ -103,16 +109,19 @@ out:
return dest;
}
-initd_node_t *initd_node_new(const initd_t *ip)
+initd_node_t *initd_node_new(initd_t *ip)
{
initd_node_t *inp = malloc(sizeof(initd_node_t));
if (!inp)
error(2, errno, "%s", __FUNCTION__);
- inp->initd = (initd_t *) ip;
+ inp->initd = ip;
inp->prev = NULL;
inp->next = NULL;
+ /* Bump the initd reference count */
+ ip->count++;
+
return inp;
}
diff --git a/lib/initd.h b/lib/initd.h
index cf25ffd..ce2c90b 100644
--- a/lib/initd.h
+++ b/lib/initd.h
@@ -21,7 +21,7 @@ extern void initd_free(initd_t *ip);
extern initd_t *initd_copy(const initd_t *source);
extern initd_t *initd_parse(const char *path);
-extern initd_node_t *initd_node_new(const initd_t *ip);
+extern initd_node_t *initd_node_new(initd_t *ip);
extern void initd_node_free(initd_node_t *inp);
extern initd_node_t *initd_node_copy(const initd_node_t *source);