All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Alchemy: Fix rt_task_unblock() for RT_MUTEX
@ 2022-03-30 20:16 Richard Weinberger
  2022-03-31  8:25 ` Bezdeka, Florian
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Richard Weinberger @ 2022-03-30 20:16 UTC (permalink / raw)
  To: xenomai; +Cc: Richard Weinberger

Starting with Xenomai 3, RT_MUTEX is based on libcobalt's pthread mutex
implementation.
POSIX requires that pthread_mutex_lock() shall not return EINTR,
this requirement breaks rt_task_unblock() if a RT_TASK blocks on
a RT_MUTEX.

To restore the functionality provide a new function, pthread_mutex_lock_eintr_np().
It can get interrupted and will return EINTR to the caller.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 include/cobalt/pthread.h |  2 ++
 lib/alchemy/mutex.c      |  2 +-
 lib/cobalt/mutex.c       | 14 ++++++++++++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 3e9bd47053bc..2994c2467219 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -62,6 +62,8 @@ COBALT_DECL(int, pthread_mutex_destroy(pthread_mutex_t *mutex));
 
 COBALT_DECL(int, pthread_mutex_lock(pthread_mutex_t *mutex));
 
+COBALT_DECL(int, pthread_mutex_lock_eintr_np(pthread_mutex_t *mutex));
+
 COBALT_DECL(int, pthread_mutex_timedlock(pthread_mutex_t *mutex,
 					 const struct timespec *to));
 
diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c
index f8933858647a..bb97395142aa 100644
--- a/lib/alchemy/mutex.c
+++ b/lib/alchemy/mutex.c
@@ -327,7 +327,7 @@ int rt_mutex_acquire_timed(RT_MUTEX *mutex,
 
 	/* Slow path. */
 	if (abs_timeout == NULL) {
-		ret = -__RT(pthread_mutex_lock(&mcb->lock));
+		ret = -__RT(pthread_mutex_lock_eintr_np(&mcb->lock));
 		goto done;
 	}
 
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 73e45a1c4396..2ef02a175c13 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -314,7 +314,7 @@ COBALT_IMPL(int, pthread_mutex_destroy, (pthread_mutex_t *mutex))
  *
  * @apitags{xthread-only, switch-primary}
  */
-COBALT_IMPL(int, pthread_mutex_lock, (pthread_mutex_t *mutex))
+static int __pthread_mutex_lock(pthread_mutex_t *mutex, bool want_eintr)
 {
 	struct cobalt_mutex_shadow *_mutex =
 		&((union cobalt_mutex_union *)mutex)->shadow_mutex;
@@ -373,7 +373,7 @@ slow_path:
 
 	do
 		ret = XENOMAI_SYSCALL1(sc_cobalt_mutex_lock, _mutex);
-	while (ret == -EINTR);
+	while (ret == -EINTR && !want_eintr);
 
 	if (ret == 0)
 		_mutex->lockcnt = 1;
@@ -392,6 +392,16 @@ protect:
 	goto fast_path;
 }
 
+COBALT_IMPL(int, pthread_mutex_lock, (pthread_mutex_t *mutex))
+{
+	return __pthread_mutex_lock(mutex, false);
+}
+
+COBALT_IMPL(int, pthread_mutex_lock_eintr_np, (pthread_mutex_t *mutex))
+{
+	return __pthread_mutex_lock(mutex, true);
+}
+
 /**
  * Attempt, during a bounded time, to lock a mutex.
  *
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-01-10  8:14 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-30 20:16 [PATCH] Alchemy: Fix rt_task_unblock() for RT_MUTEX Richard Weinberger
2022-03-31  8:25 ` Bezdeka, Florian
2022-03-31  8:36   ` Richard Weinberger
2022-04-01  7:16     ` Bezdeka, Florian
2022-04-04  9:39       ` Richard Weinberger
2022-04-04 11:20         ` Jan Kiszka
2022-04-04 13:26           ` Richard Weinberger
2022-04-04 11:21 ` Jan Kiszka
2022-04-04 12:17   ` Richard Weinberger
2022-04-04 12:34     ` Jan Kiszka
2022-04-04 12:40       ` Richard Weinberger
2023-01-09 16:25 ` [PATCH v2] " Aaron Marcher
2023-01-10  5:52   ` Jan Kiszka
2023-01-10  7:54     ` Florian Bezdeka
2023-01-10  8:02       ` Jan Kiszka
2023-01-10  8:05         ` Richard Weinberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.