diff options
author | Matt Caswell <matt@openssl.org> | 2015-11-13 23:54:44 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-11-20 23:39:30 +0000 |
commit | 68487a9b0631d27be9a1f4565e7e652ae9cb6aad (patch) | |
tree | f08b9aedfa12d06d5602f2422def273b96f7ea2c /crypto/async/async.c | |
parent | 27949c353e68825f119410f8fd73ae1d667581c7 (diff) | |
download | openssl-68487a9b0631d27be9a1f4565e7e652ae9cb6aad.zip openssl-68487a9b0631d27be9a1f4565e7e652ae9cb6aad.tar.gz openssl-68487a9b0631d27be9a1f4565e7e652ae9cb6aad.tar.bz2 |
Convert __thread to pthreads for Thread Local Storage
In theory the pthreads approach for Thread Local Storage should be more
portable.
This also changes some APIs in order to accommodate this change. In
particular ASYNC_init_pool is renamed ASYNC_init_thread and
ASYNC_free_pool is renamed ASYNC_cleanup_thread. Also introduced ASYNC_init
and ASYNC_cleanup.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/async/async.c')
-rw-r--r-- | crypto/async/async.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/crypto/async/async.c b/crypto/async/async.c index 4a89499..c18c5c4 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -156,7 +156,7 @@ static ASYNC_JOB *async_get_pool_job(void) { * Pool has not been initialised, so init with the defaults, i.e. * no max size and no pre-created jobs */ - if (ASYNC_init_pool(0, 0) == 0) + if (ASYNC_init_thread(0, 0) == 0) return NULL; pool = async_get_pool(); } @@ -328,30 +328,36 @@ static void async_empty_pool(async_pool *pool) } while (job); } -int ASYNC_init_pool(size_t max_size, size_t init_size) +int ASYNC_init(int init_thread, size_t max_size, size_t init_size) +{ + if (!async_thread_local_init()) + return 0; + + if (init_thread) + return ASYNC_init_thread(max_size, init_size); + + return 1; +} + +int ASYNC_init_thread(size_t max_size, size_t init_size) { async_pool *pool; size_t curr_size = 0; - if (init_size > max_size || max_size == 0) { - ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_INVALID_POOL_SIZE); - return 0; - } - - if(async_get_pool() != NULL) { - ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_POOL_ALREADY_INITED); + if (init_size > max_size) { + ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_INVALID_POOL_SIZE); return 0; } pool = OPENSSL_zalloc(sizeof *pool); if (pool == NULL) { - ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ERR_R_MALLOC_FAILURE); + ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE); return 0; } pool->jobs = sk_ASYNC_JOB_new_null(); if (pool->jobs == NULL) { - ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ERR_R_MALLOC_FAILURE); + ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE); OPENSSL_free(pool); return 0; } @@ -379,7 +385,7 @@ int ASYNC_init_pool(size_t max_size, size_t init_size) pool->curr_size = curr_size; if (!async_set_pool(pool)) { - ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_FAILED_TO_SET_POOL); + ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_FAILED_TO_SET_POOL); goto err; } @@ -397,15 +403,25 @@ static void async_free_pool_internal(async_pool *pool) async_empty_pool(pool); sk_ASYNC_JOB_free(pool->jobs); OPENSSL_free(pool); - async_set_pool(NULL); + (void)async_set_pool(NULL); async_ctx_free(); } -void ASYNC_free_pool(void) +void ASYNC_cleanup_thread(void) { async_free_pool_internal(async_get_pool()); } +void ASYNC_cleanup(int cleanupthread) +{ + /* + * We don't actually have any global cleanup at the moment so just cleanup + * the thread + */ + if (cleanupthread) + ASYNC_cleanup_thread(); +} + ASYNC_JOB *ASYNC_get_current_job(void) { async_ctx *ctx; |