From owner-freebsd-hackers Mon Sep 25 14:59:54 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from penfold.transactionsite.com (penfold.transactionsite.com [203.14.245.1]) by hub.freebsd.org (Postfix) with SMTP id 49C8A37B424 for ; Mon, 25 Sep 2000 14:59:49 -0700 (PDT) Received: (qmail 1433 invoked from network); 25 Sep 2000 21:59:40 -0000 Received: from haym.transactionsite.com (HELO haym) (192.168.1.9) by penfold.transactionsite.com with SMTP; 25 Sep 2000 21:59:40 -0000 Message-ID: <00b701c0273b$39f7aaa0$0901a8c0@haym.transactionsite.com> From: "Jan Mikkelsen" To: "Kevin Mills" , "FreeBSD Hackers" Subject: Re: atomic operations Date: Tue, 26 Sep 2000 08:54:48 +1100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Kevin Mills wrote: >I found the atomic_* functions in , but noticed that they >have no return value. What I need is a function that increments/decrements >the given value *and* returns the new value in an atomic operation. I >suppose this is possible, yes? How would one modify the assembly to make >this work? Atomic decrement, in the Intel style: long atomic_decrement(volatile long* address) { asm { mov ecx, [address] mov eax, -1 lock xadd [ecx], eax dec eax } /* Return value in EAX */ } An untested conversion into the GNU/AT&T style: long atomic_decrement(volatile long* address) { asm("movl 8(%ebp),%ecx"); asm("movl $-1, %eax"); asm("lock xaddl %eax,(%ecx)"); asm("decl %eax"); /* Return value in %eax */ } Deriving increment is straightforward. I haven't looked at the GNU inline assembler notation for indicating register usage. I'd be curious to see what is should look like. Jan Mikkelsen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message