From owner-svn-src-all@FreeBSD.ORG Sat Oct 1 00:22:24 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D1FE3106564A; Sat, 1 Oct 2011 00:22:24 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C13378FC08; Sat, 1 Oct 2011 00:22:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p910MO4W092531; Sat, 1 Oct 2011 00:22:24 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p910MOsr092529; Sat, 1 Oct 2011 00:22:24 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201110010022.p910MOsr092529@svn.freebsd.org> From: Marius Strobl Date: Sat, 1 Oct 2011 00:22:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225890 - head/sys/sparc64/include X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Oct 2011 00:22:24 -0000 Author: marius Date: Sat Oct 1 00:22:24 2011 New Revision: 225890 URL: http://svn.freebsd.org/changeset/base/225890 Log: - Add protective parentheses to macros as far as possible. - Move {r,w,}mb() to the top of this file where they live on most of the other architectures. Modified: head/sys/sparc64/include/atomic.h Modified: head/sys/sparc64/include/atomic.h ============================================================================== --- head/sys/sparc64/include/atomic.h Sat Oct 1 00:11:03 2011 (r225889) +++ head/sys/sparc64/include/atomic.h Sat Oct 1 00:22:24 2011 (r225890) @@ -33,6 +33,10 @@ #include +#define mb() __asm__ __volatile__ ("membar #MemIssue": : :"memory") +#define wmb() mb() +#define rmb() mb() + /* Userland needs different ASI's. */ #ifdef _KERNEL #define __ASI_ATOMIC ASI_N @@ -40,10 +44,6 @@ #define __ASI_ATOMIC ASI_P #endif -#define mb() __asm__ __volatile__ ("membar #MemIssue": : :"memory") -#define wmb() mb() -#define rmb() mb() - /* * Various simple arithmetic on memory which is atomic in the presence * of interrupts and multiple processors. See atomic(9) for details. @@ -88,30 +88,30 @@ #define itype(sz) uint ## sz ## _t -#define atomic_cas_32(p, e, s) casa(p, e, s, __ASI_ATOMIC) -#define atomic_cas_64(p, e, s) casxa(p, e, s, __ASI_ATOMIC) +#define atomic_cas_32(p, e, s) casa((p), (e), (s), __ASI_ATOMIC) +#define atomic_cas_64(p, e, s) casxa((p), (e), (s), __ASI_ATOMIC) #define atomic_cas(p, e, s, sz) \ - atomic_cas_ ## sz(p, e, s) + atomic_cas_ ## sz((p), (e), (s)) #define atomic_cas_acq(p, e, s, sz) ({ \ itype(sz) v; \ - v = atomic_cas(p, e, s, sz); \ + v = atomic_cas((p), (e), (s), sz); \ v; \ }) #define atomic_cas_rel(p, e, s, sz) ({ \ itype(sz) v; \ membar(LoadStore | StoreStore); \ - v = atomic_cas(p, e, s, sz); \ + v = atomic_cas((p), (e), (s), sz); \ v; \ }) #define atomic_op(p, op, v, sz) ({ \ itype(sz) e, r, s; \ - for (e = *(volatile itype(sz) *)p;; e = r) { \ - s = e op v; \ - r = atomic_cas_ ## sz(p, e, s); \ + for (e = *(volatile itype(sz) *)(p);; e = r) { \ + s = e op (v); \ + r = atomic_cas_ ## sz((p), e, s); \ if (r == e) \ break; \ } \ @@ -120,30 +120,30 @@ #define atomic_op_acq(p, op, v, sz) ({ \ itype(sz) t; \ - t = atomic_op(p, op, v, sz); \ + t = atomic_op((p), op, (v), sz); \ t; \ }) #define atomic_op_rel(p, op, v, sz) ({ \ itype(sz) t; \ membar(LoadStore | StoreStore); \ - t = atomic_op(p, op, v, sz); \ + t = atomic_op((p), op, (v), sz); \ t; \ }) #define atomic_load(p, sz) \ - atomic_cas(p, 0, 0, sz) + atomic_cas((p), 0, 0, sz) #define atomic_load_acq(p, sz) ({ \ itype(sz) v; \ - v = atomic_load(p, sz); \ + v = atomic_load((p), sz); \ v; \ }) #define atomic_load_clear(p, sz) ({ \ itype(sz) e, r; \ - for (e = *(volatile itype(sz) *)p;; e = r) { \ - r = atomic_cas(p, e, 0, sz); \ + for (e = *(volatile itype(sz) *)(p);; e = r) { \ + r = atomic_cas((p), e, 0, sz); \ if (r == e) \ break; \ } \ @@ -152,8 +152,8 @@ #define atomic_store(p, v, sz) do { \ itype(sz) e, r; \ - for (e = *(volatile itype(sz) *)p;; e = r) { \ - r = atomic_cas(p, e, v, sz); \ + for (e = *(volatile itype(sz) *)(p);; e = r) { \ + r = atomic_cas((p), e, (v), sz); \ if (r == e) \ break; \ } \ @@ -161,7 +161,7 @@ #define atomic_store_rel(p, v, sz) do { \ membar(LoadStore | StoreStore); \ - atomic_store(p, v, sz); \ + atomic_store((p), (v), sz); \ } while (0) #define ATOMIC_GEN(name, ptype, vtype, atype, sz) \ @@ -169,109 +169,109 @@ static __inline vtype \ atomic_add_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op(p, +, v, sz)); \ + return ((vtype)atomic_op((p), +, (v), sz)); \ } \ static __inline vtype \ atomic_add_acq_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_acq(p, +, v, sz)); \ + return ((vtype)atomic_op_acq((p), +, (v), sz)); \ } \ static __inline vtype \ atomic_add_rel_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_rel(p, +, v, sz)); \ + return ((vtype)atomic_op_rel((p), +, (v), sz)); \ } \ \ static __inline vtype \ atomic_clear_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op(p, &, ~v, sz)); \ + return ((vtype)atomic_op((p), &, ~(v), sz)); \ } \ static __inline vtype \ atomic_clear_acq_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_acq(p, &, ~v, sz)); \ + return ((vtype)atomic_op_acq((p), &, ~(v), sz)); \ } \ static __inline vtype \ atomic_clear_rel_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_rel(p, &, ~v, sz)); \ + return ((vtype)atomic_op_rel((p), &, ~(v), sz)); \ } \ \ static __inline int \ atomic_cmpset_ ## name(volatile ptype p, vtype e, vtype s) \ { \ - return (((vtype)atomic_cas(p, e, s, sz)) == e); \ + return (((vtype)atomic_cas((p), (e), (s), sz)) == (e)); \ } \ static __inline int \ atomic_cmpset_acq_ ## name(volatile ptype p, vtype e, vtype s) \ { \ - return (((vtype)atomic_cas_acq(p, e, s, sz)) == e); \ + return (((vtype)atomic_cas_acq((p), (e), (s), sz)) == (e)); \ } \ static __inline int \ atomic_cmpset_rel_ ## name(volatile ptype p, vtype e, vtype s) \ { \ - return (((vtype)atomic_cas_rel(p, e, s, sz)) == e); \ + return (((vtype)atomic_cas_rel((p), (e), (s), sz)) == (e)); \ } \ \ static __inline vtype \ atomic_load_ ## name(volatile ptype p) \ { \ - return ((vtype)atomic_cas(p, 0, 0, sz)); \ + return ((vtype)atomic_cas((p), 0, 0, sz)); \ } \ static __inline vtype \ atomic_load_acq_ ## name(volatile ptype p) \ { \ - return ((vtype)atomic_cas_acq(p, 0, 0, sz)); \ + return ((vtype)atomic_cas_acq((p), 0, 0, sz)); \ } \ \ static __inline vtype \ atomic_readandclear_ ## name(volatile ptype p) \ { \ - return ((vtype)atomic_load_clear(p, sz)); \ + return ((vtype)atomic_load_clear((p), sz)); \ } \ \ static __inline vtype \ atomic_set_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op(p, |, v, sz)); \ + return ((vtype)atomic_op((p), |, (v), sz)); \ } \ static __inline vtype \ atomic_set_acq_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_acq(p, |, v, sz)); \ + return ((vtype)atomic_op_acq((p), |, (v), sz)); \ } \ static __inline vtype \ atomic_set_rel_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_rel(p, |, v, sz)); \ + return ((vtype)atomic_op_rel((p), |, (v), sz)); \ } \ \ static __inline vtype \ atomic_subtract_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op(p, -, v, sz)); \ + return ((vtype)atomic_op((p), -, (v), sz)); \ } \ static __inline vtype \ atomic_subtract_acq_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_acq(p, -, v, sz)); \ + return ((vtype)atomic_op_acq((p), -, (v), sz)); \ } \ static __inline vtype \ atomic_subtract_rel_ ## name(volatile ptype p, atype v) \ { \ - return ((vtype)atomic_op_rel(p, -, v, sz)); \ + return ((vtype)atomic_op_rel((p), -, (v), sz)); \ } \ \ static __inline void \ atomic_store_ ## name(volatile ptype p, vtype v) \ { \ - atomic_store(p, v, sz); \ + atomic_store((p), (v), sz); \ } \ static __inline void \ atomic_store_rel_ ## name(volatile ptype p, vtype v) \ { \ - atomic_store_rel(p, v, sz); \ + atomic_store_rel((p), (v), sz); \ } ATOMIC_GEN(int, u_int *, u_int, u_int, 32);