X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fvlc_atomic.h;h=af88eabb5e7af12d38e78ae972db728d496aa68f;hb=f5235164c53588314b4a4f67109cd0035d5fb35b;hp=037c639c11fd0e5a86ef106721ec73e94f4206c1;hpb=5ff29f804f88b805c0862032832be7fc1a5d02d6;p=vlc diff --git a/include/vlc_atomic.h b/include/vlc_atomic.h index 037c639c11..af88eabb5e 100644 --- a/include/vlc_atomic.h +++ b/include/vlc_atomic.h @@ -57,6 +57,18 @@ * unsigned equivalents, i.e. 4-bytes and 8-bytes types, although GCC also * supports 1 and 2-bytes types. Some non-x86 architectures do not support * 8-byte atomic types (or not efficiently). */ +# if defined (_MSC_VER) +/* Some atomic operations of the Interlocked API are only + available for desktop apps. Thus we define the atomic types to + be at least 32 bits wide. */ +typedef int_least32_t atomic_flag; +typedef int_least32_t atomic_bool; +typedef int_least32_t atomic_char; +typedef int_least32_t atomic_schar; +typedef uint_least32_t atomic_uchar; +typedef int_least32_t atomic_short; +typedef uint_least32_t atomic_ushort; +# else typedef bool atomic_flag; typedef bool atomic_bool; typedef char atomic_char; @@ -64,6 +76,7 @@ typedef signed char atomic_schar; typedef unsigned char atomic_uchar; typedef short atomic_short; typedef unsigned short atomic_ushort; +# endif typedef int atomic_int; typedef unsigned int atomic_uint; typedef long atomic_long; @@ -311,20 +324,20 @@ typedef uintmax_t atomic_uintmax_t; /* Define macros in order to dispatch to the correct function depending on the type. Several ranges are need because some operations are not implemented for all types. */ # define atomic_type_dispatch_32_64(operation, object, ...) \ - (sizeof(*object) == 4 ? operation(object, __VA_ARGS__) : \ - sizeof(*object) == 8 ? operation##64(object, __VA_ARGS__) : \ - (abort(), 0)) + (sizeof(*object) == 4 ? operation((LONG *)object, __VA_ARGS__) : \ + sizeof(*object) == 8 ? operation##64((LONGLONG *)object, __VA_ARGS__) : \ + (abort(), 0)) # define atomic_type_dispatch_16_64(operation, object, ...) \ - (sizeof(*object) == 2 ? operation##16(object, __VA_ARGS__) : \ - atomic_type_dispatch_32_64(operation, object, __VA_ARGS__)) + (sizeof(*object) == 2 ? operation##16((short *)object, __VA_ARGS__) : \ + atomic_type_dispatch_32_64(operation, object, __VA_ARGS__)) # define atomic_type_dispatch_8_64(operation, object, ...) \ - (sizeof(*object) == 1 ? operation##8(object, __VA_ARGS__) : \ - atomic_type_dispatch_16_64(operation, object, __VA_ARGS__)) + (sizeof(*object) == 1 ? operation##8((char *)object, __VA_ARGS__) : \ + atomic_type_dispatch_16_64(operation, object, __VA_ARGS__)) # define atomic_store(object,desired) \ - atomic_type_dispatch_8_64(InterlockedExchange, object, desired) + atomic_type_dispatch_16_64(InterlockedExchange, object, desired) # define atomic_store_explicit(object,desired,order) \ atomic_store(object, desired) @@ -334,12 +347,12 @@ typedef uintmax_t atomic_uintmax_t; atomic_load(object) # define atomic_exchange(object,desired) \ - atomic_type_dispatch_8_64(InterlockedExchange, object, desired) + atomic_type_dispatch_16_64(InterlockedExchange, object, desired) # define atomic_exchange_explicit(object,desired,order) \ atomic_exchange(object, desired) # define atomic_compare_exchange_strong(object,expected,desired) \ - atomic_type_dispatch_16_64(InterlockedCompareExchange, object, expected, desired) == expected + atomic_type_dispatch_16_64(InterlockedCompareExchange, object, *expected, desired) == *expected # define atomic_compare_exchange_strong_explicit(object,expected,desired,order) \ atomic_compare_exchange_strong(object, expected, desired) # define atomic_compare_exchange_weak(object,expected,desired) \ @@ -353,7 +366,7 @@ typedef uintmax_t atomic_uintmax_t; atomic_fetch_add(object, operand) # define atomic_fetch_sub(object,operand) \ - atomic_type_dispatch_32_64(InterlockedExchangeAdd, object, -operand) + atomic_type_dispatch_32_64(InterlockedExchangeAdd, object, -(LONGLONG)operand) # define atomic_fetch_sub_explicit(object,operand,order) \ atomic_fetch_sub(object, operand)