Atomic Operations Interface


SILC Atomic operations interface provides utility functions to perform simple operations with integers atomically. This enables fast integer additions and subtractions safely in multithreaded environment. It is especially suited for reference counters and similar and is much faster than using locking. This interface supports 8, 16 and 32 bit integers and 32 or 64 bit pointers.

On some platforms this interface actually use mutual exclusion lock instead of true atomic operations, leading into some performace penalty. Also on some platforms the 8 and 16 bit integers are actually 32 bit integers.

Fast operations are supported on: x86, x86_64, ia64, PPC


 SilcAtomic32 refcnt;

 // Initialize atomic variable
 silc_atomic_init32(&refcnt, 0);

 // Increment referene counter by one
 silc_atomic_add_int32(&refcnt, 1);

 // Uninitialize atomic variable