mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
fa20edc44d
- Remove most __ASSEMBLER__ __LINKER__ ifdefs - Rename libc/intrin/bits.h to libc/serialize.h - Block pthread cancelation in fchmodat() polyfill - Remove `clang-format off` statements in third_party
25 lines
1.3 KiB
C
25 lines
1.3 KiB
C
#ifndef COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
|
|
#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
|
|
#include "libc/intrin/asmflag.h"
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
|
|
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
|
|
({ \
|
|
bool32 DidIt; \
|
|
autotype(IFTHING) IfThing = (IFTHING); \
|
|
typeof(*IfThing) IsEqualToMe = (ISEQUALTOME); \
|
|
typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME); \
|
|
asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1") \
|
|
: ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
|
|
: "r"(ReplaceItWithMe) \
|
|
: "cc"); \
|
|
DidIt; \
|
|
})
|
|
#else
|
|
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
|
|
(*(IFTHING) == (ISEQUALTOME) ? (*(IFTHING) = (REPLACEITWITHME), 1) : 0)
|
|
#endif
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_ */
|