svn commit: r361138 - head/sys/compat/linuxkpi/common/include/linux
Emmanuel Vadot
manu at FreeBSD.org
Sun May 17 20:09:11 UTC 2020
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
More information about the svn-src-head
mailing list