- Timestamp:
- Dec 6, 1999, 9:34:59 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/interlock.asm
r1977 r1987 1 ; $Id: interlock.asm,v 1. 2 1999-12-05 13:39:21 sandervlExp $1 ; $Id: interlock.asm,v 1.3 1999-12-06 08:34:59 phaller Exp $ 2 2 3 3 ;/* 4 4 ; * Interlocked apis 5 5 ; * 6 ; * IMPORTANT NOTE: THIS CODE WILL NOT RUN ON 386 CPUs, 7 ; * 486 IS MINIMUM REQUIREMENT! 8 ; * 6 9 ; * Copyright 1999 Sander van Leeuwen 7 10 ; * Copyright 1999 Patrick Haller 8 11 ; * 9 ; * Based on WINE code: win32\thread.c (990815)10 ; *11 ; * Copyright 1995 Martin von Loewis12 ; * Copyright 1997 Onno Hovers13 ; *14 12 ; * Project Odin Software License can be found in LICENSE.TXT 15 13 ; * 16 14 ; */ 17 . 586P15 .486P 18 16 NAME interlocked 19 17 20 18 CODE32 SEGMENT DWORD PUBLIC USE32 'CODE' 21 19 22 public _InterlockedIncrement@4 23 20 21 ;************************************************************************ 24 22 ;* InterlockedIncrement [KERNEL32] * 25 23 ;* * … … 30 28 ;* * 31 29 ;* The returned number need not be equal to the result!!!! * 32 30 ;************************************************************************ 31 32 public _InterlockedIncrement@4 33 33 _InterlockedIncrement@4 proc near 34 mov eax, dword ptr [esp+4] ; LPLONG lpAddend 35 lock inc dword ptr [eax] 36 mov eax, 0 37 je @end ; not incremented? 38 jl @decr 39 inc eax ; ? 40 jmp @end 41 @decr: dec eax ; ? 42 @end: ret 4 34 35 ;@@@PH NT4 implementation 36 mov ecx, [esp+4] 37 mov eax, 1 38 nop 39 lock xadd dword ptr [ecx], eax 40 inc eax 41 retn 4 42 43 ; @@@PH 1999/12/06 old implementation from W95 44 ;var_4 = dword ptr -4 45 ;arg_0 = dword ptr 4 46 ; 47 ; sub esp, 4 48 ; mov eax, [esp + 4 + arg_0] 49 ; lock inc dword ptr [eax] 50 ; mov ecx, 0ffffffffh 51 ; js _ic_2 52 ; jz _ic_1 53 ; inc ecx 54 ;_ic_1: inc ecx 55 ;_ic_2: mov [esp + 4 + var_4], ecx 56 ; mov eax, ecx 57 ; retn 4 58 ; 59 ; @@@PH 1999/12/06 old implementation from WINE 60 ; mov eax, dword ptr [esp+4] ; LPLONG lpAddend 61 ; lock inc dword ptr [eax] 62 ; mov eax, 0 63 ; je @end ; not incremented? 64 ; jl @decr 65 ; inc eax ; ? 66 ; jmp @end 67 ;@decr: dec eax ; ? 68 ;@end: ret 4 43 69 _InterlockedIncrement@4 endp 44 70 45 public _InterlockedDecrement@4 46 71 72 ;************************************************************************ 47 73 ;* InterlockedDecrement [KERNEL32] * 48 74 ;* * … … 53 79 ;* * 54 80 ;* The returned number need not be equal to the result!!!! * 55 81 ;************************************************************************ 82 83 public _InterlockedDecrement@4 56 84 _InterlockedDecrement@4 proc near 57 mov eax, dword ptr [esp+4] ; LPLONG lpAddend 58 lock dec dword ptr [eax] 59 mov eax, 0 60 je @end ; not decremented? 61 jl @decr 62 inc eax ; ? 63 jmp @end 64 @decr: dec eax ; ? 65 @end: ret 4 85 86 ;@@@PH NT4 implementation 87 mov ecx, [esp+4] 88 mov eax, 0ffffffffh 89 nop 90 lock xadd dword ptr [ecx], eax 91 dec eax 92 retn 4 93 94 95 ; @@@PH 1999/12/06 old implementation from W95 96 ;var_4 = dword ptr -4 97 ;arg_0 = dword ptr 4 98 ; 99 ; sub esp, 4 100 ; mov eax, dword ptr[esp+4+arg_0] 101 ; lock dec dword ptr [eax] 102 ; mov ecx, 0ffffffffh 103 ; js _id_2 104 ; jz _id_1 105 ; inc ecx 106 ;_id_1: inc ecx 107 ;_id_2: mov dword ptr [esp+4+var_4], ecx 108 ; mov eax, ecx 109 ; add esp, 4 110 ; retn 4 111 112 ; @@@PH 1999/12/06 old implementation from WINE 113 ; mov eax, dword ptr [esp+4] ; LPLONG lpAddend 114 ; lock dec dword ptr [eax] 115 ; mov eax, 0 116 ; je @end ; not decremented? 117 ; jl @decr 118 ; inc eax ; ? 119 ; jmp @end 120 ;@decr: dec eax ; ? 121 ;@end: ret 4 122 66 123 _InterlockedDecrement@4 endp 67 124 68 125 126 ;************************************************************************ 127 ;* InterlockedExchange [KERNEL32.???] * 128 ;* * 129 ;* Atomically exchanges a pair of values. * 130 ;* * 131 ;* RETURNS * 132 ;* Prior value of value pointed to by Target * 133 ;************************************************************************ 134 69 135 public _InterlockedExchange@8 70 ; * InterlockedExchange [KERNEL32.???]71 ; *72 ; * Atomically exchanges a pair of values.73 ; *74 ; * RETURNS75 ; * Prior value of value pointed to by Target76 77 136 _InterlockedExchange@8 proc near 78 push edx 79 mov eax, [esp+12] ; LONG value 80 mov edx,[esp+8] ; LPLONG target 81 lock xchg eax, dword ptr [edx] 82 pop edx 83 ret 8 137 138 ;@@@PH NT4 implementation 139 mov ecx, [esp+8] 140 mov edx, [esp+4] 141 mov eax, dword ptr [ecx] 142 _ie_1: 143 nop 144 lock cmpxchg dword ptr [ecx], edx 145 jnz _ie_1 146 retn 8 147 148 ; @@@PH 1999/12/06 old implementation from W95 149 ;var_4 = dword ptr -4 150 ;arg_0 = dword ptr 8 151 ;arg_4 = dword ptr 0Ch 152 ; 153 ; push ebp 154 ; mov ebp, esp 155 ; sub esp, 4 156 ; mov eax, dword ptr [ebp+arg_0] 157 ; mov ecx, dword ptr [ebp+arg_4] 158 ; xchg ecx, dword ptr [eax] 159 ; mov dword ptr [ebp+var_4], ecx 160 ; mov eax, ecx 161 ; mov esp, ebp 162 ; pop ebp 163 ; retn 8 164 165 ; @@@PH 1999/12/06 old implementation from WINE 166 ; push edx 167 ; mov eax, [esp+12] ; LONG value 168 ; mov edx,[esp+8] ; LPLONG target 169 ; lock xchg eax, dword ptr [edx] 170 ; pop edx 171 ; ret 8 84 172 _InterlockedExchange@8 endp 85 173 … … 87 175 88 176 public _InterlockedCompareExchange@12 89 ;/************************************************************************ 90 ; * InterlockedCompareExchange [KERNEL32.879] 91 ; * 92 ; * Atomically compares Destination and Comperand, and if found equal exchanges 93 ; * the value of Destination with Exchange 94 ; * 95 ; * RETURNS 96 ; * Prior value of value pointed to by Destination 97 ; */ 177 ;************************************************************************ 178 ;* InterlockedCompareExchange [KERNEL32.879] 179 ;* 180 ;* Atomically compares Destination and Comperand, and if found equal exchanges 181 ;* the value of Destination with Exchange 182 ;* 183 ;* RETURNS 184 ;* Prior value of value pointed to by Destination 185 ;* 186 ;************************************************************************ 98 187 _InterlockedCompareExchange@12 proc near 99 push ebp 100 mov ebp, esp 101 push edx 102 push ebx 103 104 mov ebx, dword ptr [ebp+8] ;PVOID *Destination, /* Address of 32-bit value to exchange */ 105 push dword ptr [ebx] ;save old *Destination 106 mov eax, [ebp+16] ;PVOID Comperand /* value to compare, 32 bits */ 107 mov edx, [ebp+12] ;PVOID Exchange, /* change value, 32 bits */ 108 lock cmpxchg dword ptr [ebx],edx 109 pop eax 110 111 pop ebx 112 pop edx 113 pop ebp 114 ret 12 188 189 ;@@@PH NT4 implementation 190 mov ecx, dword ptr [esp + 12] 191 mov edx, dword ptr [esp + 8] 192 mov eax, dword ptr [esp + 4] 193 _ice_1: 194 nop 195 lock cmpxchg dword ptr [ecx], edx 196 retn 12 197 198 199 ; @@@PH 1999/12/06 old implementation from WINE 200 ; push ebp 201 ; mov ebp, esp 202 ; push edx 203 ; push ebx 204 ; 205 ; mov ebx, dword ptr [ebp+8] ;PVOID *Destination, /* Address of 32-bit value to exchange */ 206 ; push dword ptr [ebx] ;save old *Destination 207 ; mov eax, [ebp+16] ;PVOID Comperand /* value to compare, 32 bits */ 208 ; mov edx, [ebp+12] ;PVOID Exchange, /* change value, 32 bits */ 209 ; lock cmpxchg dword ptr [ebx],edx 210 ; pop eax 211 ; 212 ; pop ebx 213 ; pop edx 214 ; pop ebp 215 ; ret 12 115 216 _InterlockedCompareExchange@12 endp 116 217 218 219 ;************************************************************************ 220 ;* InterlockedExchangeAdd [KERNEL32.880] 221 ;* 222 ;* Atomically adds Increment to Addend and returns the previous value of 223 ;* Addend 224 ;* 225 ;* RETURNS 226 ;* Prior value of value pointed to by cwAddendTarget 227 ;* 228 ;************************************************************************ 117 229 public _InterlockedExchangeAdd@8 118 ; * InterlockedExchangeAdd [KERNEL32.880]119 ; *120 ; * Atomically adds Increment to Addend and returns the previous value of121 ; * Addend122 ; *123 ; * RETURNS124 ; * Prior value of value pointed to by cwAddendTarget125 ; */126 230 _InterlockedExchangeAdd@8 proc near 127 push edx 128 mov eax, dword ptr [esp+12] ;LONG Increment /* Value to add */ 129 mov edx, dword ptr [esp+8] ;PLONG Addend, /* Address of 32-bit value to exchange */ 130 lock xadd dword ptr [edx], eax 131 pop edx 132 ret 8 231 232 ;@@@PH NT4 implementation 233 mov ecx, dword ptr [esp + 4] 234 mov eax, dword ptr [esp + 8] 235 nop 236 lock xadd dword ptr [ecx], eax 237 retn 8 238 239 ; @@@PH 1999/12/06 old implementation from WINE 240 ; 241 ; push edx 242 ; mov eax, dword ptr [esp+12] ;LONG Increment /* Value to add */ 243 ; mov edx, dword ptr [esp+8] ;PLONG Addend, /* Address of 32-bit value to exchange */ 244 ; lock xadd dword ptr [edx], eax 245 ; pop edx 246 ; ret 8 133 247 _InterlockedExchangeAdd@8 endp 134 248
Note:
See TracChangeset
for help on using the changeset viewer.