[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fix dependencies among thread modules
From: |
Bruno Haible |
Subject: |
Re: fix dependencies among thread modules |
Date: |
Tue, 24 Dec 2019 21:48:50 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-169-generic; KDE/5.18.0; x86_64; ; ) |
> 2019-12-21 Bruno Haible <address@hidden>
>
> sched_yield: Don't depend on threadlib and yield.
This patch in particular had the effect of correcting the value of YIELD_LIB
on HP-UX. Namely, on HP-UX, librt exists but is not needed for sched_yield,
because sched_yield already exists in libc. Previously, YIELD_LIB was set to
'-lrt' on this platform. Now, it is set to empty.
But this has the effect that now, on HP-UX, 'test-lock' fails to link:
/usr/ccs/bin/ld: Unsatisfied symbols:
sem_post (first referenced in test-lock.o) (code)
sem_trywait (first referenced in test-lock.o) (code)
sem_init (first referenced in test-lock.o) (code)
gmake[3]: *** [test-lock] Error 1
This patch fixes it.
2019-12-24 Bruno Haible <address@hidden>
lock tests: Fix link error on HP-UX/hppa (regression from 2019-12-21).
* m4/semaphore.m4: New file.
* modules/lock-tests (Files): Add it.
(configure.ac): Require gl_SEMAPHORE.
(Makefile.am): Link test-lock with $(LIB_SEMAPHORE).
diff --git a/m4/semaphore.m4 b/m4/semaphore.m4
new file mode 100644
index 0000000..4de6824
--- /dev/null
+++ b/m4/semaphore.m4
@@ -0,0 +1,45 @@
+# semaphore.m4 serial 1
+dnl Copyright (C) 2019 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Sets LIB_SEMAPHORE to the library needed, in addition to $(LIBMULTITHREAD),
+# for getting the <semaphore.h> functions.
+
+AC_DEFUN([gl_SEMAPHORE],
+[
+ AC_REQUIRE([gl_THREADLIB])
+ dnl sem_post is
+ dnl - in libc on macOS, FreeBSD, AIX, IRIX, Solaris 11, Haiku, Cygwin,
+ dnl - in libpthread on glibc systems, OpenBSD,
+ dnl - in libpthread or librt on NetBSD,
+ dnl - in librt on HP-UX 11, OSF/1, Solaris 10.
+ dnl On the platforms where -lpthread is needed, it is contained in
+ dnl $LIBMULTITHREAD. Therefore, the only library we need to test for is -lrt.
+ AC_CACHE_CHECK([for library needed for semaphore functions],
+ [gl_cv_semaphore_lib],
+ [save_LIBS="$LIBS"
+ LIBS="$LIBS $LIBMULTITHREAD"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <semaphore.h>]],
+ [[sem_post ((sem_t *)0);]])],
+ [gl_cv_semaphore_lib=none],
+ [LIBS="$LIBS -lrt"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <semaphore.h>]],
+ [[sem_post ((sem_t *)0);]])],
+ [gl_cv_semaphore_lib='-lrt'],
+ [gl_cv_semaphore_lib=none])
+ ])
+ LIBS="$save_LIBS"
+ ])
+ if test "x$gl_cv_semaphore_lib" = xnone; then
+ LIB_SEMAPHORE=
+ else
+ LIB_SEMAPHORE="$gl_cv_semaphore_lib"
+ fi
+ AC_SUBST([LIB_SEMAPHORE])
+])
diff --git a/modules/lock-tests b/modules/lock-tests
index 5d647fa..112fbf9 100644
--- a/modules/lock-tests
+++ b/modules/lock-tests
@@ -2,6 +2,7 @@ Files:
tests/test-rwlock1.c
tests/test-lock.c
tests/test-once.c
+m4/semaphore.m4
Depends-on:
thread
@@ -12,12 +13,13 @@ yield
configure.ac:
AC_CHECK_HEADERS_ONCE([semaphore.h])
AC_CHECK_DECLS_ONCE([alarm])
+AC_REQUIRE([gl_SEMAPHORE])
Makefile.am:
TESTS += test-rwlock1 test-lock test-once1 test-once2
check_PROGRAMS += test-rwlock1 test-lock test-once1 test-once2
test_rwlock1_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
-test_lock_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+test_lock_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@ @LIB_SEMAPHORE@
test_once1_SOURCES = test-once.c
test_once1_LDADD = $(LDADD) @LIBTHREAD@
test_once2_SOURCES = test-once.c