PERFORCE change 139471 for review
Christian S.J. Peron
csjp at FreeBSD.org
Sun Apr 6 20:21:17 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=139471
Change 139471 by csjp at ibm01 on 2008/04/06 20:20:45
Change the structure of the macros so they are safe to use within
loops, if constructs et al.
Affected files ...
.. //depot/projects/trustedbsd/netauditd/reader.c#3 edit
Differences ...
==== //depot/projects/trustedbsd/netauditd/reader.c#3 (text+ko) ====
@@ -44,21 +44,26 @@
#include "reader.h"
#include "writer.h"
-#define SRC_BUFFER_INIT(x) x = malloc(sizeof(struct au_src_buffer)); \
- assert (x != NULL); \
- bzero(x, sizeof(struct au_src_buffer));
+#define SRC_BUFFER_INIT(x) do { \
+ x = calloc(1, sizeof(struct au_src_buffer)); \
+ assert(x != NULL); \
+} while (0)
-#define WRITER_SIGNAL(x) (void) pthread_mutex_lock(&ready_lock); \
- records_waiting += x; \
- x = 0; \
- (void) pthread_cond_signal(&ready_cond); \
- (void) pthread_mutex_unlock(&ready_lock)
+#define WRITER_SIGNAL(x) do { \
+ (void) pthread_mutex_lock(&ready_lock); \
+ records_waiting += x; \
+ x = 0; \
+ (void) pthread_cond_signal(&ready_cond); \
+ (void) pthread_mutex_unlock(&ready_lock); \
+} while (0)
-#define ROTATE assert(ac->ac_q.qp_free != NULL); \
- ac->ac_q.qp_hold = ac->ac_q.qp_store; \
- ac->ac_q.qp_store = ac->ac_q.qp_free; \
- ac->ac_q.qp_free = NULL; \
- ac->ac_q.qp_store_len = 0
+#define ROTATE() do { \
+ assert(ac->ac_q.qp_free != NULL); \
+ ac->ac_q.qp_hold = ac->ac_q.qp_store; \
+ ac->ac_q.qp_store = ac->ac_q.qp_free; \
+ ac->ac_q.qp_free = NULL; \
+ ac->ac_q.qp_store_len = 0; \
+} while (0)
pthread_mutex_t ready_lock;
pthread_cond_t ready_cond;
@@ -246,7 +251,7 @@
return;
}
dprintf("rotating queues for %s", ac->ac_name);
- ROTATE;
+ ROTATE();
WRITER_SIGNAL(ac->ac_q.qp_store_n);
(void) pthread_mutex_unlock(&ac->ac_q.qp_lock);
TAILQ_INSERT_TAIL(ac->ac_q.qp_store, new, aq_glue);
@@ -370,7 +375,7 @@
(void) pthread_mutex_unlock(&ac->ac_q.qp_lock);
continue;
}
- ROTATE;
+ ROTATE();
WRITER_SIGNAL(ac->ac_q.qp_store_n);
(void) pthread_mutex_unlock(&ac->ac_q.qp_lock);
}
More information about the p4-projects
mailing list