From 4a621ec6613efd389416e939d53cbd9da4d744bf Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Tue, 4 Jun 2002 02:19:33 +0000 Subject: [PATCH] The only remaining question ... are nested or strictly unnested locks expected by OpenSSL? Right now I've left it as _DEFAULT for the platform preference. Very simple code really - the server_rec was superfluous. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95497 13f79535-47bb-0310-9956-ffa450edef68 --- modules/ssl/mod_ssl.h | 2 +- modules/ssl/ssl_engine_init.c | 2 +- modules/ssl/ssl_util.c | 60 +++++++++++------------------------ 3 files changed, 20 insertions(+), 44 deletions(-) diff --git a/modules/ssl/mod_ssl.h b/modules/ssl/mod_ssl.h index aedd09390f..5999e97ad9 100644 --- a/modules/ssl/mod_ssl.h +++ b/modules/ssl/mod_ssl.h @@ -720,7 +720,7 @@ BOOL ssl_util_path_check(ssl_pathcheck_t, const char *, apr_pool_t *); ssl_algo_t ssl_util_algotypeof(X509 *, EVP_PKEY *); char *ssl_util_algotypestr(ssl_algo_t); char *ssl_util_ptxtsub(apr_pool_t *, const char *, const char *, char *); -void ssl_util_thread_setup(server_rec *, apr_pool_t *); +void ssl_util_thread_setup(apr_pool_t *); #define APR_SHM_MAXSIZE (64 * 1024 * 1024) #endif /* __MOD_SSL_H__ */ diff --git a/modules/ssl/ssl_engine_init.c b/modules/ssl/ssl_engine_init.c index 8161ef5eb4..7116bea1cd 100644 --- a/modules/ssl/ssl_engine_init.c +++ b/modules/ssl/ssl_engine_init.c @@ -260,7 +260,7 @@ int ssl_init_Module(apr_pool_t *p, apr_pool_t *plog, ssl_init_SSLLibrary(base_server); #if APR_HAS_THREADS - ssl_util_thread_setup(base_server, p); + ssl_util_thread_setup(p); #endif /* diff --git a/modules/ssl/ssl_util.c b/modules/ssl/ssl_util.c index 2147473638..9b208b404f 100644 --- a/modules/ssl/ssl_util.c +++ b/modules/ssl/ssl_util.c @@ -400,20 +400,18 @@ const char *ssl_asn1_table_keyfmt(apr_pool_t *p, */ static apr_thread_mutex_t **lock_cs; -/* FIXME: CRYPTO_NUM_LOCKS may vary between releases - replace with - CRYPT_num_locks() [Ben, Jan 2002] */ -static long lock_count[CRYPTO_NUM_LOCKS]; +static int lock_num_locks; static void ssl_util_thr_lock(int mode, int type, - MODSSL_CRYPTO_CB_ARG_TYPE *file, - int line) + const char *file, int line) { - if (mode & CRYPTO_LOCK) { - apr_thread_mutex_lock(lock_cs[type]); - lock_count[type]++; - } - else { - apr_thread_mutex_unlock(lock_cs[type]); + if (type < lock_num_locks) { + if (mode & CRYPTO_LOCK) { + apr_thread_mutex_lock(lock_cs[type]); + } + else { + apr_thread_mutex_unlock(lock_cs[type]); + } } } @@ -437,41 +435,21 @@ static unsigned long ssl_util_thr_id(void) static apr_status_t ssl_util_thread_cleanup(void *data) { - int i; - CRYPTO_set_locking_callback(NULL); - for (i = 0; i < CRYPTO_NUM_LOCKS; i++) { - apr_thread_mutex_destroy(lock_cs[i]); - } - + /* Let the registered mutex cleanups do their own thing + */ return APR_SUCCESS; } -void ssl_util_thread_setup(server_rec *s, apr_pool_t *p) +void ssl_util_thread_setup(apr_pool_t *p) { - int i, threaded_mpm; - /* This variable is not used? -aaron - SSLModConfigRec *mc = myModConfig(s); - */ - - ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); - - if (!threaded_mpm) { - return; - } + int i; - lock_cs = apr_palloc(p, CRYPTO_NUM_LOCKS * sizeof(apr_thread_mutex_t *)); + lock_num_locks = CRYPTO_num_locks(); + lock_cs = apr_palloc(p, lock_num_locks * sizeof(*lock_cs)); - /* - * XXX: CRYPTO_NUM_LOCKS == 28 - * should determine if there are lock types we do not need - * for example: debug_malloc, debug_malloc2 (see crypto/cryptlib.c) - */ - for (i = 0; i < CRYPTO_NUM_LOCKS; i++) { - lock_count[i] = 0; - /* XXX: Can we remove the lock_count now that apr_thread_mutex_t - * can support nested (aka recursive) locks? -aaron */ + for (i = 0; i < lock_num_locks; i++) { apr_thread_mutex_create(&(lock_cs[i]), APR_THREAD_MUTEX_DEFAULT, p); } @@ -479,9 +457,7 @@ void ssl_util_thread_setup(server_rec *s, apr_pool_t *p) CRYPTO_set_locking_callback(ssl_util_thr_lock); - apr_pool_cleanup_register(p, NULL, - ssl_util_thread_cleanup, - apr_pool_cleanup_null); - + apr_pool_cleanup_register(p, NULL, ssl_util_thread_cleanup, + apr_pool_cleanup_null); } #endif -- 2.40.0