1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2016, Linaro Limited 4 */ 5 6 #include <assert.h> 7 #include <compiler.h> 8 #include <kernel/spinlock.h> 9 #include "thread_private.h" 10 spinlock_count_incr(void)11void spinlock_count_incr(void) 12 { 13 struct thread_core_local *l = thread_get_core_local(); 14 15 l->locked_count++; 16 assert(l->locked_count); 17 } 18 spinlock_count_decr(void)19void spinlock_count_decr(void) 20 { 21 struct thread_core_local *l = thread_get_core_local(); 22 23 assert(l->locked_count); 24 l->locked_count--; 25 } 26 have_spinlock(void)27bool __nostackcheck have_spinlock(void) 28 { 29 struct thread_core_local *l; 30 31 if (!thread_foreign_intr_disabled()) { 32 /* 33 * Normally we can't be holding a spinlock since doing so would 34 * imply foreign interrupts are disabled (or the spinlock 35 * logic is flawed). 36 */ 37 return false; 38 } 39 40 l = thread_get_core_local(); 41 42 return !!l->locked_count; 43 } 44