[haiku-commits] r42180 - in haiku/trunk: headers/private/kernel src/system/kernel

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 14 Jun 2011 14:41:11 +0200 (CEST)

Author: bonefish
Date: 2011-06-14 14:41:11 +0200 (Tue, 14 Jun 2011)
New Revision: 42180
Changeset: https://dev.haiku-os.org/changeset/42180

Modified:
   haiku/trunk/headers/private/kernel/smp.h
   haiku/trunk/src/system/kernel/smp.cpp
Log:
Added try_acquire_spinlock().


Modified: haiku/trunk/headers/private/kernel/smp.h
===================================================================
--- haiku/trunk/headers/private/kernel/smp.h    2011-06-14 11:42:49 UTC (rev 
42179)
+++ haiku/trunk/headers/private/kernel/smp.h    2011-06-14 12:41:11 UTC (rev 
42180)
@@ -41,6 +41,8 @@
 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 @@
 // {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 @@
 }
 
 
-#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
 

Modified: haiku/trunk/src/system/kernel/smp.cpp
===================================================================
--- haiku/trunk/src/system/kernel/smp.cpp       2011-06-14 11:42:49 UTC (rev 
42179)
+++ haiku/trunk/src/system/kernel/smp.cpp       2011-06-14 12:41:11 UTC (rev 
42180)
@@ -41,6 +41,7 @@
 #endif
 
 
+#undef try_acquire_spinlock
 #undef acquire_spinlock
 #undef release_spinlock
 
@@ -292,6 +293,32 @@
 }
 
 
+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)
 {


Other related posts:

  • » [haiku-commits] r42180 - in haiku/trunk: headers/private/kernel src/system/kernel - ingo_weinhold