source: branches/branch-1-0/src/helpers/interlock.asm

Last change on this file was 196, checked in by umoeller, 23 years ago

Misc fixes.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
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
19CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
20
21;* LONG DosInterlockedIncrement(PLONG);
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
30public DosInterlockedIncrement
31DosInterlockedIncrement proc near
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
38DosInterlockedIncrement endp
39
40;* LONG DosInterlockedDecrement(PLONG);
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
49public DosInterlockedDecrement
50DosInterlockedDecrement proc near
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
57DosInterlockedDecrement endp
58
59
60; * LONG DosInterlockedExchange(PLONG, LONG);
61; *
62; * Atomically exchanges a pair of values.
63; *
64; * RETURNS
65; * Prior value of value pointed to by Target
66
67public DosInterlockedExchange
68DosInterlockedExchange proc near
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
75DosInterlockedExchange endp
76
77
78;/************************************************************************
79; * LONG DosInterlockedCompareExchange(PLONG dest, LONG xchg, LONG compare)
80; *
81; * Atomically compares Destination and Comperand, and if found equal exchanges
82; * the value of Destination with Exchange
83; *
84; */
85
86public DosInterlockedCompareExchange
87DosInterlockedCompareExchange proc near
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
102DosInterlockedCompareExchange endp
103
104; * LONG DosInterlockedExchangeAdd(PLONG dest, LONG incr);
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
113public DosInterlockedExchangeAdd
114DosInterlockedExchangeAdd proc near
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
121DosInterlockedExchangeAdd endp
122
123CODE32 ENDS
124
125 END
Note: See TracBrowser for help on using the repository browser.