mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
locking: Introduce __cleanup() based infrastructure
Use __attribute__((__cleanup__(func))) to build: - simple auto-release pointers using __free() - 'classes' with constructor and destructor semantics for scope-based resource management. - lock guards based on the above classes. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20230612093537.614161713%40infradead.org
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
#include <linux/stringify.h>
|
||||
#include <linux/bottom_half.h>
|
||||
#include <linux/lockdep.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <asm/barrier.h>
|
||||
#include <asm/mmiowb.h>
|
||||
|
||||
@@ -502,5 +503,35 @@ int __alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask,
|
||||
|
||||
void free_bucket_spinlocks(spinlock_t *locks);
|
||||
|
||||
DEFINE_LOCK_GUARD_1(raw_spinlock, raw_spinlock_t,
|
||||
raw_spin_lock(_T->lock),
|
||||
raw_spin_unlock(_T->lock))
|
||||
|
||||
DEFINE_LOCK_GUARD_1(raw_spinlock_nested, raw_spinlock_t,
|
||||
raw_spin_lock_nested(_T->lock, SINGLE_DEPTH_NESTING),
|
||||
raw_spin_unlock(_T->lock))
|
||||
|
||||
DEFINE_LOCK_GUARD_1(raw_spinlock_irq, raw_spinlock_t,
|
||||
raw_spin_lock_irq(_T->lock),
|
||||
raw_spin_unlock_irq(_T->lock))
|
||||
|
||||
DEFINE_LOCK_GUARD_1(raw_spinlock_irqsave, raw_spinlock_t,
|
||||
raw_spin_lock_irqsave(_T->lock, _T->flags),
|
||||
raw_spin_unlock_irqrestore(_T->lock, _T->flags),
|
||||
unsigned long flags)
|
||||
|
||||
DEFINE_LOCK_GUARD_1(spinlock, spinlock_t,
|
||||
spin_lock(_T->lock),
|
||||
spin_unlock(_T->lock))
|
||||
|
||||
DEFINE_LOCK_GUARD_1(spinlock_irq, spinlock_t,
|
||||
spin_lock_irq(_T->lock),
|
||||
spin_unlock_irq(_T->lock))
|
||||
|
||||
DEFINE_LOCK_GUARD_1(spinlock_irqsave, spinlock_t,
|
||||
spin_lock_irqsave(_T->lock, _T->flags),
|
||||
spin_unlock_irqrestore(_T->lock, _T->flags),
|
||||
unsigned long flags)
|
||||
|
||||
#undef __LINUX_INSIDE_SPINLOCK_H
|
||||
#endif /* __LINUX_SPINLOCK_H */
|
||||
|
Reference in New Issue
Block a user