Fix IA-32 testandset(), make spinlock_t volatile int.

This commit is contained in:
gbeauche 2004-01-06 15:05:35 +00:00
parent 5f52e637b1
commit 9f745bd142

View File

@ -219,7 +219,7 @@ static inline uint64 tswap64(uint64 x) { return bswap_64(x); }
#ifdef __powerpc__ #ifdef __powerpc__
#define HAVE_TEST_AND_SET 1 #define HAVE_TEST_AND_SET 1
static inline int testandset(int *p) static inline int testandset(volatile int *p)
{ {
int ret; int ret;
__asm__ __volatile__("0: lwarx %0,0,%1 ;" __asm__ __volatile__("0: lwarx %0,0,%1 ;"
@ -237,14 +237,14 @@ static inline int testandset(int *p)
#ifdef __i386__ #ifdef __i386__
#define HAVE_TEST_AND_SET 1 #define HAVE_TEST_AND_SET 1
static inline int testandset(int *p) static inline int testandset(volatile int *p)
{ {
char ret; int ret;
long int readval; long int readval;
/* Note: the "xchg" instruction does not need a "lock" prefix */
__asm__ __volatile__("lock; cmpxchgl %3, %1; sete %0" __asm__ __volatile__("xchgl %0, %1"
: "=q" (ret), "=m" (*p), "=a" (readval) : "=r" (ret), "=m" (*p), "=a" (readval)
: "r" (1), "m" (*p), "a" (0) : "0" (1), "m" (*p)
: "memory"); : "memory");
return ret; return ret;
} }
@ -252,7 +252,7 @@ static inline int testandset(int *p)
#ifdef __s390__ #ifdef __s390__
#define HAVE_TEST_AND_SET 1 #define HAVE_TEST_AND_SET 1
static inline int testandset(int *p) static inline int testandset(volatile int *p)
{ {
int ret; int ret;
@ -267,7 +267,7 @@ static inline int testandset(int *p)
#ifdef __alpha__ #ifdef __alpha__
#define HAVE_TEST_AND_SET 1 #define HAVE_TEST_AND_SET 1
static inline int testandset(int *p) static inline int testandset(volatile int *p)
{ {
int ret; int ret;
unsigned long one; unsigned long one;
@ -287,7 +287,7 @@ static inline int testandset(int *p)
#ifdef __sparc__ #ifdef __sparc__
#define HAVE_TEST_AND_SET 1 #define HAVE_TEST_AND_SET 1
static inline int testandset(int *p) static inline int testandset(volatile int *p)
{ {
int ret; int ret;
@ -302,7 +302,7 @@ static inline int testandset(int *p)
#ifdef __arm__ #ifdef __arm__
#define HAVE_TEST_AND_SET 1 #define HAVE_TEST_AND_SET 1
static inline int testandset(int *p) static inline int testandset(volatile int *p)
{ {
register unsigned int ret; register unsigned int ret;
__asm__ __volatile__("swp %0, %1, [%2]" __asm__ __volatile__("swp %0, %1, [%2]"
@ -317,7 +317,7 @@ static inline int testandset(int *p)
#if HAVE_TEST_AND_SET #if HAVE_TEST_AND_SET
#define HAVE_SPINLOCKS 1 #define HAVE_SPINLOCKS 1
typedef int spinlock_t; typedef volatile int spinlock_t;
static const spinlock_t SPIN_LOCK_UNLOCKED = 0; static const spinlock_t SPIN_LOCK_UNLOCKED = 0;