Auto init/deinit libcrypto

This builds on the previous commit to auto initialise/deinitialise
libcrypto.

Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
Matt Caswell
2016-02-08 16:43:03 +00:00
parent b184e3ef73
commit 7b9f8f7f03
45 changed files with 422 additions and 347 deletions

View File

@@ -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);
}