On Fri, Sep 10, 2021 at 01:40:48PM +0200, mwilck@xxxxxxxx wrote: > From: Martin Wilck <mwilck@xxxxxxxx> > > Have struct mutex_lock take an optional wakeup function. > unlock() is renamed to __unlock() in order to prevent it from > being called by mistake. > It might be worth it to make the waiter_lock into a regular pthread_mutex_t, since it doesn't need any special handling, but this change doesn't cause any problems with it, so Reviewed-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> > Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> > --- > libmultipath/libmultipath.version | 5 +++++ > libmultipath/lock.c | 12 +++++++++++- > libmultipath/lock.h | 6 +++++- > 3 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/libmultipath/libmultipath.version b/libmultipath/libmultipath.version > index c98cf7f..2107c51 100644 > --- a/libmultipath/libmultipath.version > +++ b/libmultipath/libmultipath.version > @@ -292,3 +292,8 @@ LIBMULTIPATH_9.1.0 { > global: > timespeccmp; > } LIBMULTIPATH_9.0.0; > + > +LIBMULTIPATH_9.2.0 { > +global: > + set_wakeup_fn; > +} LIBMULTIPATH_9.1.0; > diff --git a/libmultipath/lock.c b/libmultipath/lock.c > index 72c70e3..93b48db 100644 > --- a/libmultipath/lock.c > +++ b/libmultipath/lock.c > @@ -3,6 +3,16 @@ > void cleanup_lock (void * data) > { > struct mutex_lock *lock = data; > + wakeup_fn *fn = lock->wakeup; > > - unlock(lock); > + __unlock(lock); > + if (fn) > + fn(); > +} > + > +void set_wakeup_fn(struct mutex_lock *lck, wakeup_fn *fn) > +{ > + lock(lck); > + lck->wakeup = fn; > + __unlock(lck); > } > diff --git a/libmultipath/lock.h b/libmultipath/lock.h > index d99eedb..d7b779e 100644 > --- a/libmultipath/lock.h > +++ b/libmultipath/lock.h > @@ -3,8 +3,11 @@ > > #include <pthread.h> > > +typedef void (wakeup_fn)(void); > + > struct mutex_lock { > pthread_mutex_t mutex; > + wakeup_fn *wakeup; > }; > > static inline void lock(struct mutex_lock *a) > @@ -22,7 +25,7 @@ static inline int timedlock(struct mutex_lock *a, struct timespec *tmo) > return pthread_mutex_timedlock(&a->mutex, tmo); > } > > -static inline void unlock(struct mutex_lock *a) > +static inline void __unlock(struct mutex_lock *a) > { > pthread_mutex_unlock(&a->mutex); > } > @@ -30,5 +33,6 @@ static inline void unlock(struct mutex_lock *a) > #define lock_cleanup_pop(a) pthread_cleanup_pop(1) > > void cleanup_lock (void * data); > +void set_wakeup_fn(struct mutex_lock *lock, wakeup_fn *fn); > > #endif /* _LOCK_H */ > -- > 2.33.0 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel