[29594] in CVS-changelog-for-Kerberos-V5

home help back first fref pref prev next nref lref last post

krb5 commit: Fix thread support for Solaris and simplify

daemon@ATHENA.MIT.EDU (Greg Hudson)
Mon Aug 29 17:17:52 2016

Date: Mon, 29 Aug 2016 17:17:48 -0400
From: Greg Hudson <ghudson@mit.edu>
Message-Id: <201608292117.u7TLHmT1002325@drugstore.mit.edu>
To: cvs-krb5@mit.edu
Reply-To: krbdev@mit.edu
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cvs-krb5-bounces@mit.edu

https://github.com/krb5/krb5/commit/703e5b0347f43a7cedaf336175b25b3a18ba53e2
commit 703e5b0347f43a7cedaf336175b25b3a18ba53e2
Author: Greg Hudson <ghudson@mit.edu>
Date:   Fri Aug 26 12:55:40 2016 -0400

    Fix thread support for Solaris and simplify
    
    threads.c failed to build on Solaris afer commit
    17932091cc0d5981c5a78d389ffa4a5c7b532bd6 because k5-thread.h did not
    define the conditional k5_once_t structure (because NO_WEAK_PTHREADS
    is defined) but threads.c tried to build the conditional k5_once()
    function.
    
    Use a single preprocessor symbol, USE_CONDITIONAL_PTHREADS, to
    determine whether to use and define pthreads functions which
    conditionalize on whether pthreads is loaded.  In threads.c, move the
    new k5_once() definitions into the USE_CONDITIONAL_PTHREADS block,
    defining a stub function if other code will not refer to it.
    
    Also move #pragma weak declarations from k5-threads.h into threads.c,
    as we should no longer be conditionally referring to those symbols
    outside of threads.c.
    
    Also eliminate some missing-prototype warnings where we define
    functions for linker-visibility but don't have corresponding
    prototypes in k5-threads.h.

 src/include/k5-thread.h    |   15 +++-------
 src/util/support/threads.c |   65 +++++++++++++++++++++++--------------------
 2 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h
index b2e2e43..3e3901d 100644
--- a/src/include/k5-thread.h
+++ b/src/include/k5-thread.h
@@ -243,14 +243,10 @@ typedef k5_os_nothread_mutex k5_os_mutex;
    symbol tables of the current process.  */
 
 #if defined(HAVE_PRAGMA_WEAK_REF) && !defined(NO_WEAK_PTHREADS)
-# pragma weak pthread_once
-# pragma weak pthread_mutex_lock
-# pragma weak pthread_mutex_unlock
-# pragma weak pthread_mutex_destroy
-# pragma weak pthread_mutex_init
-# pragma weak pthread_self
-# pragma weak pthread_equal
-# define USE_PTHREAD_LOCK_ONLY_IF_LOADED
+# define USE_CONDITIONAL_PTHREADS
+#endif
+
+#ifdef USE_CONDITIONAL_PTHREADS
 
 /* Can't rely on useful stubs -- see above regarding Solaris.  */
 typedef struct {
@@ -284,9 +280,8 @@ typedef pthread_mutex_t k5_os_mutex;
 # define K5_OS_MUTEX_PARTIAL_INITIALIZER        \
     PTHREAD_MUTEX_INITIALIZER
 
-#ifdef USE_PTHREAD_LOCK_ONLY_IF_LOADED
+#ifdef USE_CONDITIONAL_PTHREADS
 
-# define USE_PTHREAD_LOADED_MUTEX_FUNCTIONS
 # define k5_os_mutex_finish_init(M)             (0)
 int k5_os_mutex_init(k5_os_mutex *m);
 int k5_os_mutex_destroy(k5_os_mutex *m);
diff --git a/src/util/support/threads.c b/src/util/support/threads.c
index d1170b1..bb8e287 100644
--- a/src/util/support/threads.c
+++ b/src/util/support/threads.c
@@ -32,7 +32,9 @@
 MAKE_INIT_FUNCTION(krb5int_thread_support_init);
 MAKE_FINI_FUNCTION(krb5int_thread_support_fini);
 
-#undef k5_once
+/* This function used to be referenced from elsewhere in the tree, but is now
+ * only used internally.  Keep it linker-visible for now. */
+int krb5int_pthread_loaded(void);
 
 #ifndef ENABLE_THREADS /* no thread support */
 
@@ -46,12 +48,6 @@ int krb5int_pthread_loaded (void)
     return 0;
 }
 
