cleanup: Add conditional guard support
authorPeter Zijlstra <peterz@infradead.org>
Sun, 17 Sep 2023 11:22:17 +0000 (13:22 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 15 Nov 2023 09:15:33 +0000 (10:15 +0100)
commite4ab322fbaaaf84b23d6cb0e3317a7f68baf36dc
tree313aa91080f84450341fdab61d504a41e9b52d97
parentb85ea95d086471afb4ad062012a4d73cd328fa86
cleanup: Add conditional guard support

Adds:

 - DEFINE_GUARD_COND() / DEFINE_LOCK_GUARD_1_COND() to extend existing
   guards with conditional lock primitives, eg. mutex_trylock(),
   mutex_lock_interruptible().

   nb. both primitives allow NULL 'locks', which cause the lock to
       fail (obviously).

 - extends scoped_guard() to not take the body when the the
   conditional guard 'fails'. eg.

     scoped_guard (mutex_intr, &task->signal_cred_guard_mutex) {
...
     }

   will only execute the body when the mutex is held.

 - provides scoped_cond_guard(name, fail, args...); which extends
   scoped_guard() to do fail when the lock-acquire fails.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20231102110706.460851167%40infradead.org
include/linux/cleanup.h
include/linux/mutex.h
include/linux/rwsem.h
include/linux/spinlock.h