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