All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Bezdeka <florian.bezdeka@siemens.com>
To: xenomai@lists.linux.dev
Cc: jan.kiszka@siemens.com, Florian Bezdeka <florian.bezdeka@siemens.com>
Subject: [RFC][stable 3.0.x] lib: Switch to pthread_mutexattr_setrobust
Date: Fri, 18 Nov 2022 16:42:20 +0100	[thread overview]
Message-ID: <20221118154220.869584-1-florian.bezdeka@siemens.com> (raw)

With recent glibc (at least 2.34), autoconf fails to detect
pthread_mutexattr_setrobust_np. But that is long deprecated anyway. So
switch to pthread_mutexattr_setrobust and only fall back to _np when
needed.

This is a backport of the following commits from stable 3.2:

746cbeb6ccc0 ("lib: Switch to pthread_mutexattr_setrobust")
3f85c174e297 ("lib: Fix fallback signature of pthread_mutexattr_setrobust")
2d947e6fe3f8 ("lib: Re-add "static" to pthread_mutexattr_setrobust fallback stub")

Backporting allows the stable 3.0 branch to be build with the latest
Debian toolchain, so we don't need a special CI setup for the 3.0
branch.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---

Hi all,

would it be acceptable to apply this patch to the 3.0.x stable branch? 
It would allow us to build this branch with the same infrastructure once 
we like to update to the next Debian version (12).

Especially the y2038 tests require a recent glibc version the next 
Debian stable release (bookworm, Debian 12) will ship such a version.

One alternative would be to use different build environments for
different Xenomai stable branches. I fear that's hard to maintain -
especially the CI configuration will likely explode.

WDYT?

This patch has been tested with both build environments, so Debian 11
(as is now) and the upcoming Debian 12.

Best regards,
Florian

 configure.ac               |  1 +
 include/boilerplate/libc.h | 14 +++++++++++---
 lib/alchemy/mutex.c        |  4 ++--
 lib/vxworks/semLib.c       |  4 ++--
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index f31365c7a..0ad866ddd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -489,6 +489,7 @@ save_LIBS="$LIBS"
 LIBS="$LIBS -lrt -lpthread"
 AC_CHECK_FUNCS([pthread_mutexattr_setprotocol	\
 		pthread_mutexattr_getprotocol	\
+		pthread_mutexattr_setrobust	\
 		pthread_mutexattr_setrobust_np	\
 		pthread_condattr_getclock	\
 		pthread_condattr_setclock	\
diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h
index 134176e54..e7d33101f 100644
--- a/include/boilerplate/libc.h
+++ b/include/boilerplate/libc.h
@@ -186,10 +186,18 @@ __weak int shm_unlink(const char *name)
 }
 #endif	/* !HAVE_SHM_UNLINK */
 
-#ifndef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
-#define pthread_mutexattr_setrobust_np(__attr, __robust)	\
-	({ ENOSYS; })
+#ifndef HAVE_PTHREAD_MUTEXATTR_SETROBUST
+#ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
+#define pthread_mutexattr_setrobust	pthread_mutexattr_setrobust_np
+#else
+static inline
+int pthread_mutexattr_setrobust(pthread_mutexattr_t *attr,
+				int *robustness)
+{
+	return ENOSYS;
+}
 #endif /* !HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP */
+#endif /* !HAVE_PTHREAD_MUTEXATTR_SETROBUST */
 
 #if !defined(HAVE_PTHREAD_SETNAME_NP) && defined(CONFIG_XENO_MERCURY)
 static inline
diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c
index 09eb1364e..f89338586 100644
--- a/lib/alchemy/mutex.c
+++ b/lib/alchemy/mutex.c
@@ -131,8 +131,8 @@ int rt_mutex_create(RT_MUTEX *mutex, const char *name)
 	pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
 	pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute);
 	pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
-	/* pthread_mutexattr_setrobust_np() might not be implemented. */
-	pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+	/* pthread_mutexattr_setrobust() might not be implemented. */
+	pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP);
 	ret = __RT(pthread_mutex_init(&mcb->lock, &mattr));
 	if (ret) {
 		xnfree(mcb);
diff --git a/lib/vxworks/semLib.c b/lib/vxworks/semLib.c
index acce160ee..180ed2000 100644
--- a/lib/vxworks/semLib.c
+++ b/lib/vxworks/semLib.c
@@ -411,8 +411,8 @@ SEM_ID semMCreate(int options)
 	 */
 	pthread_mutexattr_init(&mattr);
 	pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
-	/* pthread_mutexattr_setrobust_np() might not be implemented. */
-	pthread_mutexattr_setrobust_np(&mattr, PTHREAD_MUTEX_ROBUST_NP);
+	/* pthread_mutexattr_setrobust() might not be implemented. */
+	pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP);
 	if (options & SEM_INVERSION_SAFE)
 		pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
 	pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute);
-- 
2.35.1


             reply	other threads:[~2022-11-18 21:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 15:42 Florian Bezdeka [this message]
2022-11-21  9:16 ` [RFC][stable 3.0.x] lib: Switch to pthread_mutexattr_setrobust Jan Kiszka
2022-11-21  9:51   ` Bezdeka, Florian
2022-11-21 17:49     ` Jan Kiszka
2022-11-22 10:20       ` Florian Bezdeka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221118154220.869584-1-florian.bezdeka@siemens.com \
    --to=florian.bezdeka@siemens.com \
    --cc=jan.kiszka@siemens.com \
    --cc=xenomai@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.