1 // © 2021 Qualcomm Innovation Center, Inc. All rights reserved. 2 // 3 // SPDX-License-Identifier: BSD-3-Clause 4 5 // Initialise a spinlock structure. 6 // 7 // This must be called exactly once for each lock, before any of the functions 8 // below are called. 9 void 10 spinlock_init(spinlock_t *lock); 11 12 // Acquire exclusive ownership of a lock, spinning indefinitely until it is 13 // acquired. Preemption will be disabled. 14 void 15 spinlock_acquire(spinlock_t *lock) ACQUIRE_SPINLOCK(lock); 16 17 // Attempt to immediately acquire exclusive ownership of a lock, and return true 18 // if it succeeds. If the lock is already exclusively held by another thread, 19 // return false with no side-effects. 20 // 21 // Preemption will be disabled if the lock is acquired. 22 bool 23 spinlock_trylock(spinlock_t *lock) TRY_ACQUIRE_SPINLOCK(true, lock); 24 25 // Release exclusive ownership of a lock. Preemption will be enabled. 26 void 27 spinlock_release(spinlock_t *lock) RELEASE_SPINLOCK(lock); 28 29 // As for spinlock_acquire(), but preemption must already be disabled and will 30 // not be disabled again. 31 void 32 spinlock_acquire_nopreempt(spinlock_t *lock) ACQUIRE_SPINLOCK_NP(lock); 33 34 // As for spinlock_trylock(), but preemption must already be disabled and will 35 // not be disabled again. 36 bool 37 spinlock_trylock_nopreempt(spinlock_t *lock) 38 TRY_ACQUIRE_SPINLOCK_NP(true, lock); 39 40 // As for spinlock_release(), but preemption will not be enabled. 41 void 42 spinlock_release_nopreempt(spinlock_t *lock) RELEASE_SPINLOCK_NP(lock); 43 44 // Assert that a specific spinlock is exclusively held by the caller. 45 // 46 // This might only be a static check, especially in non-debug builds. 47 void 48 assert_spinlock_held(const spinlock_t *lock) REQUIRE_LOCK(lock) 49 REQUIRE_PREEMPT_DISABLED; 50