Added try_acquire_spinlock().

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42180 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2011-06-14 12:41:11 +00:00
parent 4cc4f7bb18
commit dc3ba981d4
2 changed files with 41 additions and 3 deletions
+14 -3
View File
@@ -41,6 +41,8 @@ typedef void (*smp_call_func)(uint32 data1, int32 currentCPU, uint32 data2, uint
extern "C" {
#endif
bool try_acquire_spinlock(spinlock* lock);
status_t smp_init(struct kernel_args *args);
status_t smp_per_cpu_init(struct kernel_args *args, int32 cpu);
status_t smp_init_post_generic_syscalls(void);
@@ -71,10 +73,18 @@ int smp_intercpu_int_handler(int32 cpu);
// {acquire,release}_spinlock().
#if !DEBUG_SPINLOCKS && !B_DEBUG_SPINLOCK_CONTENTION
static inline bool
try_acquire_spinlock_inline(spinlock* lock)
{
return atomic_or((int32*)lock, 1) == 0;
}
static inline void
acquire_spinlock_inline(spinlock* lock)
{
if (atomic_or((int32*)lock, 1) == 0)
if (try_acquire_spinlock_inline(lock))
return;
acquire_spinlock(lock);
}
@@ -87,8 +97,9 @@ release_spinlock_inline(spinlock* lock)
}
#define acquire_spinlock(lock) acquire_spinlock_inline(lock)
#define release_spinlock(lock) release_spinlock_inline(lock)
#define try_acquire_spinlock(lock) try_acquire_spinlock_inline(lock)
#define acquire_spinlock(lock) acquire_spinlock_inline(lock)
#define release_spinlock(lock) release_spinlock_inline(lock)
#endif // !DEBUG_SPINLOCKS && !B_DEBUG_SPINLOCK_CONTENTION
+27
View File
@@ -41,6 +41,7 @@
#endif
#undef try_acquire_spinlock
#undef acquire_spinlock
#undef release_spinlock
@@ -292,6 +293,32 @@ process_all_pending_ici(int32 currentCPU)
}
bool
try_acquire_spinlock(spinlock* lock)
{
#if DEBUG_SPINLOCKS
if (are_interrupts_enabled()) {
panic("try_acquire_spinlock: attempt to acquire lock %p with "
"interrupts enabled", lock);
}
#endif
#if B_DEBUG_SPINLOCK_CONTENTION
if (atomic_add(&lock->lock, 1) != 0)
return false;
#else
if (atomic_or((int32*)lock, 1) != 0)
return false;
# if DEBUG_SPINLOCKS
push_lock_caller(arch_debug_get_caller(), lock);
# endif
#endif
return true;
}
void
acquire_spinlock(spinlock* lock)
{