--- src/sys/sys/spinlock.h 2005/09/16 20:55:44 1.2 +++ src/sys/sys/spinlock.h 2005/09/16 21:50:13 1.3 @@ -32,14 +32,8 @@ * $DragonFly$ */ -#ifndef _SPINLOCK_H_ -#define _SPINLOCK_H_ - -#ifdef _KERNEL -#include -#include -#include -#endif +#ifndef _SYS_SPINLOCK_H_ +#define _SYS_SPINLOCK_H_ /* * Note that the spinlock structure is retained whether we are SMP or not, @@ -50,76 +44,5 @@ struct spinlock { volatile int lock; /* 0 = unlocked, 1 = locked */ }; -#ifdef SMP - -static __inline boolean_t -spin_trylock(struct spinlock *mtx) -{ - if (atomic_swap_int(&mtx->lock, 1) == 0) - return (TRUE); - return (FALSE); -} - -extern void spin_lock_contested(struct spinlock *mtx); - -static __inline void -spin_lock(struct spinlock *mtx) -{ - if (atomic_swap_int(&mtx->lock, 1) != 0) - spin_lock_contested(mtx); /* slow path */ -} - -static __inline void -spin_unlock(struct spinlock *mtx) -{ - cpu_sfence(); - mtx->lock = 0; /* non-bus-locked lock release */ -} - -static __inline boolean_t -spin_is_locked(struct spinlock *mtx) -{ - return (mtx->lock); -} - -static __inline void -spin_init(struct spinlock *mtx) -{ - mtx->lock = 0; -} - -#else /* SMP */ - -static __inline boolean_t -spin_trylock(struct spinlock *mtx) -{ - return (TRUE); -} - -static __inline boolean_t -spin_is_locked(struct spinlock *mtx) -{ - return (FALSE); -} - -static __inline void spin_lock(struct spinlock *mtx) { } -static __inline void spin_unlock(struct spinlock *mtx) { } -static __inline void spin_init(struct spinlock *mtx) { } - -#endif /* SMP */ - -static __inline void -spin_lock_crit(struct spinlock *mtx) -{ - crit_enter(); - spin_lock(mtx); -} - -static __inline void -spin_unlock_crit(struct spinlock *mtx) -{ - spin_unlock(mtx); - crit_exit(); -} - #endif +