PERFORCE change 127223 for review

Fredrik Lindberg fli at FreeBSD.org
Fri Oct 5 04:57:00 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=127223

Change 127223 by fli at fli_genesis on 2007/10/05 11:56:26

	- Add obj_clean() that garbage collects old objects.
	- Add obj_destroy() to free objects on shutdown.
	- Don't call obj_flush() in obj_free(), obj_clean does that now.
	- Minor whitespace fixes.

Affected files ...

.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.c#3 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.h#3 edit

Differences ...

==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.c#3 (text+ko) ====

@@ -78,7 +78,7 @@
 	{ .os_sz = sizeof(struct cs_client) },
 	/* Query consumer */
 	{ .os_sz = sizeof(struct query_cons) },
-	/* Query type */ 
+	/* Query type */
 	{ .os_sz = sizeof(struct query_type) },
 	/* Outstanding UNIX pipe client query */
 	{ .os_sz = sizeof(struct csc_query) }
@@ -131,6 +131,51 @@
 }
 
 /*
+ * Destroy and free object types
+ */
+void
+obj_destroy()
+{
+	struct objs *os;
+	struct obj *o, *o2;
+	int i;
+
+	for (i = 0; i < obj_table_size; i++) {
+		os = &obj_table[i];
+		MDNS_INIT_ASSERT(os, os_magic);
+		MTX_LOCK(os, os_mtx);
+		TAILQ_FOREACH_SAFE(o, &os->os_free, o_next, o2) {
+			TAILQ_REMOVE(&os->os_free, o, o_next);
+			free(o);
+		}
+
+		MDNS_INIT_UNSET(os, os_magic);
+		MTX_UNLOCK(os, os_mtx);
+		MTX_DESTROY(os, os_mtx);
+	}
+	dprintf(DEBUG_OA, "Object allocator destroyed");
+}
+
+/*
+ * Garbage collect old objects
+ */
+void
+obj_clean()
+{
+	int i;
+	struct objs *os;
+
+	dprintf(DEBUG_OA, "Garbage collecting objects");
+	for (i = 0; i < obj_table_size; i++) {
+		os = &obj_table[i];
+		MDNS_INIT_ASSERT(os, os_magic);
+		MTX_LOCK(os, os_mtx);
+		obj_flush(i);
+		MTX_UNLOCK(os, os_mtx);
+	}
+}
+
+/*
  * Allocate an object of `type'
  */
 void *
@@ -185,6 +230,5 @@
 	MTX_LOCK(os, os_mtx);
 	TAILQ_INSERT_HEAD(&os->os_free, o, o_next);
 	dprintf(DEBUG_OA, "Released object type=%d o=%x", type, o);
-	obj_flush(type);
 	MTX_UNLOCK(os, os_mtx);
 }

==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/objalloc.h#3 (text+ko) ====

@@ -27,8 +27,8 @@
 #ifndef _OBJALLOC_H_
 #define _OBJALLOC_H_
 
-#define OBJ_PKGCHAIN	0 /* struct mdns_pkgchain {} */	
-#define OBJ_PKG			1 /* struct mdns_packet {} */ 
+#define OBJ_PKGCHAIN		0 /* struct mdns_pkgchain {} */	
+#define OBJ_PKG			1 /* struct mdns_packet {} */
 #define OBJ_PKGRES		2 /* struct mdns_pkg_res {} */
 #define OBJ_PAC			3 /* struct dbr_pac {} */
 #define OBJ_OQE			4 /* struct oq_entry {} */
@@ -39,6 +39,8 @@
 #define _OBJ_MAX		8
 
 void obj_init(void);
+void obj_destroy(void);
+void obj_clean(void);
 void * obj_alloc(int);
 void obj_free(int, void *);
 


More information about the p4-projects mailing list