Added implementations for InterlockedExchangeAdd() and
InterlockedCompareExchange().
This commit is contained in:
parent
7b06d98404
commit
6df25e8004
|
@ -893,8 +893,8 @@ init MAIN_KernelInit
|
|||
875 stdcall GetFileAttributesExW(wstr long ptr) GetFileAttributesEx32W
|
||||
876 stub GetProcessPriorityBoost
|
||||
877 stub GetThreadPriorityBoost
|
||||
878 stub InterlockedCompareExchange
|
||||
879 stub InterlockedExchangeAdd
|
||||
878 stdcall InterlockedCompareExchange (ptr long long) InterlockedCompareExchange
|
||||
879 stdcall InterlockedExchangeAdd (ptr long ) InterlockedExchangeAdd
|
||||
880 stdcall IsProcessorFeaturePresent(long) IsProcessorFeaturePresent
|
||||
881 stub OpenWaitableTimerA
|
||||
882 stub OpenWaitableTimerW
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "windows.h"
|
||||
#include "winnt.h"
|
||||
#include "winbase.h"
|
||||
#include "winerror.h"
|
||||
#include "debug.h"
|
||||
|
@ -131,3 +131,72 @@ LONG WINAPI InterlockedExchange(
|
|||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* InterlockedCompareExchange [KERNEL32.879]
|
||||
*
|
||||
* Atomically compares Destination and Comperand, and if found equal exchanges
|
||||
* the value of Destination with Exchange
|
||||
*
|
||||
* RETURNS
|
||||
* Prior value of value pointed to by Destination
|
||||
*/
|
||||
PVOID WINAPI InterlockedCompareExchange(
|
||||
PVOID *Destination, /* Address of 32-bit value to exchange */
|
||||
PVOID Exchange, /* change value, 32 bits */
|
||||
PVOID Comperand /* value to compare, 32 bits */
|
||||
) {
|
||||
#if defined(__i386__)&&defined(__GNUC__)
|
||||
PVOID ret;
|
||||
__asm__ ( /* lock for SMP systems */
|
||||
"lock\n\t"
|
||||
"cmpxchgl %2,(%1)"
|
||||
:"=r" (ret)
|
||||
:"r" (Destination),"r" (Exchange), "0" (Comperand)
|
||||
:"memory" );
|
||||
return ret;
|
||||
#else
|
||||
PVOID ret;
|
||||
/* StopAllThreadsAndProcesses() */
|
||||
|
||||
ret=*Destination;
|
||||
if(*Destination==Comperand) *Destination=Exchange;
|
||||
|
||||
/* ResumeAllThreadsAndProcesses() */
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* InterlockedExchangeAdd [KERNEL32.880]
|
||||
*
|
||||
* Atomically adds Increment to Addend and returns the previous value of
|
||||
* Addend
|
||||
*
|
||||
* RETURNS
|
||||
* Prior value of value pointed to by cwAddendTarget
|
||||
*/
|
||||
LONG WINAPI InterlockedExchangeAdd(
|
||||
PLONG Addend, /* Address of 32-bit value to exchange */
|
||||
LONG Increment /* Value to add */
|
||||
) {
|
||||
#if defined(__i386__)&&defined(__GNUC__)
|
||||
LONG ret;
|
||||
__asm__ ( /* lock for SMP systems */
|
||||
"lock\n\t"
|
||||
"xaddl %0,(%1)"
|
||||
:"=r" (ret)
|
||||
:"r" (Addend), "0" (Increment)
|
||||
:"memory" );
|
||||
return ret;
|
||||
#else
|
||||
LONG ret;
|
||||
/* StopAllThreadsAndProcesses() */
|
||||
|
||||
ret = *Addend;
|
||||
*Addend += Increment;
|
||||
|
||||
/* ResumeAllThreadsAndProcesses() */
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue