Harlequin RIP SDK

Spinlocks implemented using atomic operations. More...

#include "platform.h"
#include "hqatomic.h"
#include "hqwindows.h"

Macros

#define yield_processor()   (void)SwitchToThread()
 Yield the processor to another thread, if there is one runnable.
 
#define spinlock_pointer(addr_, locked_, count_)
 Lock a pointer using atomic operations. More...
 
#define spinlock_pointer_incomplete(addr_, locked_, count_)
 Lock a pointer using atomic operations. More...
 
#define spintrylock_pointer(addr_, locked_, didlock_)
 Try to lock a pointer using atomic operations. More...
 
#define spinunlock_pointer(addr_, unlocked_)
 Unlock a pointer using atomic operations. More...
 
#define spinunlock_pointer_incomplete(addr_, unlocked_)
 Unlock a pointer using atomic operations. More...
 
#define spin_pointer_without_lock(ptr_, uptr_)
 Get the value of a potentially spinlocked pointer in its unlocked state. More...
 
#define spin_pointer_incomplete_without_lock(ptr_, uptr_)
 Get the value of a potentially spinlocked pointer in its unlocked state. More...
 
#define spinlock_counter(addr_, count_)
 Lock a counter semaphore using atomic operations. More...
 
#define spinunlock_counter(addr_)
 Unlock a semaphore counter using atomic operations. More...
 
#define spinlock_counter_bits(addr_, bits_, count_)
 Lock a sharded counter lock using atomic operations. More...
 
#define spintrylock_counter_bits(addr_, bits_, didlock_)
 Try to lock a sharded counter using atomic operations. More...
 
#define spinunlock_counter_bits(addr_, bits_)
 Unlock a sharded counter using atomic operations. More...
 
#define spinlock_counter_R(addr_, count_)
 Lock a read-write counter lock for reading using atomic operations. More...
 
#define spintrylock_counter_R(addr_, didlock_)
 Try to lock a read-write counter lock for reading using atomic operations. More...
 
#define spinunlock_counter_R(addr_)
 Unlock a read-write counter currently locked for reading using atomic operations. More...
 
#define spinlock_counter_W(addr_, count_)
 Lock a read-write counter lock for writing using atomic operations. More...
 
#define spintrylock_counter_W(addr_, didlock_)
 Try to lock a read-write counter lock for writing using atomic operations. More...
 
#define spinunlock_counter_W(addr_)
 Unlock a read-write counter currently locked for writing using atomic operations. More...
 
#define spinlock_counter_WtoR(addr_, count_)
 Convert a read-write counter lock from writing to reading using atomic operations. More...
 
#define spintrylock_counter_RtoW(addr_, didlock_)
 Try to convert a read-write counter lock from reading to writing using atomic operations. More...
 

Typedefs

typedef void * __attribute__((__may_alias__)) spinlock_void_ptr
 Aliased void pointer, to quieten GCC warnings and prevent harmful optimisations.
 

Enumerations

enum  {
  HQSPIN_YIELD_NEVER = 0 , HQSPIN_YIELD_ALWAYS = 1 , HQSPIN_YIELD_OFTEN = 100 , HQSPIN_YIELD_SOMETIMES = 1000 ,
  HQSPIN_YIELD_RARELY = 10000
}
 Constants for yields per spinlock cycle. If the spinlock is held for a short time on average, it's worth burning a little more effort trying to get it and avoiding a context switch. Spinlocks should not be used for cases where mutexes are practicable. More...
 

Detailed Description

Spinlocks implemented using atomic operations.

Copyright (C) 2024 Global Graphics Software Ltd. All rights reserved. This source code contains the confidential and trade secret information of Global Graphics Software Ltd. It may not be used, copied or distributed for any reason except as set forth in the applicable Global Graphics license agreement.

These spinlocks are implemented in a separate file because they include platform-specific header files to yield the processor in the event of a contended spinlock