/usr/include/diet/sys/atomic.h is in dietlibc-dev 0.33~cvs20120325-6+deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #ifndef _SYS_ATOMIC_H
#define _SYS_ATOMIC_H
#include <stddef.h>
/* this file defines __CAS (compare and swap) and __atomic_add */
#ifdef __arm__
/* The situation with atomic instructions on ARM is horrible.
* So much so that the Linux kernel is offering an undocumented
* interface for a cmpxchg emulation that works on the current kernel.
* You reach it by jumping to the address 0xffff0fc0 */
typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
#define CAS(ptr,oldval,newval) __kernel_cmpxchg(oldval,newval,ptr)
#else
#if defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1))
/* recent gcc versions and the intel compiler have built-ins for this */
#define __CAS(ptr,oldval,newval) __sync_val_compare_and_swap(ptr,oldval,newval)
#else
/* This function does this, atomically:
if (*ptr == oldval) {
*ptr=newval;
return oldval;
} else
return *ptr;
It can be used to implement lock-free data structures or locking
primitives.
*/
size_t __CAS(size_t* ptr,size_t oldval,size_t newval);
#if (defined(__sparc__) && !defined(__arch64__)) || defined(__hppa__)
#define NO_CAS
#endif
#endif
#endif
#if defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1))
#define __atomic_add(ptr,val) __sync_fetch_and_add(ptr,val)
#else
static inline size_t __atomic_add(size_t* ptr,size_t val) {
size_t r,o;
do {
r=__CAS(ptr,(o=*ptr),*ptr+val);
} while (r!=o);
return r;
}
#endif
#endif
|