pullup from trunk
authorTom Yu <tlyu@mit.edu>
Mon, 18 Jul 2005 23:22:57 +0000 (23:22 +0000)
committerTom Yu <tlyu@mit.edu>
Mon, 18 Jul 2005 23:22:57 +0000 (23:22 +0000)
ticket: 3084
version_fixed: 1.4.2

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@17307 dc483132-0cff-0310-8789-dd5450dbe970

src/include/ChangeLog
src/include/k5-thread.h
src/util/support/ChangeLog
src/util/support/libkrb5support.exports
src/util/support/threads.c

index 1246894e4afe39564b59c8b761a122ad0c0585ba..c553286b6948b0e657f0fc363a30539eff73a4c4 100644 (file)
@@ -1,3 +1,9 @@
+2005-05-31  Ken Raeburn  <raeburn@mit.edu>
+
+       * k5-thread.h (krb5int_pthread_loaded) [HAVE_PRAGMA_WEAK_REF]:
+       Declare.
+       (K5_PTHREADS_LOADED) [HAVE_PRAGMA_WEAK_REF]: Use it.
+
 2005-05-17  Ken Raeburn  <raeburn@mit.edu>
 
        * fake-addrinfo.c (fai_add_hosts_by_name): Pass null pointer
index 9ac5219f4181f16e047a34a2f9c69135c1692246..d750003a00ee6173656cf7606548550ac1f52e22 100644 (file)
@@ -372,14 +372,8 @@ typedef k5_os_nothread_mutex k5_os_mutex;
 # ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_IN_THREAD_LIB
 #  pragma weak pthread_mutexattr_setrobust_np
 # endif
-# if !defined HAVE_PTHREAD_ONCE
-#  define K5_PTHREADS_LOADED   (&pthread_once != 0)
-# elif !defined HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP \
-       && defined HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_IN_THREAD_LIB
-#  define K5_PTHREADS_LOADED   (&pthread_mutexattr_setrobust_np != 0)
-# else
-#  define K5_PTHREADS_LOADED   (1)
-# endif
+extern int krb5int_pthread_loaded(void);
+# define K5_PTHREADS_LOADED    (krb5int_pthread_loaded())
 #else
 /* no pragma weak support */
 # define K5_PTHREADS_LOADED    (1)
@@ -404,6 +398,8 @@ typedef k5_os_nothread_mutex k5_os_mutex;
 #endif
 
 #if !defined(HAVE_PTHREAD_MUTEX_LOCK) && !defined(USE_PTHREAD_LOCK_ONLY_IF_LOADED)
+/* If we find a system with a broken stub for pthread_mutex_lock,
+   we may have to change this.  */
 # define USE_PTHREAD_LOCK_ONLY_IF_LOADED
 #endif
 
index ecffff7870c0474fed86db4f96f7845905f55fdd..9e974029ca6ddfe499cce4aa36fd51bc66c33504 100644 (file)
@@ -1,3 +1,14 @@
+2005-05-31  Ken Raeburn  <raeburn@mit.edu>
+
+       * threads.c [HAVE_PRAGMA_WEAK_REF]: Declare
+       pthread_{g,s}etspecific, pthread_key_{create,delete},
+       pthread_{create,join} as weak references.
+       (krb5int_pthread_loaded, loaded_test_aux) [HAVE_PRAGMA_WEAK_REF]:
+       New functions.
+       (flag_pthread_loaded, loaded_test_once) [HAVE_PRAGMA_WEAK_REF]:
+       New variables.
+       * libkrb5support.exports: Add krb5int_pthread_loaded.
+
 2005-03-20  Alexandra Ellwood  <lxs@mit.edu>
 
        * threads.c (thread_termination): Free array of pointers
index 7954cc9e80e34fa0b5f936b2c766ddbdac4dc0c6..6267e47086be561e3e4d0a7ad7ce4fc016e2f569 100644 (file)
@@ -5,3 +5,4 @@ krb5int_setspecific
 krb5int_fac
 krb5int_lock_fac
 krb5int_unlock_fac
+krb5int_pthread_loaded
index 15e991a8dcecd4eea7b0d279d69e68b1647a505e..30701c74000d74b3f8c686bff7e8ede9435ea80c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * util/support/threads.c
  *
- * Copyright 2004 by the Massachusetts Institute of Technology.
+ * Copyright 2004,2005 by the Massachusetts Institute of Technology.
  * All Rights Reserved.
  *
  * Export of this software from the United States of America may
@@ -106,6 +106,61 @@ struct tsd_block {
 # pragma weak pthread_setspecific
 # pragma weak pthread_key_create
 # pragma weak pthread_key_delete
+# pragma weak pthread_create
+# pragma weak pthread_join
+static volatile int flag_pthread_loaded = -1;
+static void loaded_test_aux(void)
+{
+    if (flag_pthread_loaded == -1)
+       flag_pthread_loaded = 1;
+    else
+       /* Could we have been called twice?  */
+       flag_pthread_loaded = 0;
+}
+static pthread_once_t loaded_test_once = PTHREAD_ONCE_INIT;
+int krb5int_pthread_loaded (void)
+{
+    int x = flag_pthread_loaded;
+    if (x != -1)
+       return x;
+    if (&pthread_getspecific == 0
+       || &pthread_setspecific == 0
+       || &pthread_key_create == 0
+       || &pthread_key_delete == 0
+       || &pthread_once == 0
+       || &pthread_mutex_lock == 0
+       || &pthread_mutex_unlock == 0
+       || &pthread_mutex_destroy == 0
+       || &pthread_mutex_init == 0
+       || &pthread_self == 0
+       || &pthread_equal == 0
+       /* This catches Solaris 9.  May be redundant with the above
+          tests now.  */
+# ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP_IN_THREAD_LIB
+       || &pthread_mutexattr_setrobust_np == 0
+# endif
+       /* Any program that's really multithreaded will have to be
+          able to create threads.  */
+       || &pthread_create == 0
+       || &pthread_join == 0
+       /* Okay, all the interesting functions -- or stubs for them --
+          seem to be present.  If we call pthread_once, does it
+          actually seem to cause the indicated function to get called
+          exactly one time?  */
+       || pthread_once(&loaded_test_once, loaded_test_aux) != 0
+       || pthread_once(&loaded_test_once, loaded_test_aux) != 0
+       /* This catches cases where pthread_once does nothing, and
+          never causes the function to get called.  That's a pretty
+          clear violation of the POSIX spec, but hey, it happens.  */
+       || flag_pthread_loaded < 0) {
+       flag_pthread_loaded = 0;
+       return 0;
+    }
+    /* If we wanted to be super-paranoid, we could try testing whether
+       pthread_get/setspecific work, too.  I don't know -- so far --
+       of any system with non-functional stubs for those.  */
+    return flag_pthread_loaded;
+}
 static struct tsd_block tsd_if_single;
 # define GET_NO_PTHREAD_TSD()  (&tsd_if_single)
 #else