mirror of
https://github.com/holub/mame
synced 2025-04-20 15:32:45 +03:00
remove asm part for atomic implementations (nw)
This commit is contained in:
parent
0b4723c8cc
commit
91d965d80c
@ -285,193 +285,6 @@ _count_leading_ones(UINT32 value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE SYNCHRONIZATION FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange32 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define compare_exchange32 _compare_exchange32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"1: lwarx %[result], 0, %[ptr] \n"
|
||||
" cmpw %[compare], %[result] \n"
|
||||
" bne 2f \n"
|
||||
" stwcx. %[exchange], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
" lwsync \n"
|
||||
"2: "
|
||||
: [dummy] "+m" (*ptr) /* Lets GCC know that *ptr will be read/written in case it's not marked volatile */
|
||||
, [result] "=&r" (result)
|
||||
: [ptr] "r" (ptr)
|
||||
, [exchange] "r" (exchange)
|
||||
, [compare] "r" (compare)
|
||||
: "cr0"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange64 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#if defined(__ppc64__) || defined(__PPC64__)
|
||||
#define compare_exchange64 _compare_exchange64
|
||||
static inline INT64 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
|
||||
{
|
||||
INT64 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"1: ldarx %[result], 0, %[ptr] \n"
|
||||
" cmpd %[compare], %[result] \n"
|
||||
" bne 2f \n"
|
||||
" stdcx. %[exchange], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
" lwsync \n"
|
||||
"2: "
|
||||
: [dummy] "+m" (*ptr) /* Lets GCC know that *ptr will be read/written in case it's not marked volatile */
|
||||
, [result] "=&r" (result)
|
||||
: [ptr] "r" (ptr)
|
||||
, [exchange] "r" (exchange)
|
||||
, [compare] "r" (compare)
|
||||
: "cr0"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_exchange32 - atomically exchange the
|
||||
exchange value with the memory at 'ptr',
|
||||
returning the original value.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_exchange32 _atomic_exchange32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"1: lwarx %[result], 0, %[ptr] \n"
|
||||
" stwcx. %[exchange], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
" lwsync \n"
|
||||
: [dummy] "+m" (*ptr) /* Lets GCC know that *ptr will be read/written in case it's not marked volatile */
|
||||
, [result] "=&r" (result)
|
||||
: [ptr] "r" (ptr)
|
||||
, [exchange] "r" (exchange)
|
||||
: "cr0"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_add32 - atomically add the delta value
|
||||
to the memory at 'ptr', returning the final
|
||||
result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_add32 _atomic_add32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_add32(INT32 volatile *ptr, INT32 delta)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"1: lwarx %[result], 0, %[ptr] \n"
|
||||
" add %[result], %[result], %[delta] \n"
|
||||
" stwcx. %[result], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
" lwsync \n"
|
||||
: [dummy] "+m" (*ptr) /* Lets GCC know that *ptr will be read/written in case it's not marked volatile */
|
||||
, [result] "=&b" (result)
|
||||
: [ptr] "r" (ptr)
|
||||
, [delta] "r" (delta)
|
||||
: "cr0"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_increment32 - atomically increment the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_increment32 _atomic_increment32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_increment32(INT32 volatile *ptr)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"1: lwarx %[result], 0, %[ptr] \n"
|
||||
" addi %[result], %[result], 1 \n"
|
||||
" stwcx. %[result], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
" lwsync \n"
|
||||
: [dummy] "+m" (*ptr) /* Lets GCC know that *ptr will be read/written in case it's not marked volatile */
|
||||
, [result] "=&b" (result)
|
||||
: [ptr] "r" (ptr)
|
||||
: "cr0"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_decrement32 - atomically decrement the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_decrement32 _atomic_decrement32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_decrement32(INT32 volatile *ptr)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"1: lwarx %[result], 0, %[ptr] \n"
|
||||
" addi %[result], %[result], -1 \n"
|
||||
" stwcx. %[result], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
" lwsync \n"
|
||||
: [dummy] "+m" (*ptr) /* Lets GCC know that *ptr will be read/written in case it's not marked volatile */
|
||||
, [result] "=&b" (result)
|
||||
: [ptr] "r" (ptr)
|
||||
: "cr0"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE TIMING FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
@ -521,162 +521,6 @@ _count_leading_ones(UINT32 value)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE SYNCHRONIZATION FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange32 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define compare_exchange32 _compare_exchange32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" lock ; cmpxchgl %[exchange], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [result] "=a" (result)
|
||||
: [compare] "1" (compare)
|
||||
, [exchange] "q" (exchange)
|
||||
: "cc"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange64 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define compare_exchange64 _compare_exchange64
|
||||
static inline INT64 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
|
||||
{
|
||||
INT64 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" lock ; cmpxchgq %[exchange], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [result] "=a" (result)
|
||||
: [compare] "1" (compare)
|
||||
, [exchange] "q" (exchange)
|
||||
: "cc"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_exchange32 - atomically exchange the
|
||||
exchange value with the memory at 'ptr',
|
||||
returning the original value.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_exchange32 _atomic_exchange32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
|
||||
{
|
||||
INT32 result;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" lock ; xchgl %[exchange], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [result] "=r" (result)
|
||||
: [exchange] "1" (exchange)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_add32 - atomically add the delta value
|
||||
to the memory at 'ptr', returning the final
|
||||
result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_add32 _atomic_add32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_add32(INT32 volatile *ptr, INT32 delta)
|
||||
{
|
||||
INT32 result = delta;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" lock ; xaddl %[result], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [result] "+r" (result)
|
||||
:
|
||||
: "cc"
|
||||
);
|
||||
|
||||
return result + delta;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_increment32 - atomically increment the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_increment32 _atomic_increment32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_increment32(INT32 volatile *ptr)
|
||||
{
|
||||
INT32 result = 1;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" lock ; xaddl %[result], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [result] "+r" (result)
|
||||
:
|
||||
: "cc"
|
||||
);
|
||||
|
||||
return result + 1;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_decrement32 - atomically decrement the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#define atomic_decrement32 _atomic_decrement32
|
||||
static inline INT32 ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_atomic_decrement32(INT32 volatile *ptr)
|
||||
{
|
||||
INT32 result = -1;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" lock ; xaddl %[result], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [result] "+r" (result)
|
||||
:
|
||||
: "cc"
|
||||
);
|
||||
|
||||
return result - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE TIMING FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
110
src/osd/eivc.h
110
src/osd/eivc.h
@ -20,19 +20,9 @@
|
||||
#pragma warning(pop)
|
||||
|
||||
#else
|
||||
extern "C" long __cdecl _InterlockedIncrement(long volatile *);
|
||||
extern "C" long __cdecl _InterlockedDecrement(long volatile *);
|
||||
extern "C" long _InterlockedExchange(long volatile *, long);
|
||||
extern "C" long _InterlockedCompareExchange (long volatile *, long, long);
|
||||
extern "C" long _InterlockedExchangeAdd(long volatile *, long);
|
||||
extern "C" unsigned char _BitScanReverse(unsigned long *Index, unsigned long Mask);
|
||||
#endif
|
||||
|
||||
#pragma intrinsic(_InterlockedIncrement)
|
||||
#pragma intrinsic(_InterlockedDecrement)
|
||||
#pragma intrinsic(_InterlockedCompareExchange)
|
||||
#pragma intrinsic(_InterlockedExchange)
|
||||
#pragma intrinsic(_InterlockedExchangeAdd)
|
||||
#if (_MSC_VER >= 1310)
|
||||
#pragma intrinsic(_BitScanReverse)
|
||||
#endif
|
||||
@ -71,104 +61,4 @@ static inline UINT8 _count_leading_ones(UINT32 value)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE SYNCHRONIZATION FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange32 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef compare_exchange32
|
||||
#define compare_exchange32 _compare_exchange32
|
||||
static inline INT32 _compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
|
||||
{
|
||||
return _InterlockedCompareExchange((volatile long *)ptr, exchange, compare);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange64 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifdef PTR64
|
||||
#ifndef compare_exchange64
|
||||
#define compare_exchange64 _compare_exchange64
|
||||
static inline INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
|
||||
{
|
||||
return _InterlockedCompareExchange64(ptr, exchange, compare);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_exchange32 - atomically exchange the
|
||||
exchange value with the memory at 'ptr',
|
||||
returning the original value.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_exchange32
|
||||
#define atomic_exchange32 _atomic_exchange32
|
||||
static inline INT32 _atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
|
||||
{
|
||||
return _InterlockedExchange((volatile long *)ptr, exchange);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_add32 - atomically add the delta value
|
||||
to the memory at 'ptr', returning the final
|
||||
result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_add32
|
||||
#define atomic_add32 _atomic_add32
|
||||
static inline INT32 _atomic_add32(INT32 volatile *ptr, INT32 delta)
|
||||
{
|
||||
return _InterlockedExchangeAdd((volatile long *)ptr, delta) + delta;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_increment32 - atomically increment the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_increment32
|
||||
#define atomic_increment32 _atomic_increment32
|
||||
static inline INT32 _atomic_increment32(INT32 volatile *ptr)
|
||||
{
|
||||
return _InterlockedIncrement((volatile long *)ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_decrement32 - atomically decrement the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_decrement32
|
||||
#define atomic_decrement32 _atomic_decrement32
|
||||
static inline INT32 _atomic_decrement32(INT32 volatile *ptr)
|
||||
{
|
||||
return _InterlockedDecrement((volatile long *)ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __EIVC__ */
|
||||
|
@ -16,61 +16,6 @@
|
||||
/* we come with implementations for GCC x86 and PPC */
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
//============================================================
|
||||
// osd_exchange64
|
||||
//============================================================
|
||||
|
||||
static inline INT64 ATTR_UNUSED ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_osd_exchange64(INT64 volatile *ptr, INT64 exchange)
|
||||
{
|
||||
INT64 ret;
|
||||
__asm__ __volatile__ (
|
||||
" lock ; xchg %[exchange], %[ptr] ;"
|
||||
: [ptr] "+m" (*ptr)
|
||||
, [ret] "=r" (ret)
|
||||
: [exchange] "1" (exchange)
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
#define osd_exchange64 _osd_exchange64
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
||||
|
||||
#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__)
|
||||
|
||||
|
||||
#if defined(__ppc64__) || defined(__PPC64__)
|
||||
|
||||
//============================================================
|
||||
// osd_exchange64
|
||||
//============================================================
|
||||
|
||||
static inline INT64 ATTR_UNUSED ATTR_NONNULL(1) ATTR_FORCE_INLINE
|
||||
_osd_exchange64(INT64 volatile *ptr, INT64 exchange)
|
||||
{
|
||||
INT64 ret;
|
||||
__asm__ __volatile__ (
|
||||
"1: ldarx %[ret], 0, %[ptr] \n"
|
||||
" stdcx. %[exchange], 0, %[ptr] \n"
|
||||
" bne- 1b \n"
|
||||
: [ret] "=&r" (ret)
|
||||
: [ptr] "r" (ptr)
|
||||
, [exchange] "r" (exchange)
|
||||
: "cr0"
|
||||
);
|
||||
return ret;
|
||||
}
|
||||
#define osd_exchange64 _osd_exchange64
|
||||
|
||||
#endif /* __ppc64__ || __PPC64__ */
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#include "eigccx86.h"
|
||||
#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__)
|
||||
@ -89,33 +34,6 @@ _osd_exchange64(INT64 volatile *ptr, INT64 exchange)
|
||||
|
||||
#include "eivc.h"
|
||||
|
||||
INT32 win_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange);
|
||||
INT32 win_atomic_exchange32(INT32 volatile *ptr, INT32 exchange);
|
||||
INT32 win_atomic_add32(INT32 volatile *ptr, INT32 delta);
|
||||
|
||||
#ifdef PTR64
|
||||
INT64 win_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange);
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef compare_exchange32
|
||||
#define compare_exchange32 win_compare_exchange32
|
||||
#endif /* compare_exchange32 */
|
||||
|
||||
#ifdef PTR64
|
||||
#ifndef compare_exchange64
|
||||
#define compare_exchange64 win_compare_exchange64
|
||||
#endif /* compare_exchange64 */
|
||||
#endif
|
||||
|
||||
#ifndef atomic_exchange32
|
||||
#define atomic_exchange32 win_atomic_exchange32
|
||||
#endif /* atomic_exchange32 */
|
||||
|
||||
|
||||
#ifndef atomic_add32
|
||||
#define atomic_add32 win_atomic_add32
|
||||
#endif /* atomic_add32 */
|
||||
#else
|
||||
|
||||
#error "no matching assembler implementations found - please compile with NOASM=1"
|
||||
@ -375,160 +293,6 @@ static inline UINT8 count_leading_ones(UINT32 val)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE SYNCHRONIZATION FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange32 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
|
||||
Note that the default implementation does
|
||||
no synchronization. You MUST override this
|
||||
in osinline.h for it to be useful in a
|
||||
multithreaded environment!
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef compare_exchange32
|
||||
static inline INT32 compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
|
||||
{
|
||||
INT32 oldval = *ptr;
|
||||
if (*ptr == compare)
|
||||
*ptr = exchange;
|
||||
return oldval;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange64 - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
|
||||
Note that the default implementation does
|
||||
no synchronization. You MUST override this
|
||||
in osinline.h for it to be useful in a
|
||||
multithreaded environment!
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifdef PTR64
|
||||
#ifndef compare_exchange64
|
||||
static inline INT64 compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
|
||||
{
|
||||
INT64 oldval = *ptr;
|
||||
if (*ptr == compare)
|
||||
*ptr = exchange;
|
||||
return oldval;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
compare_exchange_ptr - compare the 'compare'
|
||||
value against the memory at 'ptr'; if equal,
|
||||
swap in the 'exchange' value. Regardless,
|
||||
return the previous value at 'ptr'.
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef compare_exchange_ptr
|
||||
static inline void *compare_exchange_ptr(void * volatile *ptr, void *compare, void *exchange)
|
||||
{
|
||||
#ifdef PTR64
|
||||
INT64 result;
|
||||
result = compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange);
|
||||
#else
|
||||
INT32 result;
|
||||
result = compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange);
|
||||
#endif
|
||||
return (void *)result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_exchange32 - atomically exchange the
|
||||
exchange value with the memory at 'ptr',
|
||||
returning the original value.
|
||||
|
||||
Note that the default implementation does
|
||||
no synchronization. You MUST override this
|
||||
in osinline.h for it to be useful in a
|
||||
multithreaded environment!
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_exchange32
|
||||
static inline INT32 atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
|
||||
{
|
||||
INT32 oldval = *ptr;
|
||||
*ptr = exchange;
|
||||
return oldval;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_add32 - atomically add the delta value
|
||||
to the memory at 'ptr', returning the final
|
||||
result.
|
||||
|
||||
Note that the default implementation does
|
||||
no synchronization. You MUST override this
|
||||
in osinline.h for it to be useful in a
|
||||
multithreaded environment!
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_add32
|
||||
static inline INT32 atomic_add32(INT32 volatile *ptr, INT32 delta)
|
||||
{
|
||||
return (*ptr += delta);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_increment32 - atomically increment the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
|
||||
Note that the default implementation does
|
||||
no synchronization. You MUST override this
|
||||
in osinline.h for it to be useful in a
|
||||
multithreaded environment!
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_increment32
|
||||
static inline INT32 atomic_increment32(INT32 volatile *ptr)
|
||||
{
|
||||
return atomic_add32(ptr, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
atomic_decrement32 - atomically decrement the
|
||||
32-bit value in memory at 'ptr', returning the
|
||||
final result.
|
||||
|
||||
Note that the default implementation does
|
||||
no synchronization. You MUST override this
|
||||
in osinline.h for it to be useful in a
|
||||
multithreaded environment!
|
||||
-------------------------------------------------*/
|
||||
|
||||
#ifndef atomic_decrement32
|
||||
static inline INT32 atomic_decrement32(INT32 volatile *ptr)
|
||||
{
|
||||
return atomic_add32(ptr, -1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
INLINE TIMING FUNCTIONS
|
||||
***************************************************************************/
|
||||
|
@ -45,46 +45,6 @@ struct osd_thread {
|
||||
void *param;
|
||||
};
|
||||
|
||||
//============================================================
|
||||
// win_compare_exchange32
|
||||
//============================================================
|
||||
|
||||
INT32 win_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
|
||||
{
|
||||
return InterlockedCompareExchange((LPLONG)ptr, (LONG)exchange, (LONG)compare);
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// win_compare_exchange64
|
||||
//============================================================
|
||||
|
||||
#ifdef PTR64
|
||||
INT64 win_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
|
||||
{
|
||||
return InterlockedCompareExchange64((LONGLONG*)ptr, (LONGLONG)exchange, (LONGLONG)compare);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//============================================================
|
||||
// win_atomic_exchange32
|
||||
//============================================================
|
||||
|
||||
INT32 win_atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
|
||||
{
|
||||
return InterlockedExchange((LONG *) ptr, exchange);
|
||||
}
|
||||
|
||||
|
||||
//============================================================
|
||||
// win_atomic_add32
|
||||
//============================================================
|
||||
|
||||
INT32 win_atomic_add32(INT32 volatile *ptr, INT32 delta)
|
||||
{
|
||||
return InterlockedExchangeAdd((LONG *) ptr, delta) + delta;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
// osd_event_alloc
|
||||
|
Loading…
Reference in New Issue
Block a user