2021-08-05 22:26:29

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V3 15/64] rtmutex: Provide rt_mutex_base_is_locked()

Provide rt_mutex_base_is_locked() which will be used for various wrapped
locking primitives for RT.

Signed-off-by: Thomas Gleixner <[email protected]>
---
include/linux/rtmutex.h | 11 +++++++++++
1 file changed, 11 insertions(+)

--- a/include/linux/rtmutex.h
+++ b/include/linux/rtmutex.h
@@ -32,6 +32,17 @@ struct rt_mutex_base {
.owner = NULL \
}

+/**
+ * rt_mutex_base_is_locked - is the rtmutex locked
+ * @lock: the mutex to be queried
+ *
+ * Returns true if the mutex is locked, false if unlocked.
+ */
+static inline bool rt_mutex_base_is_locked(struct rt_mutex_base *lock)
+{
+ return lock->owner != NULL;
+}
+
extern void rt_mutex_base_init(struct rt_mutex_base *rtb);

/**


2021-08-08 20:43:53

by Davidlohr Bueso

[permalink] [raw]
Subject: Re: [patch V3 15/64] rtmutex: Provide rt_mutex_base_is_locked()

>+/**
>+ * rt_mutex_base_is_locked - is the rtmutex locked
>+ * @lock: the mutex to be queried
>+ *
>+ * Returns true if the mutex is locked, false if unlocked.
>+ */
>+static inline bool rt_mutex_base_is_locked(struct rt_mutex_base *lock)
>+{
>+ return lock->owner != NULL;

Does this want to be READ_ONCE()? While not a big deal because
it's ultimately only used by drm debugging, I don't see any harm
in avoiding potential tearing.

Thanks,
Davidlohr

2021-08-09 11:58:37

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [patch V3 15/64] rtmutex: Provide rt_mutex_base_is_locked()

On Sun, Aug 08 2021 at 13:41, Davidlohr Bueso wrote:
>>+/**
>>+ * rt_mutex_base_is_locked - is the rtmutex locked
>>+ * @lock: the mutex to be queried
>>+ *
>>+ * Returns true if the mutex is locked, false if unlocked.
>>+ */
>>+static inline bool rt_mutex_base_is_locked(struct rt_mutex_base *lock)
>>+{
>>+ return lock->owner != NULL;
>
> Does this want to be READ_ONCE()? While not a big deal because
> it's ultimately only used by drm debugging, I don't see any harm
> in avoiding potential tearing.

Makes sense.