Page 1 of 1
InterlockedIncrement_() Error
Posted: Thu Feb 27, 2025 10:53 pm
by AndyMK
Is there a way to use
in Purebasic? I get
Error. referenced by Purebasic.obj:(WinMain)
Re: InterlockedIncrement_() Error
Posted: Thu Feb 27, 2025 11:17 pm
by idle
you can use this
Code: Select all
Macro _glockInc(var)
CompilerIf #PB_Compiler_Backend = #PB_Backend_C
! __atomic_fetch_add(&v_#var,1,__ATOMIC_SEQ_CST);
CompilerElse
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!lock add dword [v_#var],1
CompilerElse
!lock add qword [v_#var],1
CompilerEndIf
CompilerEndIf
EndMacro
Macro _plockInc(var)
CompilerIf #PB_Compiler_Backend = #PB_Backend_C
! __atomic_fetch_add(&v_#var,1,__ATOMIC_SEQ_CST);
CompilerElse
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!lock add dword [p.v_#var],1
CompilerElse
!lock add qword [p.v_#var],1
CompilerEndIf
CompilerEndIf
EndMacro
Procedure foo(x)
_plockInc(x)
Debug x
EndProcedure
x.i = 1
_glockInc(x)
Debug x
foo(x)
Re: InterlockedIncrement_() Error
Posted: Fri Feb 28, 2025 6:53 am
by AndyMK
Thanks idle. What's the difference between the two macros?
Ah ok, the second one is for pointer variables?
Re: InterlockedIncrement_() Error
Posted: Fri Feb 28, 2025 7:24 am
by idle
No for private vars asm backend