version 1.18.2.1, 2007/11/19 00:46:59 |
version 1.18.2.2, 2007/12/27 00:43:23 |
|
|
#ifndef _X86_LOCK_H_ |
#ifndef _X86_LOCK_H_ |
#define _X86_LOCK_H_ |
#define _X86_LOCK_H_ |
|
|
#ifdef _KERNEL |
|
#include <machine/cpufunc.h> |
|
#endif |
|
#include <machine/atomic.h> |
|
|
|
|
|
static __inline int |
static __inline int |
__SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr) |
__SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr) |
{ |
{ |
Line 75 __cpu_simple_lock_clear(__cpu_simple_loc |
|
Line 69 __cpu_simple_lock_clear(__cpu_simple_loc |
|
*__ptr = __SIMPLELOCK_UNLOCKED; |
*__ptr = __SIMPLELOCK_UNLOCKED; |
} |
} |
|
|
|
#ifdef _KERNEL |
|
|
|
#include <machine/cpufunc.h> |
|
|
|
void __cpu_simple_lock_init(__cpu_simple_lock_t *); |
|
void __cpu_simple_lock(__cpu_simple_lock_t *); |
|
int __cpu_simple_lock_try(__cpu_simple_lock_t *); |
|
void __cpu_simple_unlock(__cpu_simple_lock_t *); |
|
|
|
#define SPINLOCK_SPIN_HOOK /* nothing */ |
|
#define SPINLOCK_BACKOFF_HOOK x86_pause() |
|
|
|
#else |
|
|
static __inline void __cpu_simple_lock_init(__cpu_simple_lock_t *) |
static __inline void __cpu_simple_lock_init(__cpu_simple_lock_t *) |
__attribute__((__unused__)); |
__attribute__((__unused__)); |
static __inline void __cpu_simple_lock(__cpu_simple_lock_t *) |
static __inline void __cpu_simple_lock(__cpu_simple_lock_t *) |
Line 92 __cpu_simple_lock_init(__cpu_simple_lock |
|
Line 100 __cpu_simple_lock_init(__cpu_simple_lock |
|
__insn_barrier(); |
__insn_barrier(); |
} |
} |
|
|
static __inline void |
static __inline int |
__cpu_simple_lock(__cpu_simple_lock_t *lockp) |
__cpu_simple_lock_try(__cpu_simple_lock_t *lockp) |
{ |
{ |
|
uint8_t val; |
|
|
while (x86_atomic_testset_b(lockp, __SIMPLELOCK_LOCKED) |
val = __SIMPLELOCK_LOCKED; |
!= __SIMPLELOCK_UNLOCKED) { |
__asm volatile ("xchgb %0,(%2)" : |
do { |
"=r" (val) |
#ifdef _KERNEL |
:"0" (val), "r" (lockp)); |
x86_pause(); |
|
#endif /* _KERNEL */ |
|
} while (*lockp == __SIMPLELOCK_LOCKED); |
|
} |
|
__insn_barrier(); |
__insn_barrier(); |
|
return val == __SIMPLELOCK_UNLOCKED; |
} |
} |
|
|
static __inline int |
static __inline void |
__cpu_simple_lock_try(__cpu_simple_lock_t *lockp) |
__cpu_simple_lock(__cpu_simple_lock_t *lockp) |
{ |
{ |
int r = (x86_atomic_testset_b(lockp, __SIMPLELOCK_LOCKED) |
|
== __SIMPLELOCK_UNLOCKED); |
|
|
|
|
while (!__cpu_simple_lock_try(lockp)) |
|
/* nothing */; |
__insn_barrier(); |
__insn_barrier(); |
|
|
return (r); |
|
} |
} |
|
|
/* |
/* |
Line 178 __cpu_simple_unlock(__cpu_simple_lock_t |
|
Line 182 __cpu_simple_unlock(__cpu_simple_lock_t |
|
*lockp = __SIMPLELOCK_UNLOCKED; |
*lockp = __SIMPLELOCK_UNLOCKED; |
} |
} |
|
|
#define SPINLOCK_SPIN_HOOK /* nothing */ |
|
#define SPINLOCK_BACKOFF_HOOK x86_pause() |
|
|
|
#ifdef _KERNEL |
|
void mb_read(void); |
|
void mb_write(void); |
|
void mb_memory(void); |
|
#endif /* _KERNEL */ |
#endif /* _KERNEL */ |
|
|
#endif /* _X86_LOCK_H_ */ |
#endif /* _X86_LOCK_H_ */ |