[5938] | 1 | ; $Id: interlock.asm,v 1.10 2001-06-09 19:45:42 sandervl Exp $
|
---|
[737] | 2 |
|
---|
| 3 | ;/*
|
---|
| 4 | ; * Interlocked apis
|
---|
| 5 | ; *
|
---|
| 6 | ; * Copyright 1999 Sander van Leeuwen
|
---|
| 7 | ; * Copyright 1999 Patrick Haller
|
---|
| 8 | ; *
|
---|
[2088] | 9 | ; * Based on WINE code: win32\thread.c (990815)
|
---|
| 10 | ; *
|
---|
| 11 | ; * Copyright 1995 Martin von Loewis
|
---|
| 12 | ; * Copyright 1997 Onno Hovers
|
---|
| 13 | ; *
|
---|
[737] | 14 | ; * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 15 | ; *
|
---|
| 16 | ; */
|
---|
[2088] | 17 | .586P
|
---|
[737] | 18 | NAME interlocked
|
---|
| 19 |
|
---|
| 20 | CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
|
---|
| 21 |
|
---|
[2088] | 22 | public _InterlockedIncrement@4
|
---|
[737] | 23 |
|
---|
| 24 | ;* InterlockedIncrement [KERNEL32] *
|
---|
| 25 | ;* *
|
---|
| 26 | ;* InterlockedIncrement adds 1 to a long variable and returns *
|
---|
| 27 | ;* - a negative number if the result < 0 *
|
---|
| 28 | ;* - zero if the result == 0 *
|
---|
| 29 | ;* - a positive number if the result > 0 *
|
---|
| 30 | ;* *
|
---|
| 31 | ;* The returned number need not be equal to the result!!!! *
|
---|
| 32 |
|
---|
| 33 | _InterlockedIncrement@4 proc near
|
---|
[5938] | 34 | ;we are allowed to trash edx
|
---|
| 35 | mov edx, dword ptr [esp+4] ; LPLONG lpAddend
|
---|
| 36 | mov eax, 1
|
---|
| 37 | lock xadd dword ptr [edx], eax
|
---|
| 38 | inc eax
|
---|
| 39 | ret 4
|
---|
[737] | 40 | _InterlockedIncrement@4 endp
|
---|
| 41 |
|
---|
[2088] | 42 | public _InterlockedDecrement@4
|
---|
[737] | 43 |
|
---|
| 44 | ;* InterlockedDecrement [KERNEL32] *
|
---|
| 45 | ;* *
|
---|
| 46 | ;* InterlockedIncrement adds 1 to a long variable and returns *
|
---|
| 47 | ;* - a negative number if the result < 0 *
|
---|
| 48 | ;* - zero if the result == 0 *
|
---|
| 49 | ;* - a positive number if the result > 0 *
|
---|
| 50 | ;* *
|
---|
| 51 | ;* The returned number need not be equal to the result!!!! *
|
---|
| 52 |
|
---|
| 53 | _InterlockedDecrement@4 proc near
|
---|
[5938] | 54 | ;we are allowed to trash edx
|
---|
| 55 | mov edx, dword ptr [esp+4] ; LPLONG lpAddend
|
---|
| 56 | mov eax, -1
|
---|
| 57 | lock xadd dword ptr [edx], eax
|
---|
| 58 | dec eax
|
---|
| 59 | ret 4
|
---|
[737] | 60 | _InterlockedDecrement@4 endp
|
---|
| 61 |
|
---|
| 62 |
|
---|
[2088] | 63 | public _InterlockedExchange@8
|
---|
| 64 | ; * InterlockedExchange [KERNEL32.???]
|
---|
| 65 | ; *
|
---|
| 66 | ; * Atomically exchanges a pair of values.
|
---|
| 67 | ; *
|
---|
| 68 | ; * RETURNS
|
---|
| 69 | ; * Prior value of value pointed to by Target
|
---|
[1987] | 70 |
|
---|
| 71 | _InterlockedExchange@8 proc near
|
---|
[2088] | 72 | push edx
|
---|
| 73 | mov eax, [esp+12] ; LONG value
|
---|
| 74 | mov edx,[esp+8] ; LPLONG target
|
---|
| 75 | lock xchg eax, dword ptr [edx]
|
---|
| 76 | pop edx
|
---|
[2090] | 77 | ret 8
|
---|
[737] | 78 | _InterlockedExchange@8 endp
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | public _InterlockedCompareExchange@12
|
---|
[2088] | 83 | ;/************************************************************************
|
---|
| 84 | ; * InterlockedCompareExchange [KERNEL32.879]
|
---|
| 85 | ; *
|
---|
| 86 | ; * Atomically compares Destination and Comperand, and if found equal exchanges
|
---|
| 87 | ; * the value of Destination with Exchange
|
---|
| 88 | ; *
|
---|
| 89 | ; */
|
---|
[737] | 90 | _InterlockedCompareExchange@12 proc near
|
---|
[2088] | 91 | push ebp
|
---|
| 92 | mov ebp, esp
|
---|
| 93 | push edx
|
---|
| 94 | push ebx
|
---|
[737] | 95 |
|
---|
[2088] | 96 | mov ebx, dword ptr [ebp+8] ;PVOID *Destination, /* Address of 32-bit value to exchange */
|
---|
| 97 | mov eax, [ebp+16] ;PVOID Comperand /* value to compare, 32 bits */
|
---|
| 98 | mov edx, [ebp+12] ;PVOID Exchange, /* change value, 32 bits */
|
---|
| 99 | lock cmpxchg dword ptr [ebx],edx
|
---|
[737] | 100 |
|
---|
[2088] | 101 | pop ebx
|
---|
| 102 | pop edx
|
---|
| 103 | pop ebp
|
---|
| 104 | ret 12
|
---|
[737] | 105 | _InterlockedCompareExchange@12 endp
|
---|
| 106 |
|
---|
| 107 | public _InterlockedExchangeAdd@8
|
---|
[2088] | 108 | ; * InterlockedExchangeAdd [KERNEL32.880]
|
---|
| 109 | ; *
|
---|
| 110 | ; * Atomically adds Increment to Addend and returns the previous value of
|
---|
| 111 | ; * Addend
|
---|
| 112 | ; *
|
---|
| 113 | ; * RETURNS
|
---|
| 114 | ; * Prior value of value pointed to by cwAddendTarget
|
---|
| 115 | ; */
|
---|
[737] | 116 | _InterlockedExchangeAdd@8 proc near
|
---|
[2088] | 117 | push edx
|
---|
| 118 | mov eax, dword ptr [esp+12] ;LONG Increment /* Value to add */
|
---|
| 119 | mov edx, dword ptr [esp+8] ;PLONG Addend, /* Address of 32-bit value to exchange */
|
---|
| 120 | lock xadd dword ptr [edx], eax
|
---|
| 121 | pop edx
|
---|
| 122 | ret 8
|
---|
[737] | 123 | _InterlockedExchangeAdd@8 endp
|
---|
| 124 |
|
---|
[22018] | 125 | public _interlocked_cmpxchg64
|
---|
| 126 | _interlocked_cmpxchg64 proc near
|
---|
| 127 | push ebx;
|
---|
| 128 | push esi;
|
---|
| 129 | mov esi, 12[esp];
|
---|
| 130 | mov ebx, 16[esp];
|
---|
| 131 | mov ecx, 20[esp];
|
---|
| 132 | mov eax, 24[esp];
|
---|
| 133 | mov edx, 28[esp];
|
---|
| 134 | lock cmpxchg8b [esi];
|
---|
| 135 | pop esi;
|
---|
| 136 | pop ebx;
|
---|
| 137 | ret;
|
---|
| 138 | _interlocked_cmpxchg64 endp
|
---|
| 139 |
|
---|
[737] | 140 | CODE32 ENDS
|
---|
| 141 |
|
---|
| 142 | END
|
---|