mirror of https://github.com/openssl/openssl.git
				
				
				
			Move the async-job api to use the new thread-local api
Make the async-job api use our new thread-local storage api. Not strictly needed, but reduces our OS level key usage Reviewed-by: Saša Nedvědický <sashan@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/27794)
This commit is contained in:
		
							parent
							
								
									d6d5170ed2
								
							
						
					
					
						commit
						21980b9813
					
				|  | @ -17,6 +17,7 @@ | ||||||
| 
 | 
 | ||||||
| /* This must be the first #include file */ | /* This must be the first #include file */ | ||||||
| #include "async_local.h" | #include "async_local.h" | ||||||
|  | #include "internal/threads_common.h" | ||||||
| 
 | 
 | ||||||
| #include <openssl/err.h> | #include <openssl/err.h> | ||||||
| #include "crypto/cryptlib.h" | #include "crypto/cryptlib.h" | ||||||
|  | @ -27,9 +28,6 @@ | ||||||
| #define ASYNC_JOB_PAUSED    2 | #define ASYNC_JOB_PAUSED    2 | ||||||
| #define ASYNC_JOB_STOPPING  3 | #define ASYNC_JOB_STOPPING  3 | ||||||
| 
 | 
 | ||||||
| static CRYPTO_THREAD_LOCAL ctxkey; |  | ||||||
| static CRYPTO_THREAD_LOCAL poolkey; |  | ||||||
| 
 |  | ||||||
| static void async_delete_thread_state(void *arg); | static void async_delete_thread_state(void *arg); | ||||||
| 
 | 
 | ||||||
| static async_ctx *async_ctx_new(void) | static async_ctx *async_ctx_new(void) | ||||||
|  | @ -46,7 +44,7 @@ static async_ctx *async_ctx_new(void) | ||||||
|     async_fibre_init_dispatcher(&nctx->dispatcher); |     async_fibre_init_dispatcher(&nctx->dispatcher); | ||||||
|     nctx->currjob = NULL; |     nctx->currjob = NULL; | ||||||
|     nctx->blocked = 0; |     nctx->blocked = 0; | ||||||
|     if (!CRYPTO_THREAD_set_local(&ctxkey, nctx)) |     if (!CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_CTX_KEY, NULL, nctx)) | ||||||
|         goto err; |         goto err; | ||||||
| 
 | 
 | ||||||
|     return nctx; |     return nctx; | ||||||
|  | @ -58,7 +56,7 @@ err: | ||||||
| 
 | 
 | ||||||
