On 2/6/25 10:10 AM, Marco Elver wrote:
@@ -243,15 +243,18 @@ const volatile void * __must_check_fn(const volatile void *val) #define DEFINE_CLASS(_name, _type, _exit, _init, _init_args...) \ typedef _type class_##_name##_t; \ static inline void class_##_name##_destructor(_type *p) \ + __no_capability_analysis \ { _type _T = *p; _exit; } \ static inline _type class_##_name##_constructor(_init_args) \ + __no_capability_analysis \ { _type t = _init; return t; }
guard() uses the constructor and destructor functions defined by DEFINE_GUARD(). The DEFINE_GUARD() implementation uses DEFINE_CLASS(). Here is an example that I found in <linux/mutex.h>: DEFINE_GUARD(mutex, struct mutex *, mutex_lock(_T), mutex_unlock(_T)) For this example, how is the compiler told that mutex _T is held around the code protected by guard()? Thanks, Bart.