2022-04-12 12:20:17 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_BITS_LOCKXADD_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_BITS_LOCKXADD_H_
|
2022-04-07 07:15:35 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2022-04-12 12:20:17 +00:00
|
|
|
intptr_t _lockxadd(void *, intptr_t, size_t);
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
2022-04-07 07:15:35 +00:00
|
|
|
#define _lockxadd(PTR, VAL) \
|
|
|
|
({ \
|
|
|
|
typeof(*(PTR)) Res; \
|
|
|
|
typeof(Res) Val = (VAL); \
|
|
|
|
asm volatile("lock xadd\t%0,%1" : "=r"(Res), "+m"(*(PTR)) : "0"(Val)); \
|
|
|
|
Res; /* contains *PTR before addition cf. InterlockedAdd() */ \
|
|
|
|
})
|
2022-04-12 12:20:17 +00:00
|
|
|
#else
|
|
|
|
#define _lockxadd(MEM, VAL) _lockxadd(MEM, (intptr_t)(VAL), sizeof(*(MEM)))
|
|
|
|
#endif /* GNUC && !ANSI && x86 */
|
2022-04-07 07:15:35 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
2022-04-12 12:20:17 +00:00
|
|
|
#endif /* COSMOPOLITAN_LIBC_BITS_LOCKXADD_H_ */
|