[Xenomai-git] Philippe Gerum : lib/cobalt: check for valid mutex init decls

2017-04-17 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 00ea14550cf6967655489669fb4c7aab1f8451fa
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=00ea14550cf6967655489669fb4c7aab1f8451fa

Author: Philippe Gerum 
Date:   Sat Apr 15 14:57:45 2017 +0200

lib/cobalt: check for valid mutex init decls

Not all mutex types may be supported by the underlying *libc
implementation.

---

 configure.ac   |2 ++
 lib/cobalt/mutex.c |   15 ---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index fbfb60f..bc586e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -525,6 +525,8 @@ LIBS="$save_LIBS"
 save_CPPFLAGS="$CPPFLAGS"
 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 AC_CHECK_DECLS([PTHREAD_PRIO_NONE], [], [], [#include ])
+AC_CHECK_DECLS([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [], [], [#include 
])
+AC_CHECK_DECLS([PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP], [], [], [#include 
])
 CPPFLAGS=$save_CPPFLAGS
 
 dnl If we can't set the clock for condvar timeouts, then
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 9d8a914..eba236b 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -192,23 +192,32 @@ COBALT_IMPL(int, pthread_mutex_destroy, (pthread_mutex_t 
*mutex))
 
 static int __attribute__((cold)) cobalt_mutex_autoinit(pthread_mutex_t *mutex)
 {
-   static pthread_mutex_t uninit_normal_mutex = PTHREAD_MUTEX_INITIALIZER;
-   struct cobalt_mutex_shadow *_mutex =
-   &((union cobalt_mutex_union *)mutex)->shadow_mutex;
+   static pthread_mutex_t uninit_normal_mutex =
+   PTHREAD_MUTEX_INITIALIZER;
+#if HAVE_DECL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
static pthread_mutex_t uninit_recursive_mutex =
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+#endif
+#if HAVE_DECL_PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
static pthread_mutex_t uninit_errorcheck_mutex =
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+#endif
+   struct cobalt_mutex_shadow *_mutex =
+   &((union cobalt_mutex_union *)mutex)->shadow_mutex;
int err __attribute__((unused));
pthread_mutexattr_t mattr;
int ret = 0, type;
 
if (memcmp(mutex, _normal_mutex, sizeof(*mutex)) == 0)
type = PTHREAD_MUTEX_DEFAULT;
+#if HAVE_DECL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
else if (memcmp(mutex, _recursive_mutex, sizeof(*mutex)) == 0)
type = PTHREAD_MUTEX_RECURSIVE_NP;
+#endif
+#if HAVE_DECL_PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
else if (memcmp(mutex, _errorcheck_mutex, sizeof(*mutex)) == 0)
type = PTHREAD_MUTEX_ERRORCHECK_NP;
+#endif
else
return EINVAL;
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : lib/cobalt: check for valid mutex init decls

2017-04-15 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 00ea14550cf6967655489669fb4c7aab1f8451fa
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=00ea14550cf6967655489669fb4c7aab1f8451fa

Author: Philippe Gerum 
Date:   Sat Apr 15 14:57:45 2017 +0200

lib/cobalt: check for valid mutex init decls

Not all mutex types may be supported by the underlying *libc
implementation.

---

 configure.ac   |2 ++
 lib/cobalt/mutex.c |   15 ---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index fbfb60f..bc586e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -525,6 +525,8 @@ LIBS="$save_LIBS"
 save_CPPFLAGS="$CPPFLAGS"
 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 AC_CHECK_DECLS([PTHREAD_PRIO_NONE], [], [], [#include ])
+AC_CHECK_DECLS([PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], [], [], [#include 
])
+AC_CHECK_DECLS([PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP], [], [], [#include 
])
 CPPFLAGS=$save_CPPFLAGS
 
 dnl If we can't set the clock for condvar timeouts, then
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 9d8a914..eba236b 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -192,23 +192,32 @@ COBALT_IMPL(int, pthread_mutex_destroy, (pthread_mutex_t 
*mutex))
 
 static int __attribute__((cold)) cobalt_mutex_autoinit(pthread_mutex_t *mutex)
 {
-   static pthread_mutex_t uninit_normal_mutex = PTHREAD_MUTEX_INITIALIZER;
-   struct cobalt_mutex_shadow *_mutex =
-   &((union cobalt_mutex_union *)mutex)->shadow_mutex;
+   static pthread_mutex_t uninit_normal_mutex =
+   PTHREAD_MUTEX_INITIALIZER;
+#if HAVE_DECL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
static pthread_mutex_t uninit_recursive_mutex =
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+#endif
+#if HAVE_DECL_PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
static pthread_mutex_t uninit_errorcheck_mutex =
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+#endif
+   struct cobalt_mutex_shadow *_mutex =
+   &((union cobalt_mutex_union *)mutex)->shadow_mutex;
int err __attribute__((unused));
pthread_mutexattr_t mattr;
int ret = 0, type;
 
if (memcmp(mutex, _normal_mutex, sizeof(*mutex)) == 0)
type = PTHREAD_MUTEX_DEFAULT;
+#if HAVE_DECL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
else if (memcmp(mutex, _recursive_mutex, sizeof(*mutex)) == 0)
type = PTHREAD_MUTEX_RECURSIVE_NP;
+#endif
+#if HAVE_DECL_PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
else if (memcmp(mutex, _errorcheck_mutex, sizeof(*mutex)) == 0)
type = PTHREAD_MUTEX_ERRORCHECK_NP;
+#endif
else
return EINVAL;
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git