From: Oliver Kurth Date: Thu, 8 Feb 2018 00:39:25 +0000 (-0800) Subject: Common header file change not applicable to open-vm-tools. X-Git-Tag: stable-10.3.0~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25d00050c8009dd74e3bbcf1883fdd408411a693;p=thirdparty%2Fopen-vm-tools.git Common header file change not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/vm_atomic.h b/open-vm-tools/lib/include/vm_atomic.h index 94eaf1d31..887d042d0 100644 --- a/open-vm-tools/lib/include/vm_atomic.h +++ b/open-vm-tools/lib/include/vm_atomic.h @@ -2910,6 +2910,50 @@ Atomic_TestBit64(Atomic_uint64 *var, // IN } +/* + *----------------------------------------------------------------------------- + * + * Atomic_TestSetBit64 -- + * + * Atomically test and set the bit 'bit' in var. + * Bit must be between 0 and 63. + * + * Results: + * TRUE if the tested bit was set; else FALSE. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static INLINE Bool +Atomic_TestSetBit64(Atomic_uint64 *var, // IN/OUT + unsigned bit) // IN +{ +#if defined __x86_64__ && defined __GNUC__ + Bool out; + ASSERT(bit <= 63); + __asm__ __volatile__( + "lock; btsq %2, %1; setc %0" + : "=rm" (out), "+m" (var->value) + : "rJ" ((uint64)bit) + : "cc" + ); + return out; +#else + uint64 oldVal; + uint64 mask; + ASSERT(bit <= 63); + mask = CONST64U(1) << bit; + do { + oldVal = var->value; + } while (!Atomic_CMPXCHG64(var, oldVal, oldVal | mask)); + return (oldVal & mask) != 0; +#endif +} + + #if defined __GNUC__ /* *-----------------------------------------------------------------------------