mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 16:13:19 +09: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:
@@ -19,6 +19,7 @@
|
||||
#include <asm/processor.h>
|
||||
#include <linux/osq_lock.h>
|
||||
#include <linux/debug_locks.h>
|
||||
#include <linux/cleanup.h>
|
||||
|
||||
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
||||
# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
|
||||
@@ -219,4 +220,7 @@ extern void mutex_unlock(struct mutex *lock);
|
||||
|
||||
extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
|
||||
|
||||
DEFINE_GUARD(mutex, struct mutex *, mutex_lock(_T), mutex_unlock(_T))
|
||||
DEFINE_FREE(mutex, struct mutex *, if (_T) mutex_unlock(_T))
|
||||
|
||||
#endif /* __LINUX_MUTEX_H */
|
||||
|
||||
Reference in New Issue
Block a user