-int
-k5_once(k5_once_t *once, void (*fn)(void))
-{
-    return k5_os_nothread_once(once, fn);
-}
-
 #elif defined(_WIN32)
 
 static DWORD tls_idx;
@@ -85,16 +81,11 @@ void krb5int_thread_detach_hook (void)
     }
 }
 
-/* Stub functions not used on Windows. */
+/* Stub function not used on Windows. */
 int krb5int_pthread_loaded (void)
 {
     return 0;
 }
-int
-k5_once(k5_once_t *once, void (*fn)(void))
-{
-    return 0;
-}
 #else /* POSIX threads */
 
 /* Must support register/delete/register sequence, e.g., if krb5 is
@@ -121,6 +112,13 @@ struct tsd_block {
 };
 
 #ifdef HAVE_PRAGMA_WEAK_REF
+# pragma weak pthread_once
+# pragma weak pthread_mutex_lock
+# pragma weak pthread_mutex_unlock
+# pragma weak pthread_mutex_destroy
+# pragma weak pthread_mutex_init
+# pragma weak pthread_self
+# pragma weak pthread_equal
 # pragma weak pthread_getspecific
 # pragma weak pthread_setspecific
 # pragma weak pthread_key_create
@@ -177,15 +175,6 @@ int krb5int_pthread_loaded (void)
     return flag_pthread_loaded;
 }
 
-int
-k5_once(k5_once_t *once, void (*fn)(void))
-{
-    if (krb5int_pthread_loaded())
-        return pthread_once(&once->o, fn);
-    else
-        return k5_os_nothread_once(&once->n, fn);
-}
-
 static struct tsd_block tsd_if_single;
 # define GET_NO_PTHREAD_TSD()   (&tsd_if_single)
 #else
@@ -195,11 +184,6 @@ int krb5int_pthread_loaded (void)
     return 1;
 }
 
-int
-k5_once(k5_once_t *once, void (*fn)(void))
-{
-    return pthread_once(once, fn);
-}
 # define GET_NO_PTHREAD_TSD()   (abort(),(struct tsd_block *)0)
 #endif
 
@@ -539,7 +523,7 @@ krb5int_mutex_unlock (k5_mutex_t *m)
     k5_mutex_unlock (m);
 }
 
-#ifdef USE_PTHREAD_LOADED_MUTEX_FUNCTIONS
+#ifdef USE_CONDITIONAL_PTHREADS
 
 int
 k5_os_mutex_init(k5_os_mutex *m)
@@ -577,12 +561,28 @@ k5_os_mutex_unlock(k5_os_mutex *m)
         return 0;
 }
 
-#else /* USE_PTHREAD_LOADED_MUTEX_FUNCTIONS */
+int
+k5_once(k5_once_t *once, void (*fn)(void))
+{
+    if (krb5int_pthread_loaded())
+        return pthread_once(&once->o, fn);
+    else
+        return k5_os_nothread_once(&once->n, fn);
+}
+
+#else /* USE_CONDITIONAL_PTHREADS */
 
 #undef k5_os_mutex_init
 #undef k5_os_mutex_destroy
 #undef k5_os_mutex_lock
 #undef k5_os_mutex_unlock
+#undef k5_once
+
+int k5_os_mutex_init(k5_os_mutex *m);
+int k5_os_mutex_destroy(k5_os_mutex *m);
+int k5_os_mutex_lock(k5_os_mutex *m);
+int k5_os_mutex_unlock(k5_os_mutex *m);
+int k5_once(k5_once_t *once, void (*fn)(void));
 
 /* Stub functions */
 int
@@ -605,5 +605,10 @@ k5_os_mutex_unlock(k5_os_mutex *m)
 {
     return 0;
 }
+int
+k5_once(k5_once_t *once, void (*fn)(void))
+{
+    return 0;
+}
 
-#endif /* USE_PTHREAD_LOADED_MUTEX_FUNCTIONS */
+#endif /* not USE_CONDITIONAL_PTHREADS */
_______________________________________________
cvs-krb5 mailing list
cvs-krb5@mit.edu
https://mailman.mit.edu/mailman/listinfo/cvs-krb5

home help back first fref pref prev next nref lref last post