123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #ifndef _PT_MACHINE_H
- #define _PT_MACHINE_H 1
- #include <features.h>
- #ifndef __ASSEMBLER__
- #ifndef PT_EI
- # define PT_EI __extern_always_inline __attribute__((visibility("hidden")))
- #endif
- extern long int testandset (int *spinlock);
- extern int __compare_and_swap (long int *p, long int oldval, long int newval);
- #define CURRENT_STACK_FRAME __builtin_frame_address (0)
- #if defined __GNUC__ && __GNUC__ >= 2 && \
- (defined __i486__ || defined __pentium__ || defined __pentiumpro__ || defined __pentium4__ || \
- defined __athlon__ || defined __k8__)
- PT_EI long int
- testandset (int *spinlock)
- {
- long int ret;
- __asm__ __volatile__ (
- "xchgl %0, %1"
- : "=r" (ret), "=m" (*spinlock)
- : "0" (1), "m" (*spinlock)
- : "memory");
- return ret;
- }
- #define HAS_COMPARE_AND_SWAP
- PT_EI int
- __compare_and_swap (long int *p, long int oldval, long int newval)
- {
- char ret;
- long int readval;
- __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
- : "=q" (ret), "=m" (*p), "=a" (readval)
- : "r" (newval), "m" (*p), "a" (oldval)
- : "memory");
- return ret;
- }
- #if defined(__ASSUME_LDT_WORKS) && __ASSUME_LDT_WORKS > 0
- #include "useldt.h"
- #endif
- #define BUSY_WAIT_NOP __asm__ ("rep; nop")
- #else
- extern int compare_and_swap_is_available (void);
- PT_EI long int
- testandset (int *spinlock)
- {
- long int ret;
- __asm__ __volatile__(
- "xchgl %0, %1"
- : "=r"(ret), "=m"(*spinlock)
- : "0"(1), "m"(*spinlock)
- : "memory");
- return ret;
- }
- #define HAS_COMPARE_AND_SWAP
- #define TEST_FOR_COMPARE_AND_SWAP
- PT_EI int
- __compare_and_swap (long int *p, long int oldval, long int newval)
- {
- char ret;
- long int readval;
- __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
- : "=q" (ret), "=m" (*p), "=a" (readval)
- : "r" (newval), "m" (*p), "a" (oldval)
- : "memory");
- return ret;
- }
- PT_EI int
- compare_and_swap_is_available (void)
- {
- int changed;
- int oldflags;
-
- __asm__ __volatile__ ("pushfl; popl %0" : "=r" (oldflags) : );
-
- __asm__ __volatile__ ("pushl %0; popfl" : : "r" (oldflags ^ 0x40000) : "cc");
-
- __asm__ __volatile__ ("pushfl; popl %0" : "=r" (changed) : );
-
- changed = (changed ^ oldflags) & 0x40000;
-
- __asm__ __volatile__ ("pushl %0; popfl" : : "r" (oldflags) : "cc");
-
- return changed != 0;
- }
- #endif
- #endif
- #endif
|