|
1 / -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 / |
|
3 / This Source Code Form is subject to the terms of the Mozilla Public |
|
4 / License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 / file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
6 |
|
7 / PRInt32 __PR_MD_ATOMIC_INCREMENT(PRInt32 *val) |
|
8 / |
|
9 / Atomically increment the integer pointed to by 'val' and return |
|
10 / the result of the increment. |
|
11 / |
|
12 .text |
|
13 .globl __PR_MD_ATOMIC_INCREMENT |
|
14 .align 4 |
|
15 __PR_MD_ATOMIC_INCREMENT: |
|
16 movl 4(%esp), %ecx |
|
17 movl $1, %eax |
|
18 lock |
|
19 xaddl %eax, (%ecx) |
|
20 incl %eax |
|
21 ret |
|
22 |
|
23 / PRInt32 __PR_MD_ATOMIC_DECREMENT(PRInt32 *val) |
|
24 / |
|
25 / Atomically decrement the integer pointed to by 'val' and return |
|
26 / the result of the decrement. |
|
27 / |
|
28 .text |
|
29 .globl __PR_MD_ATOMIC_DECREMENT |
|
30 .align 4 |
|
31 __PR_MD_ATOMIC_DECREMENT: |
|
32 movl 4(%esp), %ecx |
|
33 movl $-1, %eax |
|
34 lock |
|
35 xaddl %eax, (%ecx) |
|
36 decl %eax |
|
37 ret |
|
38 |
|
39 / PRInt32 __PR_MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval) |
|
40 / |
|
41 / Atomically set the integer pointed to by 'val' to the new |
|
42 / value 'newval' and return the old value. |
|
43 / |
|
44 / An alternative implementation: |
|
45 / .text |
|
46 / .globl __PR_MD_ATOMIC_SET |
|
47 / .align 4 |
|
48 /__PR_MD_ATOMIC_SET: |
|
49 / movl 4(%esp), %ecx |
|
50 / movl 8(%esp), %edx |
|
51 / movl (%ecx), %eax |
|
52 /retry: |
|
53 / lock |
|
54 / cmpxchgl %edx, (%ecx) |
|
55 / jne retry |
|
56 / ret |
|
57 / |
|
58 .text |
|
59 .globl __PR_MD_ATOMIC_SET |
|
60 .align 4 |
|
61 __PR_MD_ATOMIC_SET: |
|
62 movl 4(%esp), %ecx |
|
63 movl 8(%esp), %eax |
|
64 xchgl %eax, (%ecx) |
|
65 ret |
|
66 |
|
67 / PRInt32 __PR_MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 val) |
|
68 / |
|
69 / Atomically add 'val' to the integer pointed to by 'ptr' |
|
70 / and return the result of the addition. |
|
71 / |
|
72 .text |
|
73 .globl __PR_MD_ATOMIC_ADD |
|
74 .align 4 |
|
75 __PR_MD_ATOMIC_ADD: |
|
76 movl 4(%esp), %ecx |
|
77 movl 8(%esp), %eax |
|
78 movl %eax, %edx |
|
79 lock |
|
80 xaddl %eax, (%ecx) |
|
81 addl %edx, %eax |
|
82 ret |