git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Support pthread with no recursive mutex (SunOS 5.6)

From
GVGary V. Vaughan <git@mlists.thewrittenword.com>
Date
Nov 2, 2010, 14:12 UTC
Message-ID
<20101102141227.GA3991@thor.il.thewrittenword.com>

Thanks for merging my last patch series into the new release. git 1.7.3.2 now compiles correctly on all of our hosts, save Solaris 2.6 (SunOS 5.6) which has no recursive mutex support in its pthreads. While we could penalize that platform by disabling threads entirely, they worked perfectly well up until this release.

This patch adds a new configure and Makefile setting to selectively disable just the single recursive mutex usage in favour of the older implementation that used a simple non-recursive mutex in the same spot, but on just Solaris 2.6.

Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com>
---
 Makefile               |    4 ++++
 builtin/pack-objects.c |    4 ++++
 config.mak.in          |    1 +
 configure.ac           |   16 ++++++++++++++++
 thread-utils.c         |    2 ++
 thread-utils.h         |    2 ++
 6 files changed, 29 insertions(+)
Index: b/Makefile
===================================================================
--- a/Makefile
+++ b/Makefile
@@ -119,6 +119,9 @@ all::
 #
 # Define NO_PTHREADS if you do not have or do not want to use Pthreads.
 #
+# Define NO_RECURSIVE_MUTEX if you do have Pthreads, but with no support for
+# recursive mutexs (SunOS 5.6).
+#
 # Define NO_PREAD if you have a problem with pread() system call (e.g.
 # cygwin1.dll before v1.5.22).
 #
@@ -847,6 +850,7 @@ ifeq ($(uname_S),SunOS)
 		SOCKLEN_T = int
 		NO_HSTRERROR = YesPlease
 		NO_IPV6 = YesPlease
+		NO_RECURSIVE_MUTEX = YesPlease
 		NO_SOCKADDR_STORAGE = YesPlease
 		NO_UNSETENV = YesPlease
 		NO_SETENV = YesPlease
Index: b/builtin/pack-objects.c
===================================================================
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1561,7 +1561,11 @@ static pthread_cond_t progress_cond;
  */
 static void init_threaded_search(void)
 {
+#ifndef NO_RECURSIVE_MUTEX
 	init_recursive_mutex(&read_mutex);
+#else
+	pthread_mutex_init(&read_mutex, NULL);
+#endif
 	pthread_mutex_init(&cache_mutex, NULL);
 	pthread_mutex_init(&progress_mutex, NULL);
 	pthread_cond_init(&progress_cond, NULL);
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -876,6 +876,9 @@ AC_SUBST(NO_MKSTEMPS)
 # Define NO_PTHREADS if we do not have pthreads.
 #
 # Define PTHREAD_LIBS to the linker flag used for Pthread support.
+#
+# Define NO_RECURSIVE_MUTEX if you do have Pthreads, but with no support for
+# recursive mutexes (SunOS 5.6).
 AC_DEFUN([PTHREADTEST_SRC], [
 #include <pthread.h>
 
@@ -940,9 +943,22 @@ fi
 
 CFLAGS="$old_CFLAGS"
 
+if test $threads_found = yes; then
+  AC_MSG_CHECKING([Checking for PTHREAD_MUTEX_RECURSIVE support])
+  AC_EGREP_HEADER([PTHREAD_MUTEX_RECURSIVE], [pthread.h],
+	[], [NO_RECURSIVE_MUTEX=YesPlease])
+  if test -n "$NO_RECURSIVE_MUTEX"; then
+    AC_MSG_RESULT([no])
+  else
+    AC_MSG_RESULT([yes])
+  fi
+fi
+
+
 AC_SUBST(PTHREAD_CFLAGS)
 AC_SUBST(PTHREAD_LIBS)
 AC_SUBST(NO_PTHREADS)
+AC_SUBST(NO_RECURSIVE_MUTEX)
 
 ## Output files
 AC_CONFIG_FILES(["${config_file}":"${config_in}":"${config_append}"])
Index: b/thread-utils.c
===================================================================
--- a/thread-utils.c
+++ b/thread-utils.c
@@ -45,6 +45,7 @@ int online_cpus(void)
 	return 1;
 }
 
+#ifndef NO_RECURSIVE_MUTEX
 int init_recursive_mutex(pthread_mutex_t *m)
 {
 	pthread_mutexattr_t a;
@@ -59,3 +60,4 @@ int init_recursive_mutex(pthread_mutex_t
 	}
 	return ret;
 }
+#endif
Index: b/thread-utils.h
===================================================================
--- a/thread-utils.h
+++ b/thread-utils.h
@@ -2,6 +2,8 @@
 #define THREAD_COMPAT_H
 
 extern int online_cpus(void);
+#ifndef NO_RECURSIVE_MUTEX
 extern int init_recursive_mutex(pthread_mutex_t*);
+#endif
 
 #endif /* THREAD_COMPAT_H */
Index: b/config.mak.in
===================================================================
--- a/config.mak.in
+++ b/config.mak.in
@@ -66,5 +66,6 @@ SOCKLEN_T=@SOCKLEN_T@
 FREAD_READS_DIRECTORIES=@FREAD_READS_DIRECTORIES@
 SNPRINTF_RETURNS_BOGUS=@SNPRINTF_RETURNS_BOGUS@
 NO_PTHREADS=@NO_PTHREADS@
+NO_RECURSIVE_MUTEX=@NO_RECURSIVE_MUTEX@
 PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
 PTHREAD_LIBS=@PTHREAD_LIBS@
--
Gary V. Vaughan (gary@thewrittenword.com)
Next: Jonathan Nieder
Message 1 of 3 in “Support pthread with no recursive mutex (SunOS 5.6)”
  1. Gary V. VaughanNov 2, 2010
  2. Jonathan NiederNov 2, 2010
  3. Junio C HamanoNov 4, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.