From 493bf919bd09ab9808130e7a59d5de3c0151cd2e Mon Sep 17 00:00:00 2001 From: biyu gong <872044@qq.com> Date: Wed, 14 Aug 2024 13:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9=20Windows?= =?UTF-8?q?=20XP=E7=B3=BB=E7=BB=9F,=20=E4=BD=BF=E7=94=A8vc141=5Fxp?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=B7=A5=E5=85=B7=E9=9B=86=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=80=9A=E8=BF=87.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/hatomic.h | 10 ++++++++-- event/wepoll/wepoll.c | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/base/hatomic.h b/base/hatomic.h index eea6a617f..0fbd24309 100644 --- a/base/hatomic.h +++ b/base/hatomic.h @@ -52,8 +52,14 @@ static inline bool atomic_flag_test_and_set(atomic_flag* p) { return InterlockedCompareExchange((LONG*)&p->_Value, 1, 0); } -#define ATOMIC_ADD InterlockedAdd -#define ATOMIC_SUB(p, n) InterlockedAdd(p, -n) +#if WINVER > 0x0600 + #define ATOMIC_ADD InterlockedAdd + #define ATOMIC_SUB(p, n) InterlockedAdd(p, -n) +#else + #define ATOMIC_ADD(p, n) (InterlockedExchangeAdd(p, n) + n) + #define ATOMIC_SUB(p, n) (InterlockedExchangeAdd(p, -n) - n) +#endif + #define ATOMIC_INC InterlockedIncrement #define ATOMIC_DEC InterlockedDecrement diff --git a/event/wepoll/wepoll.c b/event/wepoll/wepoll.c index 186d3f2d4..3b1a456e7 100644 --- a/event/wepoll/wepoll.c +++ b/event/wepoll/wepoll.c @@ -1552,7 +1552,11 @@ static void reflock__await_event(void* address) { } void reflock_ref(reflock_t* reflock) { +#if WINVER > 0x0600 long state = InterlockedAdd(&reflock->state, REFLOCK__REF); +#else + long state = InterlockedExchangeAdd(&reflock->state, REFLOCK__REF) + REFLOCK__REF; +#endif /* Verify that the counter didn't overflow and the lock isn't destroyed. */ assert((state & REFLOCK__DESTROY_MASK) == 0); @@ -1560,7 +1564,11 @@ void reflock_ref(reflock_t* reflock) { } void reflock_unref(reflock_t* reflock) { +#if WINVER > 0x0600 long state = InterlockedAdd(&reflock->state, -REFLOCK__REF); +#else + long state = InterlockedExchangeAdd(&reflock->state, -REFLOCK__REF) - REFLOCK__REF; +#endif /* Verify that the lock was referenced and not already destroyed. */ assert((state & REFLOCK__DESTROY_MASK & ~REFLOCK__DESTROY) == 0); @@ -1570,8 +1578,12 @@ void reflock_unref(reflock_t* reflock) { } void reflock_unref_and_destroy(reflock_t* reflock) { +#if WINVER > 0x0600 long state = InterlockedAdd(&reflock->state, REFLOCK__DESTROY - REFLOCK__REF); +#else + long state = InterlockedExchangeAdd(&reflock->state, REFLOCK__DESTROY - REFLOCK__REF) + (REFLOCK__DESTROY - REFLOCK__REF); +#endif long ref_count = state & REFLOCK__REF_MASK; /* Verify that the lock was referenced and not already destroyed. */