parent
b3db5ee364
commit
148962dbc4
1 changed files with 43 additions and 7 deletions
|
@ -67,6 +67,7 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// In MSVC, correct alignment of each type is already ensured.
|
||||
#define _Atomic(T) struct { T __val; }
|
||||
|
@ -191,7 +192,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedCompareExchange64((LONGLONG *) object, desired, *expected); \
|
||||
break; \
|
||||
|
@ -201,7 +202,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedCompareExchange16((SHORT *) object, desired, *expected); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedCompareExchange8((char *) object, desired, *expected); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_compare_exchange_strong"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
@ -214,7 +220,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedExchange64((LONGLONG *) object, desired); \
|
||||
break; \
|
||||
|
@ -224,7 +230,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedExchange16((SHORT *) object, desired); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedExchange8((char *) object, desired); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_exchange_strong"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
@ -234,7 +245,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedExchangeAdd64((LONGLONG *) object, operand); \
|
||||
break; \
|
||||
|
@ -244,7 +255,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedExchangeAdd16((SHORT *) object, operand); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedExchangeAdd8((char *) object, operand); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_fetch_add"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
@ -254,7 +270,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedAnd64((LONGLONG *) object, operand); \
|
||||
break; \
|
||||
|
@ -264,7 +280,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedAnd16((SHORT *) object, operand); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedAnd8((char *) object, operand); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_fetch_and"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
@ -274,7 +295,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedOr64((LONGLONG *) object, operand); \
|
||||
break; \
|
||||
|
@ -284,7 +305,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedOr16((SHORT *) object, operand); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedOr8((char *) object, operand); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_fetch_or"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
@ -297,7 +323,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedXor64((LONGLONG *) object, operand); \
|
||||
break; \
|
||||
|
@ -307,7 +333,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedXor16((SHORT *) object, operand); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedXor8((char *) object, operand); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_fetch_xor"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
@ -317,7 +348,7 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
__pragma(warning(push)) \
|
||||
__pragma(warning(disable: 4244)) \
|
||||
do { \
|
||||
switch (sizeof(object)) { \
|
||||
switch (sizeof(out)) { \
|
||||
case sizeof(uint64_t): \
|
||||
out = _InterlockedExchangeAdd64((LONGLONG *) object, 0); \
|
||||
break; \
|
||||
|
@ -327,7 +358,12 @@ typedef _Atomic (uintmax_t) atomic_uintmax_t;
|
|||
case sizeof(uint16_t): \
|
||||
out = _InterlockedExchangeAdd16((SHORT *) object, 0); \
|
||||
break; \
|
||||
case sizeof(uint8_t): \
|
||||
out = _InterlockedExchangeAdd8((char *) object, 0); \
|
||||
break; \
|
||||
default: \
|
||||
fprintf(stderr, "Unsupported integer type in atomic_load"); \
|
||||
exit(-1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue