From owner-p4-projects@FreeBSD.ORG Sun Apr 6 20:21:17 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B66951065672; Sun, 6 Apr 2008 20:21:17 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78E94106564A for ; Sun, 6 Apr 2008 20:21:17 +0000 (UTC) (envelope-from csjp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5E62E8FC1C for ; Sun, 6 Apr 2008 20:21:17 +0000 (UTC) (envelope-from csjp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m36KLHxT014900 for ; Sun, 6 Apr 2008 20:21:17 GMT (envelope-from csjp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m36KLGab014898 for perforce@freebsd.org; Sun, 6 Apr 2008 20:21:16 GMT (envelope-from csjp@freebsd.org) Date: Sun, 6 Apr 2008 20:21:16 GMT Message-Id: <200804062021.m36KLGab014898@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to csjp@freebsd.org using -f From: "Christian S.J. Peron" To: Perforce Change Reviews Cc: Subject: PERFORCE change 139471 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Apr 2008 20:21:17 -0000 http://perforce.freebsd.org/chv.cgi?CH=139471 Change 139471 by csjp@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); }