diff options
author | Matt Caswell <matt@openssl.org> | 2016-02-08 17:43:03 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-02-09 16:11:38 +0100 |
commit | 7b9f8f7f03eda2faa1cdd42ed29a0b70e60eaf59 (patch) | |
tree | 30f805756265bd1d016aead84dcf1c909cca8b4b /crypto/async/arch | |
parent | Provide framework for auto initialise/deinitialise of the library (diff) | |
download | openssl-7b9f8f7f03eda2faa1cdd42ed29a0b70e60eaf59.tar.xz openssl-7b9f8f7f03eda2faa1cdd42ed29a0b70e60eaf59.zip |
Auto init/deinit libcrypto
This builds on the previous commit to auto initialise/deinitialise
libcrypto.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/async/arch')
-rw-r--r-- | crypto/async/arch/async_null.c | 5 | ||||
-rw-r--r-- | crypto/async/arch/async_null.h | 2 | ||||
-rw-r--r-- | crypto/async/arch/async_posix.c | 8 | ||||
-rw-r--r-- | crypto/async/arch/async_posix.h | 2 | ||||
-rw-r--r-- | crypto/async/arch/async_win.c | 42 | ||||
-rw-r--r-- | crypto/async/arch/async_win.h | 2 |
6 files changed, 14 insertions, 47 deletions
diff --git a/crypto/async/arch/async_null.c b/crypto/async/arch/async_null.c index d3f686f492..2b1d28eaf3 100644 --- a/crypto/async/arch/async_null.c +++ b/crypto/async/arch/async_null.c @@ -80,11 +80,6 @@ int async_global_init(void) return 0; } -int async_local_init(void) -{ - return 0; -} - void async_local_cleanup(void) { } diff --git a/crypto/async/arch/async_null.h b/crypto/async/arch/async_null.h index 93887aec19..4cd0a8b966 100644 --- a/crypto/async/arch/async_null.h +++ b/crypto/async/arch/async_null.h @@ -66,7 +66,7 @@ typedef struct async_fibre_st { # define async_set_ctx(nctx) 0 -# define async_get_ctx() ((async_ctx *)NULL) +# define async_arch_get_ctx() ((async_ctx *)NULL) # define async_fibre_swapcontext(o,n,r) 0 # define async_fibre_makecontext(c) 0 # define async_fibre_free(f) diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c index 1df77cccbe..57cce7b4c4 100644 --- a/crypto/async/arch/async_posix.c +++ b/crypto/async/arch/async_posix.c @@ -72,14 +72,6 @@ int async_global_init(void) return 1; } -int async_local_init(void) -{ - if (!async_set_ctx(NULL) || ! async_set_pool(NULL)) - return 0; - - return 1; -} - void async_local_cleanup(void) { } diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h index 85d033f851..7f1bdd1cc5 100644 --- a/crypto/async/arch/async_posix.h +++ b/crypto/async/arch/async_posix.h @@ -78,7 +78,7 @@ typedef struct async_fibre_st { } async_fibre; # define async_set_ctx(nctx) (pthread_setspecific(posixctx , (nctx)) == 0) -# define async_get_ctx() ((async_ctx *)pthread_getspecific(posixctx)) +# define async_arch_get_ctx() ((async_ctx *)pthread_getspecific(posixctx)) # define async_set_pool(p) (pthread_setspecific(posixpool , (p)) == 0) # define async_get_pool() ((async_pool *)pthread_getspecific(posixpool)) diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c index f3de79a73b..3f3a005cc2 100644 --- a/crypto/async/arch/async_win.c +++ b/crypto/async/arch/async_win.c @@ -66,7 +66,6 @@ struct winpool { static DWORD asyncwinpool = 0; static DWORD asyncwinctx = 0; -static DWORD asyncwindispatch = 0; void async_start_func(void); @@ -75,33 +74,22 @@ int async_global_init(void) { asyncwinpool = TlsAlloc(); asyncwinctx = TlsAlloc(); - asyncwindispatch = TlsAlloc(); - if (asyncwinpool == TLS_OUT_OF_INDEXES || asyncwinctx == TLS_OUT_OF_INDEXES - || asyncwindispatch == TLS_OUT_OF_INDEXES) { + if (asyncwinpool == TLS_OUT_OF_INDEXES + || asyncwinctx == TLS_OUT_OF_INDEXES) { if (asyncwinpool != TLS_OUT_OF_INDEXES) { TlsFree(asyncwinpool); } if (asyncwinctx != TLS_OUT_OF_INDEXES) { TlsFree(asyncwinctx); } - if (asyncwindispatch != TLS_OUT_OF_INDEXES) { - TlsFree(asyncwindispatch); - } return 0; } return 1; } -int async_local_init(void) -{ - return (TlsSetValue(asyncwinpool, NULL) != 0) - && (TlsSetValue(asyncwinctx, NULL) != 0) - && (TlsSetValue(asyncwindispatch, NULL) != 0); -} - void async_local_cleanup(void) { - async_ctx *ctx = async_get_ctx(); + async_ctx *ctx = async_arch_get_ctx(); if (ctx != NULL) { async_fibre *fibre = &ctx->dispatcher; if(fibre != NULL && fibre->fibre != NULL && fibre->converted) { @@ -115,32 +103,24 @@ void async_global_cleanup(void) { TlsFree(asyncwinpool); TlsFree(asyncwinctx); - TlsFree(asyncwindispatch); asyncwinpool = 0; asyncwinctx = 0; - asyncwindispatch = 0; } int async_fibre_init_dispatcher(async_fibre *fibre) { LPVOID dispatcher; - dispatcher = (LPVOID)TlsGetValue(asyncwindispatch); - if (dispatcher == NULL) { - fibre->fibre = ConvertThreadToFiber(NULL); - if (fibre->fibre == NULL) { - fibre->converted = 0; - fibre->fibre = GetCurrentFiber(); - if (fibre->fibre == NULL) - return 0; - } else { - fibre->converted = 1; - } - if (TlsSetValue(asyncwindispatch, (LPVOID)fibre->fibre) == 0) + fibre->fibre = ConvertThreadToFiber(NULL); + if (fibre->fibre == NULL) { + fibre->converted = 0; + fibre->fibre = GetCurrentFiber(); + if (fibre->fibre == NULL) return 0; } else { - fibre->fibre = dispatcher; + fibre->converted = 1; } + return 1; } @@ -196,7 +176,7 @@ int async_set_pool(async_pool *pool) return TlsSetValue(asyncwinpool, (LPVOID)pool) != 0; } -async_ctx *async_get_ctx(void) +async_ctx *async_arch_get_ctx(void) { return (async_ctx *)TlsGetValue(asyncwinctx); } diff --git a/crypto/async/arch/async_win.h b/crypto/async/arch/async_win.h index fa345cb1f7..87e30a4f6e 100644 --- a/crypto/async/arch/async_win.h +++ b/crypto/async/arch/async_win.h @@ -73,7 +73,7 @@ typedef struct async_fibre_st { ((c)->fibre = CreateFiber(0, async_start_func_win, 0)) # define async_fibre_free(f) (DeleteFiber((f)->fibre)) -async_ctx *async_get_ctx(void); +async_ctx *async_arch_get_ctx(void); int async_set_ctx(async_ctx *ctx); int async_fibre_init_dispatcher(async_fibre *fibre); |