1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_SEQMUTEX_H
3 #define _BCACHEFS_SEQMUTEX_H
5 #include <linux/mutex.h>
12 #define seqmutex_init(_lock) mutex_init(&(_lock)->lock)
14 static inline bool seqmutex_trylock(struct seqmutex
*lock
)
16 return mutex_trylock(&lock
->lock
);
19 static inline void seqmutex_lock(struct seqmutex
*lock
)
21 mutex_lock(&lock
->lock
);
25 static inline u32
seqmutex_unlock(struct seqmutex
*lock
)
28 mutex_unlock(&lock
->lock
);
32 static inline bool seqmutex_relock(struct seqmutex
*lock
, u32 seq
)
34 if (lock
->seq
!= seq
|| !mutex_trylock(&lock
->lock
))
37 if (lock
->seq
!= seq
) {
38 mutex_unlock(&lock
->lock
);
45 #endif /* _BCACHEFS_SEQMUTEX_H */