Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-03

Cmpxchg

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Werner Van Belle

Hello,

I have been browsing the web somewhat to figure out how I can have access to a cmpxchg function in freepascal. At the momente I found very little information. Some references on people arguing that this is unnecessary. Others that it takes too much time etcetera. In any case: I _really_ want to have access to a cmpxchg function and tried to find information on the assembler routines on how to get access to such function.

I got as far as the following statement, which doesn't compile of course

function cmpxchg(CompareVal, NewVal: Cardinal; var Target: Cardinal):
Cardinal; assembler;
asm
 lock cmpxchg [%eax], %ecx
end;

Now, the problem is twofold:
1. in which registers are the incoming values ?
2. there are syntax errors in this couple of lines and I have no idea what the proper syntax would be (and the freepascal wiki, has very little information on the assembler directives themselves).

I will of course be grateful to anybody helping me solve this problem and send a very nice 'thank you' email :-)

Wkr,

Reply by email

Jonas Maebe
to Werner Van Belle
Werner Van Belle wrote 9 lines
I have been browsing the web somewhat to figure out how I can have access to a cmpxchg function in freepascal. At the momente I found very little information. Some references on people arguing that this is unnecessary. Others that it takes too much time etcetera. In any case: I _really_ want to have access to a cmpxchg function and tried to find information on the assembler routines on how to get access to such function.

The function you want is InterlockedCompareExchange(), which is defined in the system unit: http://www.freepascal.org/docs-html/rtl/system/interlockedcompareexchange.html

It does what cmpxchg does, and moreover is cross-platform.

Jonas

Reply by email

Werner Van Belle
to Jonas Maebe
Jonas Maebe wrote 17 lines
On 31 Mar 2010, at 16:13, Werner Van Belle wrote: > I have been browsing the web somewhat to figure out how I can have > access to a cmpxchg function in freepascal. At the momente I found very > little information. Some references on people arguing that this is > unnecessary. Others that it takes too much time etcetera. In any case: I > _really_ want to have access to a cmpxchg function and tried to find > information on the assembler routines on how to get access to such > function. The function you want is InterlockedCompareExchange(), which is defined in the system unit: http://www.freepascal.org/docs-html/rtl/system/interlockedcompareexchange.html It does what cmpxchg does, and moreover is cross-platform.

Cool !!! Thanks a lot for the info. This is exactly what I was looking for !

Reply by email