Function gdal_sys::CPLAtomicAdd

source ·
pub unsafe extern "C" fn CPLAtomicAdd(
    ptr: *mut c_int,
    increment: c_int
) -> c_int
Expand description

Add a value to a pointed integer in a thread and SMP-safe way and return the resulting value of the operation.

This function, which in most cases is implemented by a few efficient machine instructions, guarantees that the value pointed by ptr will be incremented in a thread and SMP-safe way. The variables for this function must be aligned on a 32-bit boundary.

Depending on the platforms, this function can also act as a memory barrier, but this should not be assumed.

Current platforms/architectures where an efficient implementation exists are MacOSX, MS Windows, i386/x86_64 with GCC and platforms supported by GCC 4.1 or higher. For other platforms supporting the pthread library, and when GDAL is configured with thread-support, the atomicity will be done with a mutex, but with reduced efficiency. For the remaining platforms, a simple addition with no locking will be done…

@param ptr a pointer to an integer to increment @param increment the amount to add to the pointed integer @return the pointed value AFTER the result of the addition