summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2021-10-26 09:53:25 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-10-26 12:44:01 +0300
commit8d9639790ca5ab1a7f7ffe52ba1d47b3616e3af1 (patch)
tree7fd2f931d7420dc0790a6200dabb61331428e148 /src
parent5bb694c2618c88752fb13c6b0c15715b9ca487d9 (diff)
downloadlibatomic_ops-8d9639790ca5ab1a7f7ffe52ba1d47b3616e3af1.tar.gz
Fix test_and_set for MS VC if char is unsigned
(fix of commit eb83b6186) Also, "truncation from AO_BYTE_TS_val to CHAR" compiler warning is eliminated. * src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800 && (!_M_ARM || _M_ARM>=6)] (AO_test_and_set_full): Cast AO_TS_SET to AO_TS_t (before passing to the argument of char type); apply &0xff to the result instead of cast to unsigned char; add comment. * src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800 && (_M_ARM>=6 || _M_ARM64)] (AO_test_and_set, AO_test_and_set_acquire, AO_test_and_set_release): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/atomic_ops/sysdeps/msftc/common32_defs.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/atomic_ops/sysdeps/msftc/common32_defs.h b/src/atomic_ops/sysdeps/msftc/common32_defs.h
index 646eaf3..ece41f7 100644
--- a/src/atomic_ops/sysdeps/msftc/common32_defs.h
+++ b/src/atomic_ops/sysdeps/msftc/common32_defs.h
@@ -1155,8 +1155,11 @@
AO_INLINE AO_TS_VAL_t
AO_test_and_set_full(volatile AO_TS_t *addr)
{
- return (AO_TS_VAL_t)((unsigned char)_InterlockedExchange8(
- (char volatile *)addr, AO_TS_SET));
+ return (AO_TS_VAL_t)(_InterlockedExchange8((char volatile *)addr,
+ (AO_TS_t)AO_TS_SET) & 0xff);
+ /* Note: bitwise "and 0xff" is applied to the result because cast */
+ /* to unsigned char does not work properly (for a reason) if /J */
+ /* option is passed to the MS VC compiler. */
}
# define AO_HAVE_test_and_set_full
# endif /* !_M_ARM || _M_ARM >= 6 */
@@ -1169,24 +1172,24 @@
AO_INLINE AO_TS_VAL_t
AO_test_and_set(volatile AO_TS_t *addr)
{
- return (AO_TS_VAL_t)((unsigned char)_InterlockedExchange8_nf(
- (char volatile *)addr, AO_TS_SET));
+ return (AO_TS_VAL_t)(_InterlockedExchange8_nf((char volatile *)addr,
+ (AO_TS_t)AO_TS_SET) & 0xff);
}
# define AO_HAVE_test_and_set
AO_INLINE AO_TS_VAL_t
AO_test_and_set_acquire(volatile AO_TS_t *addr)
{
- return (AO_TS_VAL_t)((unsigned char)_InterlockedExchange8_acq(
- (char volatile *)addr, AO_TS_SET));
+ return (AO_TS_VAL_t)(_InterlockedExchange8_acq((char volatile *)addr,
+ (AO_TS_t)AO_TS_SET) & 0xff);
}
# define AO_HAVE_test_and_set_acquire
AO_INLINE AO_TS_VAL_t
AO_test_and_set_release(volatile AO_TS_t *addr)
{
- return (AO_TS_VAL_t)((unsigned char)_InterlockedExchange8_rel(
- (char volatile *)addr, AO_TS_SET));
+ return (AO_TS_VAL_t)(_InterlockedExchange8_rel((char volatile *)addr,
+ (AO_TS_t)AO_TS_SET) & 0xff);
}
# define AO_HAVE_test_and_set_release
# endif /* _M_ARM >= 6 || _M_ARM64 */