| 1 | ; $Id: interlock.asm,v 1.1 2002-04-07 14:35:24 sandervl Exp $
 | 
|---|
| 2 | 
 | 
|---|
| 3 | ;/*
 | 
|---|
| 4 | ; * Interlocked apis
 | 
|---|
| 5 | ; *
 | 
|---|
| 6 | ; * Copyright 1999 Sander van Leeuwen
 | 
|---|
| 7 | ; * Copyright 1999 Patrick Haller
 | 
|---|
| 8 | ; *
 | 
|---|
| 9 | ; * Based on WINE code: win32\thread.c (990815)
 | 
|---|
| 10 | ; *
 | 
|---|
| 11 | ; * Copyright 1995 Martin von Loewis
 | 
|---|
| 12 | ; * Copyright 1997 Onno Hovers
 | 
|---|
| 13 | ; *
 | 
|---|
| 14 | ; * Project Odin Software License can be found in LICENSE.TXT
 | 
|---|
| 15 | ; *
 | 
|---|
| 16 | ; */
 | 
|---|
| 17 | .586P
 | 
|---|
| 18 |                NAME    interlocked
 | 
|---|
| 19 | 
 | 
|---|
| 20 | CODE32         SEGMENT DWORD PUBLIC USE32 'CODE'
 | 
|---|
| 21 | 
 | 
|---|
| 22 |        public  _DosInterlockedIncrement@4
 | 
|---|
| 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 | _DosInterlockedIncrement@4 proc near
 | 
|---|
| 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
 | 
|---|
| 40 | _DosInterlockedIncrement@4 endp
 | 
|---|
| 41 | 
 | 
|---|
| 42 |        public  _DosInterlockedDecrement@4
 | 
|---|
| 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 | _DosInterlockedDecrement@4 proc near
 | 
|---|
| 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
 | 
|---|
| 60 | _DosInterlockedDecrement@4 endp
 | 
|---|
| 61 | 
 | 
|---|
| 62 | 
 | 
|---|
| 63 |        public  _DosInterlockedExchange@8
 | 
|---|
| 64 | ; *           InterlockedExchange                               [KERNEL32.???]
 | 
|---|
| 65 | ; *
 | 
|---|
| 66 | ; * Atomically exchanges a pair of values.
 | 
|---|
| 67 | ; *
 | 
|---|
| 68 | ; * RETURNS
 | 
|---|
| 69 | ; *     Prior value of value pointed to by Target
 | 
|---|
| 70 | 
 | 
|---|
| 71 | _DosInterlockedExchange@8 proc near
 | 
|---|
| 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
 | 
|---|
| 77 |         ret     8
 | 
|---|
| 78 | _DosInterlockedExchange@8 endp
 | 
|---|
| 79 | 
 | 
|---|
| 80 | 
 | 
|---|
| 81 | 
 | 
|---|
| 82 |                 public _DosInterlockedCompareExchange@12
 | 
|---|
| 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 | ; */
 | 
|---|
| 90 | _DosInterlockedCompareExchange@12 proc near
 | 
|---|
| 91 |         push    ebp
 | 
|---|
| 92 |         mov     ebp, esp
 | 
|---|
| 93 |         push    edx
 | 
|---|
| 94 |         push    ebx
 | 
|---|
| 95 | 
 | 
|---|
| 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
 | 
|---|
| 100 | 
 | 
|---|
| 101 |         pop     ebx
 | 
|---|
| 102 |         pop     edx
 | 
|---|
| 103 |         pop     ebp
 | 
|---|
| 104 |         ret     12
 | 
|---|
| 105 | _DosInterlockedCompareExchange@12 endp
 | 
|---|
| 106 | 
 | 
|---|
| 107 |                 public _DosInterlockedExchangeAdd@8
 | 
|---|
| 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 | ; */
 | 
|---|
| 116 | _DosInterlockedExchangeAdd@8 proc near
 | 
|---|
| 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
 | 
|---|
| 123 | _DosInterlockedExchangeAdd@8 endp
 | 
|---|
| 124 | 
 | 
|---|
| 125 | CODE32          ENDS
 | 
|---|
| 126 | 
 | 
|---|
| 127 |                 END
 | 
|---|