| async_ctx *async_get_ctx(void) | async_ctx *async_get_ctx(void) | ||||||
| { | { | ||||||
|     return (async_ctx *)CRYPTO_THREAD_get_local(&ctxkey); |     return (async_ctx *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_CTX_KEY, NULL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int async_ctx_free(void) | static int async_ctx_free(void) | ||||||
|  | @ -67,7 +65,7 @@ static int async_ctx_free(void) | ||||||
| 
 | 
 | ||||||
|     ctx = async_get_ctx(); |     ctx = async_get_ctx(); | ||||||
| 
 | 
 | ||||||
|     if (!CRYPTO_THREAD_set_local(&ctxkey, NULL)) |     if (!CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_CTX_KEY, NULL, NULL)) | ||||||
|         return 0; |         return 0; | ||||||
| 
 | 
 | ||||||
|     OPENSSL_free(ctx); |     OPENSSL_free(ctx); | ||||||
|  | @ -101,7 +99,7 @@ static ASYNC_JOB *async_get_pool_job(void) { | ||||||
|     ASYNC_JOB *job; |     ASYNC_JOB *job; | ||||||
|     async_pool *pool; |     async_pool *pool; | ||||||
| 
 | 
 | ||||||
|     pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); |     pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL); | ||||||
|     if (pool == NULL) { |     if (pool == NULL) { | ||||||
|         /*
 |         /*
 | ||||||
|          * Pool has not been initialised, so init with the defaults, i.e. |          * Pool has not been initialised, so init with the defaults, i.e. | ||||||
|  | @ -109,7 +107,7 @@ static ASYNC_JOB *async_get_pool_job(void) { | ||||||
|          */ |          */ | ||||||
|         if (ASYNC_init_thread(0, 0) == 0) |         if (ASYNC_init_thread(0, 0) == 0) | ||||||
|             return NULL; |             return NULL; | ||||||
|         pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); |         pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     job = sk_ASYNC_JOB_pop(pool->jobs); |     job = sk_ASYNC_JOB_pop(pool->jobs); | ||||||
|  | @ -133,7 +131,7 @@ static ASYNC_JOB *async_get_pool_job(void) { | ||||||
| static void async_release_job(ASYNC_JOB *job) { | static void async_release_job(ASYNC_JOB *job) { | ||||||
|     async_pool *pool; |     async_pool *pool; | ||||||
| 
 | 
 | ||||||
|     pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); |     pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL); | ||||||
|     if (pool == NULL) { |     if (pool == NULL) { | ||||||
|         ERR_raise(ERR_LIB_ASYNC, ERR_R_INTERNAL_ERROR); |         ERR_raise(ERR_LIB_ASYNC, ERR_R_INTERNAL_ERROR); | ||||||
|         return; |         return; | ||||||
|  | @ -327,21 +325,11 @@ static void async_empty_pool(async_pool *pool) | ||||||
| 
 | 
 | ||||||
| int async_init(void) | int async_init(void) | ||||||
| { | { | ||||||
|     if (!CRYPTO_THREAD_init_local(&ctxkey, NULL)) |  | ||||||
|         return 0; |  | ||||||
| 
 |  | ||||||
|     if (!CRYPTO_THREAD_init_local(&poolkey, NULL)) { |  | ||||||
|         CRYPTO_THREAD_cleanup_local(&ctxkey); |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return async_local_init(); |     return async_local_init(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void async_deinit(void) | void async_deinit(void) | ||||||
| { | { | ||||||
|     CRYPTO_THREAD_cleanup_local(&ctxkey); |  | ||||||
|     CRYPTO_THREAD_cleanup_local(&poolkey); |  | ||||||
|     async_local_deinit(); |     async_local_deinit(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -391,7 +379,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size) | ||||||
|         curr_size++; |         curr_size++; | ||||||
|     } |     } | ||||||
|     pool->curr_size = curr_size; |     pool->curr_size = curr_size; | ||||||
|     if (!CRYPTO_THREAD_set_local(&poolkey, pool)) { |     if (!CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL, pool)) { | ||||||
|         ERR_raise(ERR_LIB_ASYNC, ASYNC_R_FAILED_TO_SET_POOL); |         ERR_raise(ERR_LIB_ASYNC, ASYNC_R_FAILED_TO_SET_POOL); | ||||||
|         goto err; |         goto err; | ||||||
|     } |     } | ||||||
|  | @ -406,13 +394,14 @@ err: | ||||||
| 
 | 
 | ||||||
| static void async_delete_thread_state(void *arg) | static void async_delete_thread_state(void *arg) | ||||||
| { | { | ||||||
|     async_pool *pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); |     async_pool *pool = (async_pool *)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, | ||||||
|  |                                                                 NULL); | ||||||
| 
 | 
 | ||||||
|     if (pool != NULL) { |     if (pool != NULL) { | ||||||
|         async_empty_pool(pool); |         async_empty_pool(pool); | ||||||
|         sk_ASYNC_JOB_free(pool->jobs); |         sk_ASYNC_JOB_free(pool->jobs); | ||||||
|         OPENSSL_free(pool); |         OPENSSL_free(pool); | ||||||
|         CRYPTO_THREAD_set_local(&poolkey, NULL); |         CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_ASYNC_POOL_KEY, NULL, NULL); | ||||||
|     } |     } | ||||||
|     async_local_cleanup(); |     async_local_cleanup(); | ||||||
|     async_ctx_free(); |     async_ctx_free(); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue