mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2026-07-05 18:41:21 +00:00
Add a non-blocking `spin_trylock()` function to the existing spinlock implementation. This API attempts to acquire the lock and returns `1` on success or `0` if the lock is already held. It enables conditional locking scenarios where blocking is undesirable. Change-Id: I9483206952d1a34dc245ebf69e80c3645b658946 Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
39 lines
732 B
C
39 lines
732 B
C
/*
|
|
* Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef SPINLOCK_H
|
|
#define SPINLOCK_H
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
typedef struct spinlock {
|
|
volatile uint32_t lock;
|
|
} spinlock_t;
|
|
|
|
typedef struct bitlock {
|
|
volatile uint8_t lock;
|
|
} bitlock_t;
|
|
|
|
void spin_lock(spinlock_t *lock);
|
|
void spin_unlock(spinlock_t *lock);
|
|
|
|
void bit_lock(bitlock_t *lock, uint8_t mask);
|
|
void bit_unlock(bitlock_t *lock, uint8_t mask);
|
|
|
|
bool spin_trylock(spinlock_t *lock);
|
|
|
|
#else
|
|
|
|
/* Spin lock definitions for use in assembly */
|
|
#define SPINLOCK_ASM_ALIGN 2
|
|
#define SPINLOCK_ASM_SIZE 4
|
|
|
|
#endif /* __ASSEMBLER__ */
|
|
#endif /* SPINLOCK_H */
|