mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 09:48:29 +00:00
parent
5e069a64d4
commit
d932948fb4
954 changed files with 1095 additions and 1342 deletions
25
libc/bits/xchg.internal.h
Normal file
25
libc/bits/xchg.internal.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_XCHG_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_XCHG_H_
|
||||
#include "libc/str/str.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* Exchanges *MEMORY into *LOCALVAR.
|
||||
*
|
||||
* @return *MEMORY
|
||||
* @see lockcmpxchg()
|
||||
* todo(jart): what's the point of this?
|
||||
*/
|
||||
#define xchg(MEMORY, LOCALVAR) \
|
||||
({ \
|
||||
autotype(MEMORY) Memory = (MEMORY); \
|
||||
typeof(Memory) LocalVar = (LOCALVAR); \
|
||||
typeof(*Memory) Temp; \
|
||||
memcpy(&Temp, Memory, sizeof(Temp)); \
|
||||
memcpy(Memory, LocalVar, sizeof(Temp)); \
|
||||
memcpy(LocalVar, &Temp, sizeof(Temp)); \
|
||||
Temp; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_XCHG_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue