From owner-p4-projects Sat Jan 25 20:47:54 2003 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3DDB637B405; Sat, 25 Jan 2003 20:47:51 -0800 (PST) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C834F37B401 for ; Sat, 25 Jan 2003 20:47:50 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 712C143E4A for ; Sat, 25 Jan 2003 20:47:50 -0800 (PST) (envelope-from jmallett@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h0Q4lobv052796 for ; Sat, 25 Jan 2003 20:47:50 -0800 (PST) (envelope-from jmallett@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h0Q4loSc052793 for perforce@freebsd.org; Sat, 25 Jan 2003 20:47:50 -0800 (PST) Date: Sat, 25 Jan 2003 20:47:50 -0800 (PST) Message-Id: <200301260447.h0Q4loSc052793@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jmallett@freebsd.org using -f From: Juli Mallett Subject: PERFORCE change 24210 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://perforce.freebsd.org/chv.cgi?CH=24210 Change 24210 by jmallett@jmallett_dalek on 2003/01/25 20:47:23 Add the readandclear functions for int/long. Add some comments about the format of this file. Affected files ... .. //depot/projects/mips/sys/mips/include/atomic.h#6 edit Differences ... ==== //depot/projects/mips/sys/mips/include/atomic.h#6 (text+ko) ==== @@ -27,6 +27,16 @@ #ifndef _MACHINE_ATOMIC_H_ #define _MACHINE_ATOMIC_H_ +/* + * Atomic operations on the MIPS, keep code abstracted up to the point + * that it is no longer clean. Keep operations on each type sorted in + * an order relative to eachother. + */ + +/* + * Integer atomic operations, hardware calls this single. + */ + #define ATOMIC_OP(op, asmop) \ static __inline void \ atomic_ ## op ## _int(u_int *p, u_int val) \ @@ -50,6 +60,30 @@ ATOMIC_OP(set, "or %[temp], %[temp], %[val]") ATOMIC_OP(subtract, "subu %[temp], %[temp], %[val]") +static __inline int +atomic_readandclear_int(u_int *p) +{ + u_int temp, res; + + __asm __volatile ( + "1:\n\t" + "ll %[temp], %[p]\n\t" + "move %[res], %[temp]\n\t" + "move %[temp], 0\n\t" + "sc %[temp], %[p]\n\t" + "beqz %[temp], 1b\n\t" + : [val] "=r"(val) + : [temp] "r"(temp), [p] "r"(p), [res] "r"(res) + : "memory" + ); + + return res; +} + +/* + * Long atomic operations, hardware calls this double. + */ + #define ATOMIC_DOP(op, asmop) \ static __inline void \ atomic_ ## op ## _long(u_long *p, u_long val) \ @@ -73,4 +107,24 @@ ATOMIC_DOP(set, "or %[temp], %[temp], %[val]") ATOMIC_DOP(subtract, "dsubu %[temp], %[temp], %[val]") +static __inline long +atomic_readandclear_int(u_long *p) +{ + u_long temp, res; + + __asm __volatile ( + "1:\n\t" + "lld %[temp], %[p]\n\t" + "move %[res], %[temp]\n\t" + "move %[temp], 0\n\t" + "scd %[temp], %[p]\n\t" + "beqz %[temp], 1b\n\t" + : [val] "=r"(val) + : [temp] "r"(temp), [p] "r"(p), [res] "r"(res) + : "memory" + ); + + return res; +} + #endif /* !_MACHINE_ATOMIC_H_ */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message