From: Greg Hudson Date: Fri, 26 Aug 2016 16:55:40 +0000 (-0400) Subject: Fix thread support for Solaris and simplify X-Git-Tag: krb5-1.15-beta1~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=703e5b0347f43a7cedaf336175b25b3a18ba53e2;p=thirdparty%2Fkrb5.git 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. --- diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h index b2e2e43289..3e3901d6e8 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 d1170b11ef..bb8e287ecf 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 */