InterlockedIncrement_() Error

Just starting out? Need help? Post your questions and find answers here.
AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

InterlockedIncrement_() Error

Post by AndyMK »

Is there a way to use

Code: Select all

InterlockedIncrement_()
in Purebasic? I get
Error. referenced by Purebasic.obj:(WinMain)
User avatar
idle
Always Here
Always Here
Posts: 5835
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: InterlockedIncrement_() Error

Post 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) 

AndyMK
Enthusiast
Enthusiast
Posts: 582
Joined: Wed Jul 12, 2006 4:38 pm
Location: UK

Re: InterlockedIncrement_() Error

Post by AndyMK »

Thanks idle. What's the difference between the two macros?

Ah ok, the second one is for pointer variables?
User avatar
idle
Always Here
Always Here
Posts: 5835
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: InterlockedIncrement_() Error

Post by idle »

No for private vars asm backend
Post Reply