]> git.sesse.net Git - ffmpeg/commitdiff
compat/atomics: add typecasts in atomic_compare_exchange_strong()
authorWan-Teh Chang <wtc@google.com>
Sat, 3 Dec 2016 00:56:16 +0000 (16:56 -0800)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Thu, 8 Dec 2016 20:53:58 +0000 (15:53 -0500)
The Solaris and Windows emulations of atomic_compare_exchange_strong()
need typecasts to avoid compiler warnings, because the functions they
call expect a void* pointer but an intptr_t integer is passed.

Note that the emulations of atomic_compare_exchange_strong() (except
the gcc version) only work for atomic_intptr_t because of the type of
the second argument (|expected|). See
http://en.cppreference.com/w/c/atomic:

_Bool atomic_compare_exchange_strong( volatile A* obj,
                                      C* expected, C desired );

The types of the first argument and second argument are different
(|A| and |C|, respectively). |C| is the non-atomic type corresponding
to |A|. In the emulations of atomic_compare_exchange_strong(), |C| is
intptr_t. This implies |A| can only be sig_intptr_t.

Signed-off-by: Wan-Teh Chang <wtc@google.com>
compat/atomics/suncc/stdatomic.h
compat/atomics/win32/stdatomic.h

index 32129aae5377a81e04cc031b5c2ed465df5f20e3..aef498d022c685eded5a91a31f98ba8252a82e20 100644 (file)
@@ -108,7 +108,7 @@ static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *exp
                                                  intptr_t desired)
 {
     intptr_t  old = *expected;
-    *expected = atomic_cas_ptr(object, old, desired);
+    *expected = (intptr_t)atomic_cas_ptr(object, (void *)old, (void *)desired);
     return *expected == old;
 }
 
index bdd39337a3d11008e07755276865412736f317f7..9cfdaa523ffbd0681ed802841b1209962cfd5df4 100644 (file)
@@ -104,7 +104,8 @@ static inline int atomic_compare_exchange_strong(intptr_t *object, intptr_t *exp
                                                  intptr_t desired)
 {
     intptr_t old = *expected;
-    *expected = InterlockedCompareExchangePointer(object, desired, old);
+    *expected = (intptr_t)InterlockedCompareExchangePointer(
+        (PVOID *)object, (PVOID)desired, (PVOID)old);
     return *expected == old;
 }