kernel: add functions to lock/unlock a pair of locks without saving irq flags

This commit is contained in:
2026-03-14 22:25:15 +00:00
parent 115a2e7415
commit 62bdb51618
2 changed files with 38 additions and 18 deletions

View File

@@ -22,6 +22,32 @@ typedef __aligned(8) ml_hwlock_t spin_lock_t;
#define spin_unlock_irqrestore(lck, flags) \
ml_hwlock_unlock_irqrestore(lck, flags);
static inline void spin_lock_pair(spin_lock_t *a, spin_lock_t *b)
{
if (a == b) {
spin_lock(a);
} else if (a < b) {
spin_lock(a);
spin_lock(b);
} else {
spin_lock(b);
spin_lock(a);
}
}
static inline void spin_unlock_pair(spin_lock_t *a, spin_lock_t *b)
{
if (a == b) {
spin_unlock(a);
} else if (a < b) {
spin_unlock(b);
spin_unlock(a);
} else {
spin_unlock(a);
spin_unlock(b);
}
}
static inline void spin_lock_pair_irqsave(
spin_lock_t *a,
spin_lock_t *b,

View File

@@ -180,20 +180,22 @@ void object_unlock_irqrestore(struct object *obj, unsigned long flags)
spin_unlock_irqrestore(&obj->ob_lock, flags);
}
void object_lock_pair(struct object *a, struct object *b)
{
spin_lock_pair(&a->ob_lock, &b->ob_lock);
}
void object_unlock_pair(struct object *a, struct object *b)
{
spin_unlock_pair(&a->ob_lock, &b->ob_lock);
}
void object_lock_pair_irqsave(
struct object *a,
struct object *b,
unsigned long *flags)
{
if (a == b) {
object_lock_irqsave(a, flags);
} else if (a < b) {
object_lock_irqsave(a, flags);
object_lock(b);
} else {
object_lock_irqsave(b, flags);
object_lock(a);
}
spin_lock_pair_irqsave(&a->ob_lock, &b->ob_lock, flags);
}
void object_unlock_pair_irqrestore(
@@ -201,15 +203,7 @@ void object_unlock_pair_irqrestore(
struct object *b,
unsigned long flags)
{
if (a == b) {
object_unlock_irqrestore(a, flags);
} else if (a < b) {
object_unlock(b);
object_unlock_irqrestore(a, flags);
} else {
object_unlock(a);
object_unlock_irqrestore(b, flags);
}
spin_unlock_pair_irqrestore(&a->ob_lock, &b->ob_lock, flags);
}
void *object_data(struct object *obj)