Date: Sun, 17 May 2020 20:09:11 +0000 (UTC) From: Emmanuel Vadot <manu@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361138 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <202005172009.04HK9B68064776@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: manu Date: Sun May 17 20:09:11 2020 New Revision: 361138 URL: https://svnweb.freebsd.org/changeset/base/361138 Log: linuxkpi: Add atomic_dec_and_mutex_lock This function decrement the counter and if the result is 0 it acquires the mutex and returns 1, if not it simply returns 0. Needed by DRM from Linux v5.3 Sponsored-by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24847 Modified: head/sys/compat/linuxkpi/common/include/linux/mutex.h Modified: head/sys/compat/linuxkpi/common/include/linux/mutex.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/mutex.h Sun May 17 15:32:36 2020 (r361137) +++ head/sys/compat/linuxkpi/common/include/linux/mutex.h Sun May 17 20:09:11 2020 (r361138) @@ -37,6 +37,7 @@ #include <sys/sx.h> #include <linux/spinlock.h> +#include <asm/atomic.h> typedef struct mutex { struct sx sx; @@ -123,6 +124,16 @@ static inline bool mutex_is_owned(mutex_t *m) { return (sx_xlocked(&m->sx)); +} + +static inline int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *m) +{ + if (atomic_dec_and_test(cnt)) { + mutex_lock(m); + return (1); + } + + return (0); } #ifdef WITNESS_ALL
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005172009.04HK9B68064776>