diff options
author | Peter Zijlstra <peterz@infradead.org> | 2023-05-26 12:23:48 +0200 |
---|---|---|
committer | Peter Zijlstra <peterz@infradead.org> | 2023-06-26 11:14:18 +0200 |
commit | 54da6a0924311c7cf5015533991e44fb8eb12773 (patch) | |
tree | af497256995d40431b9c214e7faa45639bf3d991 /include/linux/mutex.h | |
parent | 9a1f37ebcfe061721564042254719dc8fd5c9fa0 (diff) | |
download | lwn-54da6a0924311c7cf5015533991e44fb8eb12773.tar.gz lwn-54da6a0924311c7cf5015533991e44fb8eb12773.zip |
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
Diffstat (limited to 'include/linux/mutex.h')
-rw-r--r-- | include/linux/mutex.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/include/linux/mutex.h b/include/linux/mutex.h index 8f226d460f51..a33aa9eb9fc3 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -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 */ |