atomic: __PHYSFS_ATOMIC_(DECR|INCR) should return final value.

Fixes #46.
This commit is contained in:
Ryan C. Gordon 2022-09-29 10:53:18 -04:00
parent ee956e0e5c
commit c743450d86
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
2 changed files with 6 additions and 5 deletions

View File

@ -99,8 +99,8 @@ static inline int __PHYSFS_atomicAdd(int *ptrval, const int val)
{
int retval;
__PHYSFS_platformGrabMutex(stateLock);
*ptrval += val;
retval = *ptrval;
*ptrval = retval + val;
__PHYSFS_platformReleaseMutex(stateLock);
return retval;
} /* __PHYSFS_atomicAdd */

View File

@ -109,14 +109,15 @@ const void *__PHYSFS_winrtCalcPrefDir(void);
#endif
/* atomic operations. */
/* increment/decrement operations return the final incremented/decremented value. */
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
#include <intrin.h>
__PHYSFS_COMPILE_TIME_ASSERT(LongEqualsInt, sizeof (int) == sizeof (long));
#define __PHYSFS_ATOMIC_INCR(ptrval) _InterlockedIncrement((long*)(ptrval))
#define __PHYSFS_ATOMIC_DECR(ptrval) _InterlockedDecrement((long*)(ptrval))
#elif defined(__clang__) || (defined(__GNUC__) && (((__GNUC__ * 10000) + (__GNUC_MINOR__ * 100)) >= 40100))
#define __PHYSFS_ATOMIC_INCR(ptrval) __sync_fetch_and_add(ptrval, 1)
#define __PHYSFS_ATOMIC_DECR(ptrval) __sync_fetch_and_add(ptrval, -1)
#define __PHYSFS_ATOMIC_INCR(ptrval) __sync_add_and_fetch(ptrval, 1)
#define __PHYSFS_ATOMIC_DECR(ptrval) __sync_add_and_fetch(ptrval, -1)
#elif defined(__WATCOMC__) && defined(__386__)
extern __inline int _xadd_watcom(volatile int *a, int v);
#pragma aux _xadd_watcom = \
@ -124,8 +125,8 @@ extern __inline int _xadd_watcom(volatile int *a, int v);
parm [ecx] [eax] \
value [eax] \
modify exact [eax];
#define __PHYSFS_ATOMIC_INCR(ptrval) _xadd_watcom(ptrval, 1)
#define __PHYSFS_ATOMIC_DECR(ptrval) _xadd_watcom(ptrval, -1)
#define __PHYSFS_ATOMIC_INCR(ptrval) (_xadd_watcom(ptrval, 1)+1)
#define __PHYSFS_ATOMIC_DECR(ptrval) (_xadd_watcom(ptrval, -1)-1)
#else
#define PHYSFS_NEED_ATOMIC_OP_FALLBACK 1
int __PHYSFS_ATOMIC_INCR(int *ptrval);