* New fix for fpc_atomic_cmp_xchg_alu, as suggested by Sven

This commit is contained in:
Michaël Van Canneyt 2025-01-08 14:56:16 +01:00
parent 5d100fd2c6
commit 8488c87b20
3 changed files with 21 additions and 14 deletions

View File

@ -3532,24 +3532,18 @@ end;
{$endif FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_64} {$endif FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_64}
{$if defined(FPC_SYSTEM_NEEDS_ATOMIC_FALLBACK)} {$if defined(FPC_SYSTEM_NEEDS_ATOMIC_FALLBACK)}
Type
{$IFDEF CPUWASM32}
TAtomicLockType = longint;
{$ELSE}
TAtomicLockType = ALUSInt;
{$ENDIF}
var var
gAtomicLock: TAtomicLockType = 0; gAtomicLock: ALUSInt = 0;
function fpc_atomic_cmp_xchg_alu(var Target: TAtomicLockType; NewValue: TAtomicLockType; Comparand: TAtomicLockType): TAtomicLockType; external name function fpc_atomic_cmp_xchg_alu(var Target: ALUSInt; NewValue: ALUSInt; Comparand: ALUSInt): ALUSInt; external name
{$if SIZEOF(TAtomicLockType)=1} {$if defined(CPUINT8)}
'FPC_ATOMIC_CMP_XCHG_8' 'FPC_ATOMIC_CMP_XCHG_8'
{$elseif SIZEOF(TAtomicLockType)=2} {$elseif defined(CPUINT16)}
'FPC_ATOMIC_CMP_XCHG_16' 'FPC_ATOMIC_CMP_XCHG_16'
{$elseif SIZEOF(TAtomicLockType)=4} {$elseif defined(CPUINT32)}
'FPC_ATOMIC_CMP_XCHG_32' 'FPC_ATOMIC_CMP_XCHG_32'
{$elseif SIZEOF(TAtomicLockType)=8} {$elseif defined(CPUINT64)}
'FPC_ATOMIC_CMP_XCHG_64' 'FPC_ATOMIC_CMP_XCHG_64'
{$else} {$else}
'FPC_ATOMIC_CMP_XCHG_UNKNOWN' 'FPC_ATOMIC_CMP_XCHG_UNKNOWN'
@ -3558,7 +3552,7 @@ function fpc_atomic_cmp_xchg_alu(var Target: TAtomicLockType; NewValue: TAtomicL
procedure AtomicEnterLock; procedure AtomicEnterLock;
var var
r: TAtomicLockType; r: ALUSInt;
begin begin
{ spin until we get the lock } { spin until we get the lock }
repeat repeat

View File

@ -81,7 +81,7 @@ function fpc_wasm32_i32_atomic_rmw_cmpxchg_u(Dest: PLongWord; Expected, Replacem
function fpc_wasm32_i64_atomic_rmw8_cmpxchg_u(Dest: PByte; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw8_cmpxchg_u]; function fpc_wasm32_i64_atomic_rmw8_cmpxchg_u(Dest: PByte; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw8_cmpxchg_u];
function fpc_wasm32_i64_atomic_rmw16_cmpxchg_u(Dest: PWord; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw16_cmpxchg_u]; function fpc_wasm32_i64_atomic_rmw16_cmpxchg_u(Dest: PWord; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw16_cmpxchg_u];
function fpc_wasm32_i64_atomic_rmw32_cmpxchg_u(Dest: PWord; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw32_cmpxchg_u]; function fpc_wasm32_i64_atomic_rmw32_cmpxchg_u(Dest: PWord; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw32_cmpxchg_u];
function fpc_wasm32_i64_atomic_rmw_cmpxchg_u(Dest: PLongWord; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw_cmpxchg]; function fpc_wasm32_i64_atomic_rmw_cmpxchg_u(Dest: PQWord; Expected, Replacement: QWord): QWord;[internproc:fpc_in_wasm32_i64_atomic_rmw_cmpxchg];
function fpc_wasm32_memory_atomic_wait32(Dest: PLongWord; Expected: LongWord; Timeout: Int64): LongInt;[internproc:fpc_in_wasm32_memory_atomic_wait32]; function fpc_wasm32_memory_atomic_wait32(Dest: PLongWord; Expected: LongWord; Timeout: Int64): LongInt;[internproc:fpc_in_wasm32_memory_atomic_wait32];
function fpc_wasm32_memory_atomic_wait64(Dest: PQWord; Expected: QWord; Timeout: Int64): LongInt;[internproc:fpc_in_wasm32_memory_atomic_wait64]; function fpc_wasm32_memory_atomic_wait64(Dest: PQWord; Expected: QWord; Timeout: Int64): LongInt;[internproc:fpc_in_wasm32_memory_atomic_wait64];

View File

@ -145,6 +145,19 @@ function fpc_atomic_cmp_xchg_32 (var Target: longint; NewValue: longint; Compara
{$endif FPC_WASM_THREADS} {$endif FPC_WASM_THREADS}
end; end;
{$ifndef VER3_2}
{$define FPC_SYSTEM_HAS_ATOMIC_CMP_XCHG_64}
function fpc_atomic_cmp_xchg_64 (var Target: Int64; NewValue: Int64; Comparand: Int64) : Int64; [public,alias:'FPC_ATOMIC_CMP_XCHG_64'];
begin
{$ifdef FPC_WASM_THREADS}
Result:=Int64(fpc_wasm32_i64_atomic_rmw_cmpxchg_u(@Target,QWord({$ifdef VER3_2}Comperand{$else}Comparand{$endif}),LongWord(NewValue)));
{$else FPC_WASM_THREADS}
Result:=Target;
if Target={$ifdef VER3_2}Comperand{$else}Comparand{$endif} then
Target:=NewValue;
{$endif FPC_WASM_THREADS}
end;
{$endif VER3_2}
{$ifdef VER3_2} {$ifdef VER3_2}
function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint;