michael@0: / -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: / michael@0: / This Source Code Form is subject to the terms of the Mozilla Public michael@0: / License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: / file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: / PRInt32 __PR_MD_ATOMIC_INCREMENT(PRInt32 *val) michael@0: / michael@0: / Atomically increment the integer pointed to by 'val' and return michael@0: / the result of the increment. michael@0: / michael@0: .text michael@0: .globl __PR_MD_ATOMIC_INCREMENT michael@0: .align 4 michael@0: __PR_MD_ATOMIC_INCREMENT: michael@0: movl 4(%esp), %ecx michael@0: movl $1, %eax michael@0: lock michael@0: xaddl %eax, (%ecx) michael@0: incl %eax michael@0: ret michael@0: michael@0: / PRInt32 __PR_MD_ATOMIC_DECREMENT(PRInt32 *val) michael@0: / michael@0: / Atomically decrement the integer pointed to by 'val' and return michael@0: / the result of the decrement. michael@0: / michael@0: .text michael@0: .globl __PR_MD_ATOMIC_DECREMENT michael@0: .align 4 michael@0: __PR_MD_ATOMIC_DECREMENT: michael@0: movl 4(%esp), %ecx michael@0: movl $-1, %eax michael@0: lock michael@0: xaddl %eax, (%ecx) michael@0: decl %eax michael@0: ret michael@0: michael@0: / PRInt32 __PR_MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval) michael@0: / michael@0: / Atomically set the integer pointed to by 'val' to the new michael@0: / value 'newval' and return the old value. michael@0: / michael@0: / An alternative implementation: michael@0: / .text michael@0: / .globl __PR_MD_ATOMIC_SET michael@0: / .align 4 michael@0: /__PR_MD_ATOMIC_SET: michael@0: / movl 4(%esp), %ecx michael@0: / movl 8(%esp), %edx michael@0: / movl (%ecx), %eax michael@0: /retry: michael@0: / lock michael@0: / cmpxchgl %edx, (%ecx) michael@0: / jne retry michael@0: / ret michael@0: / michael@0: .text michael@0: .globl __PR_MD_ATOMIC_SET michael@0: .align 4 michael@0: __PR_MD_ATOMIC_SET: michael@0: movl 4(%esp), %ecx michael@0: movl 8(%esp), %eax michael@0: xchgl %eax, (%ecx) michael@0: ret michael@0: michael@0: / PRInt32 __PR_MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 val) michael@0: / michael@0: / Atomically add 'val' to the integer pointed to by 'ptr' michael@0: / and return the result of the addition. michael@0: / michael@0: .text michael@0: .globl __PR_MD_ATOMIC_ADD michael@0: .align 4 michael@0: __PR_MD_ATOMIC_ADD: michael@0: movl 4(%esp), %ecx michael@0: movl 8(%esp), %eax michael@0: movl %eax, %edx michael@0: lock michael@0: xaddl %eax, (%ecx) michael@0: addl %edx, %eax michael@0: ret