Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Jun 2007 12:37:46 GMT
From:      Fredrik Lindberg <fli@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 120776 for review
Message-ID:  <200706021237.l52Cbk9c020784@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=120776

Change 120776 by fli@fli_genesis on 2007/06/02 12:36:56

	- Debugging and style fixes.
	- Fix header protection defines in stack_buf.h 

Affected files ...

.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_buf.c#5 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/stack_buf.h#4 edit

Differences ...

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

@@ -24,12 +24,13 @@
  *
  */
 
+#include <assert.h>
 #include <stdlib.h>
+#include <string.h>
 #include <strings.h>
-#include <string.h>
-#include <assert.h>
 
 #include "stack_buf.h"
+#include "debug.h"
 
 struct mdns_bufpool * mdns_bufpool_init(size_t, int,
     bp_lock, bp_unlock, void *arg);
@@ -54,6 +55,7 @@
 	bp->bp_unlock = unlock;
 	bp->bp_lockarg = arg;
 	TAILQ_INIT(&bp->bp_list);
+	MDNS_INIT_SET(bp, bp_magic);
 	return (bp);	
 }
 
@@ -63,6 +65,7 @@
 	struct mdns_buf *buf;
 	int ret;
 
+	MDNS_INIT_ASSERT(bp, bp_magic);
 	MDNS_BP_LOCK(bp);
 
 	while (!TAILQ_EMPTY(&bp->bp_list)) {
@@ -75,8 +78,10 @@
 	ret = TAILQ_EMPTY(&bp->bp_list);
 	MDNS_BP_UNLOCK(bp);
 
-	if (ret == 1)
+	if (ret == 1) {
+		MDNS_INIT_UNSET(bp, bp_magic);
 		free(bp);
+	}
 	return (ret);
 }
 
@@ -84,6 +89,7 @@
 mdns_bufpool_setsize(struct mdns_bufpool *bp, size_t len)
 {
 
+	MDNS_INIT_ASSERT(bp, bp_magic);
 	MDNS_BP_LOCK(bp);
 	bp->bp_defsz = len;
 	MDNS_BP_UNLOCK(bp);
@@ -94,6 +100,7 @@
 {
 	size_t len;
 
+	MDNS_INIT_ASSERT(bp, bp_magic);
 	MDNS_BP_LOCK(bp);
 	len = bp->bp_defsz;
 	MDNS_BP_UNLOCK(bp);
@@ -107,6 +114,8 @@
 {
 	struct mdns_buf *buf;
 
+	MDNS_INIT_ASSERT(bp, bp_magic);
+
 	if (!locked)
 		MDNS_BP_LOCK(bp);
 
@@ -144,6 +153,7 @@
 		TAILQ_INIT(&bh->bh_list);
 	TAILQ_INSERT_TAIL(&bh->bh_list, buf, b_list);
 	bh->bh_size++;
+	MDNS_INIT_SET(buf, b_magic);
 
 	if (!locked)
 		MDNS_BP_UNLOCK(bp);
@@ -156,9 +166,12 @@
 {
 	int i;
 
+	MDNS_INIT_ASSERT(bp, bp_magic);
+	MDNS_INIT_ASSERT(buf, b_magic);
 	if (!locked)
 		MDNS_BP_LOCK(bp);
 
+	MDNS_INIT_UNSET(buf, b_magic);
 	TAILQ_REMOVE(&bh->bh_list, buf, b_list);
 	bh->bh_size--;
 	if (!(buf->b_flags & MDNS_BUF_TEMP)) {
@@ -193,6 +206,7 @@
 {
 	char *p;
 
+	MDNS_INIT_ASSERT(buf, b_magic);
 	if (len == 0)
 		len = buf->b_sz * 2;
 	else if (len < buf->b_len)
@@ -218,6 +232,9 @@
 	size_t len;
 	struct mdns_bufhead bh2;
 
+	MDNS_INIT_ASSERT(bp, bp_magic);
+	MDNS_INIT_ASSERT(buf, b_magic);
+
 	if (MDNS_BUFHSZ(bh) <= 1)
 		return (TAILQ_FIRST(&bh->bh_list));
 

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

@@ -24,16 +24,19 @@
  *
  */
 
-#ifndef _CORE_BUF_H_
-#define _CORE_BUF_H_
+#ifndef _STACK_BUF_H_
+#define _STACK_BUF_H_
 
 #include <stdint.h>
 #include <sys/queue.h>
 
+#include "debug.h"
+
 /*
  * Buffer segment
  */
 struct mdns_buf {
+	MAGIC(b_magic);
 	TAILQ_ENTRY(mdns_buf) b_list;
 	char *b_buf; /* raw byte buffer */
 	size_t b_sz; /* buffer size */
@@ -42,6 +45,9 @@
 #define MDNS_BUF_TEMP 0x01 /* do not put back on free list after use */
 };
 
+/*
+ * Handy buffer manipulation macros
+ */
 #define MDNS_BUF(b) (b)->b_buf
 #define MDNS_BUFSZ(b) (b)->b_sz
 #define MDNS_BUFLEN(b) (b)->b_len
@@ -64,7 +70,7 @@
  * Buffer pool
  */
 struct mdns_bufpool {
-	uint32_t bp_magic;
+	MAGIC(bp_magic);
 	TAILQ_HEAD(, mdns_buf) bp_list; /* free list */
 	size_t bp_defsz; /* default segment size */
 	int bp_lim; /* max number of segments */
@@ -83,6 +89,9 @@
 	size_t bh_size; /* number of buffer segments in list */
 };
 
+/*
+ * Handy buffer head manipulation macros
+ */
 #define MDNS_BUFHEAD(bh) (bh)->bh_list
 #define MDNS_BUFH(bh) TAILQ_FIRST(&(bh)->bh_list)
 #define MDNS_BUFHSZ(bh) (bh)->bh_size
@@ -97,5 +106,5 @@
 void mdns_bufpool_setsize(struct mdns_bufpool *, size_t);
 size_t mdns_bufpool_getsize(struct mdns_bufpool *);
 
-#endif /* _CORE_BUF_H_ */
+#endif /* _STACK_BUF_H_ */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706021237.l52Cbk9c020784>