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 spinlock_count_incr(void)10void spinlock_count_incr(void) 11 { 12 struct thread_core_local *l = thread_get_core_local(); 13 14 l->locked_count++; 15 assert(l->locked_count); 16 } 17 spinlock_count_decr(void)18void spinlock_count_decr(void) 19 { 20 struct thread_core_local *l = thread_get_core_local(); 21 22 assert(l->locked_count); 23 l->locked_count--; 24 } 25 have_spinlock(void)26bool __nostackcheck have_spinlock(void) 27 { 28 struct thread_core_local *l; 29 30 if (!thread_foreign_intr_disabled()) { 31 /* 32 * Normally we can't be holding a spinlock since doing so would 33 * imply foreign interrupts are disabled (or the spinlock 34 * logic is flawed). 35 */ 36 return false; 37 } 38 39 l = thread_get_core_local(); 40 41 return !!l->locked_count; 42 } 43