+static inline void
+bfd_lock (bfd_main_t * bm)
+{
+ uword my_thread_index = __os_thread_index;
+
+ if (bm->owner_thread_index == my_thread_index
+ && bm->lock_recursion_count > 0)
+ {
+ bm->lock_recursion_count++;
+ return;
+ }
+
+ clib_spinlock_lock_if_init (&bm->lock);
+ bm->lock_recursion_count = 1;
+ bm->owner_thread_index = my_thread_index;
+}
+
+static inline void
+bfd_unlock (bfd_main_t * bm)
+{
+ uword my_thread_index = __os_thread_index;
+ ASSERT (bm->owner_thread_index == my_thread_index);
+
+ if (bm->lock_recursion_count > 1)
+ {
+ bm->lock_recursion_count--;
+ return;
+ }
+ bm->lock_recursion_count = 0;
+ bm->owner_thread_index = ~0;
+ clib_spinlock_unlock_if_init (&bm->lock);
+}
+
+static inline void
+bfd_lock_check (bfd_main_t * bm)
+{
+ if (PREDICT_FALSE (bm->lock_recursion_count < 1))
+ clib_warning ("lock check failure");
+}
+