From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 18 08:32:15 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0F04B30E for ; Wed, 18 Feb 2015 08:32:15 +0000 (UTC) Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by mx1.freebsd.org (Postfix) with ESMTP id 73F502E0 for ; Wed, 18 Feb 2015 08:32:14 +0000 (UTC) Received: from freebsd.my.domain (unknown [58.211.218.74]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygBHTvYDTuRUIKYoAw--.30331S2; Wed, 18 Feb 2015 16:32:09 +0800 (CST) From: Tiwei Bie To: freebsd-hackers@freebsd.org Subject: [PATCH] Use anonymous unions and structs to organize shared space instead of preprocessor macros. Date: Wed, 18 Feb 2015 16:31:48 +0800 Message-Id: <1424248308-20753-1-git-send-email-btw@mail.ustc.edu.cn> X-Mailer: git-send-email 2.1.2 X-CM-TRANSID: LkAmygBHTvYDTuRUIKYoAw--.30331S2 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar17KryUJw4rXr15WF17KFg_yoWxXrykpa yfCFWayrWUJr1DWr97Ga15uaySkw4kCr1xGay3Zw40gF4Sqr17Wr1Utr4rArW5ZrWku3s2 vrs0kw4ru3s2kF7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU90b7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv 0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z2 80aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxE wVAFwVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267 AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWU JwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIda VFxhVjvjDU0xZFpf9x07bzwZcUUUUU= X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQUBAVQhl-COsAAVs9 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Feb 2015 08:32:15 -0000 Hi all, Similar to r278920 [1], the preprocessor macros are converted into anonymous unions and structs in buf, devreq, file, sigio, vnode, xvnode and uma_slab. [1] http://svnweb.freebsd.org/base?view=revision&revision=278920 --- sys/sys/buf.h | 8 +++----- sys/sys/bus.h | 8 +++----- sys/sys/file.h | 9 +++------ sys/sys/sigio.h | 8 +++----- sys/sys/vnode.h | 34 ++++++++++++---------------------- sys/vm/uma_int.h | 9 +++------ 6 files changed, 27 insertions(+), 49 deletions(-) diff --git a/sys/sys/buf.h b/sys/sys/buf.h index 71ef74f..7324f90 100644 --- a/sys/sys/buf.h +++ b/sys/sys/buf.h @@ -124,14 +124,12 @@ struct buf { struct ucred *b_wcred; /* Write credentials reference. */ void *b_saveaddr; /* Original b_addr for physio. */ union { - TAILQ_ENTRY(buf) bu_freelist; /* (Q) */ + TAILQ_ENTRY(buf) b_freelist; /* (Q) */ struct { void (*pg_iodone)(void *, vm_page_t *, int, int); int pg_reqpage; - } bu_pager; - } b_union; -#define b_freelist b_union.bu_freelist -#define b_pager b_union.bu_pager + } b_pager; + }; union cluster_info { TAILQ_HEAD(cluster_list_head, buf) cluster_head; TAILQ_ENTRY(buf) cluster_entry; diff --git a/sys/sys/bus.h b/sys/sys/bus.h index d6dc535..e76b2ca 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -102,11 +102,9 @@ struct devreq { char dr_name[128]; int dr_flags; /* request-specific flags */ union { - struct devreq_buffer dru_buffer; - void *dru_data; - } dr_dru; -#define dr_buffer dr_dru.dru_buffer /* variable-sized buffer */ -#define dr_data dr_dru.dru_data /* fixed-size buffer */ + struct devreq_buffer dr_buffer; /* variable-sized buffer */ + void *dr_data; /* fixed-size buffer */ + }; }; #define DEV_ATTACH _IOW('D', 1, struct devreq) diff --git a/sys/sys/file.h b/sys/sys/file.h index 1538851..4ac62b9 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -173,10 +173,10 @@ struct file { int f_seqcount; /* (a) Count of sequential accesses. */ off_t f_nextoff; /* next expected read/write offset. */ union { - struct cdev_privdata *fvn_cdevpriv; + struct cdev_privdata *f_cdevpriv; /* (d) Private data for the cdev. */ - struct fadvise_info *fvn_advice; - } f_vnun; + struct fadvise_info *f_advice; + }; /* * DFLAG_SEEKABLE specific fields */ @@ -187,9 +187,6 @@ struct file { void *f_label; /* Place-holder for MAC label. */ }; -#define f_cdevpriv f_vnun.fvn_cdevpriv -#define f_advice f_vnun.fvn_advice - #define FOFFSET_LOCKED 0x1 #define FOFFSET_LOCK_WAITING 0x2 #define FDEVFS_VNODE 0x4 diff --git a/sys/sys/sigio.h b/sys/sys/sigio.h index 62ece6d..fc84154 100644 --- a/sys/sys/sigio.h +++ b/sys/sys/sigio.h @@ -45,17 +45,15 @@ */ struct sigio { union { - struct proc *siu_proc; /* (c) process to receive SIGIO/SIGURG */ - struct pgrp *siu_pgrp; /* (c) process group to receive ... */ - } sio_u; + struct proc *sio_proc; /* (c) process to receive SIGIO/SIGURG */ + struct pgrp *sio_pgrp; /* (c) process group to receive ... */ + }; SLIST_ENTRY(sigio) sio_pgsigio; /* (pg) sigio's for process or group */ struct sigio **sio_myref; /* (c) location of the pointer that holds * the reference to this structure */ struct ucred *sio_ucred; /* (c) current credentials */ pid_t sio_pgid; /* (c) pgid for signals */ }; -#define sio_proc sio_u.siu_proc -#define sio_pgrp sio_u.siu_pgrp SLIST_HEAD(sigiolst, sigio); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 8a14f69..ff7f13f 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -114,11 +114,11 @@ struct vnode { * See #defines below for renaming to v_* namespace. */ union { - struct mount *vu_mount; /* v ptr to mountpoint (VDIR) */ - struct socket *vu_socket; /* v unix domain net (VSOCK) */ - struct cdev *vu_cdev; /* v device (VCHR, VBLK) */ - struct fifoinfo *vu_fifoinfo; /* v fifo (VFIFO) */ - } v_un; + struct mount *v_mountedhere; /* v ptr to mountpoint (VDIR) */ + struct socket *v_socket; /* v unix domain net (VSOCK) */ + struct cdev *v_rdev; /* v device (VCHR, VBLK) */ + struct fifoinfo *v_fifoinfo; /* v fifo (VFIFO) */ + }; /* * vfs_hash: (mount + inode) -> vnode hash. The hash value @@ -173,11 +173,6 @@ struct vnode { #endif /* defined(_KERNEL) || defined(_KVM_VNODE) */ -#define v_mountedhere v_un.vu_mount -#define v_socket v_un.vu_socket -#define v_rdev v_un.vu_cdev -#define v_fifoinfo v_un.vu_fifoinfo - /* XXX: These are temporary to avoid a source sweep at this time */ #define v_object v_bufobj.bo_object @@ -196,20 +191,15 @@ struct xvnode { long xv_numoutput; /* num of writes in progress */ enum vtype xv_type; /* vnode type */ union { - void *xvu_socket; /* socket, if VSOCK */ - void *xvu_fifo; /* fifo, if VFIFO */ - dev_t xvu_rdev; /* maj/min, if VBLK/VCHR */ + void *xv_socket; /* socket, if VSOCK */ + void *xv_fifo; /* fifo, if VFIFO */ + dev_t xv_rdev; /* maj/min, if VBLK/VCHR */ struct { - dev_t xvu_dev; /* device, if VDIR/VREG/VLNK */ - ino_t xvu_ino; /* id, if VDIR/VREG/VLNK */ - } xv_uns; - } xv_un; + dev_t xv_dev; /* device, if VDIR/VREG/VLNK */ + ino_t xv_ino; /* id, if VDIR/VREG/VLNK */ + }; + }; }; -#define xv_socket xv_un.xvu_socket -#define xv_fifo xv_un.xvu_fifo -#define xv_rdev xv_un.xvu_rdev -#define xv_dev xv_un.xv_uns.xvu_dev -#define xv_ino xv_un.xv_uns.xvu_ino /* We don't need to lock the knlist */ #define VN_KNLIST_EMPTY(vp) ((vp)->v_pollinfo == NULL || \ diff --git a/sys/vm/uma_int.h b/sys/vm/uma_int.h index 1ffc7d5..dff24be 100644 --- a/sys/vm/uma_int.h +++ b/sys/vm/uma_int.h @@ -231,9 +231,9 @@ BITSET_DEFINE(slabbits, SLAB_SETSIZE); struct uma_slab { uma_keg_t us_keg; /* Keg we live in */ union { - LIST_ENTRY(uma_slab) _us_link; /* slabs in zone */ - unsigned long _us_size; /* Size of allocation */ - } us_type; + LIST_ENTRY(uma_slab) us_link; /* slabs in zone */ + unsigned long us_size; /* Size of allocation */ + }; SLIST_ENTRY(uma_slab) us_hlink; /* Link for hash table */ uint8_t *us_data; /* First item */ struct slabbits us_free; /* Free bitmask. */ @@ -245,9 +245,6 @@ struct uma_slab { uint8_t us_pad; /* Pad to 32bits, unused. */ }; -#define us_link us_type._us_link -#define us_size us_type._us_size - /* * The slab structure for UMA_ZONE_REFCNT zones for whose items we * maintain reference counters in the slab for. -- 2.1.2 Tiwei Bie