diff options
author | Matt Caswell <matt@openssl.org> | 2015-09-16 23:43:45 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-11-20 23:33:46 +0000 |
commit | d63de0ebff88c4ef1d93065c4e531fdf5ed894fe (patch) | |
tree | 7d4ca66376a9ba38d1a4c279ba2dd45b422bba8d | |
parent | 5e6f9775a9db38b50c2f5487f126b58f7bfff78e (diff) | |
download | openssl-d63de0ebff88c4ef1d93065c4e531fdf5ed894fe.tar.gz |
Implement windows async pool and notify support
Port the async pool and notify code to windows.
Reviewed-by: Rich Salz <rsalz@openssl.org>
-rw-r--r-- | crypto/async/Makefile | 3 | ||||
-rw-r--r-- | crypto/async/arch/async_posix.c | 4 | ||||
-rw-r--r-- | crypto/async/arch/async_win.c | 98 | ||||
-rw-r--r-- | crypto/async/arch/async_win.h | 2 | ||||
-rw-r--r-- | crypto/async/async.c | 23 | ||||
-rw-r--r-- | crypto/async/async_locl.h | 4 |
6 files changed, 121 insertions, 13 deletions
diff --git a/crypto/async/Makefile b/crypto/async/Makefile index c09cb31a79..4f0b3926de 100644 --- a/crypto/async/Makefile +++ b/crypto/async/Makefile @@ -22,8 +22,7 @@ LIBOBJ=async.o arch/async_posix.o arch/async_win.o SRC= $(LIBSRC) -EXHEADER= async.h -HEADER= $(EXHEADER) async_locl.h arch/async_posix.h arch/async_win.h +HEADER= async_locl.h arch/async_posix.h arch/async_win.h arch/async_null.h ALL= $(GENERAL) $(SRC) $(HEADER) diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c index d85a537d09..4333c87f1d 100644 --- a/crypto/async/arch/async_posix.c +++ b/crypto/async/arch/async_posix.c @@ -120,12 +120,13 @@ STACK_OF(ASYNC_JOB) *async_get_pool(void) return pool; } -void async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size, +int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size, size_t max_size) { pool = poolin; pool_curr_size = curr_size; pool_max_size = max_size; + return 1; } void async_increment_pool_size(void) @@ -146,6 +147,7 @@ size_t async_pool_max_size(void) void async_release_pool(void) { sk_ASYNC_JOB_free(pool); + pool = NULL; } int async_pool_can_grow(void) diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c index 23447b068d..2afa306bc0 100644 --- a/crypto/async/arch/async_win.c +++ b/crypto/async/arch/async_win.c @@ -56,7 +56,13 @@ #ifdef ASYNC_WIN # include <windows.h> -# include "cryptlib.h" +# include "internal/cryptlib.h" + +struct winpool { + STACK_OF(ASYNC_JOB) *pool; + size_t curr_size; + size_t max_size; +}; void ASYNC_start_func(void); @@ -81,4 +87,94 @@ VOID CALLBACK ASYNC_start_func_win(PVOID unused) ASYNC_start_func(); } +int async_pipe(int *pipefds) +{ + if (_pipe(pipefds, 256, _O_BINARY) == 0) + return 1; + + return 0; +} + +int async_write1(int fd, const void *buf) +{ + if (_write(fd, buf, 1) > 0) + return 1; + + return 0; +} + +int async_read1(int fd, void *buf) +{ + if (_read(fd, buf, 1) > 0) + return 1; + + return 0; +} + +STACK_OF(ASYNC_JOB) *async_get_pool(void) +{ + struct winpool *pool; + pool = (struct winpool *) + CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL); + return pool->pool; +} + + +int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size, + size_t max_size) +{ + struct winpool *pool; + pool = OPENSSL_malloc(sizeof *pool); + if (!pool) + return 0; + + pool->pool = poolin; + pool->curr_size = curr_size; + pool->max_size = max_size; + CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL, (void *)pool); + return 1; +} + +void async_increment_pool_size(void) +{ + struct winpool *pool; + pool = (struct winpool *) + CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL); + pool->curr_size++; +} + +void async_release_job_to_pool(ASYNC_JOB *job) +{ + struct winpool *pool; + pool = (struct winpool *) + CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL); + sk_ASYNC_JOB_push(pool->pool, job); +} + +size_t async_pool_max_size(void) +{ + struct winpool *pool; + pool = (struct winpool *) + CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL); + return pool->max_size; +} + +void async_release_pool(void) +{ + struct winpool *pool; + pool = (struct winpool *) + CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL); + sk_ASYNC_JOB_free(pool->pool); + OPENSSL_free(pool); + CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL, NULL); +} + +int async_pool_can_grow(void) +{ + struct winpool *pool; + pool = (struct winpool *) + CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL); + return (pool->max_size == 0) || (pool->curr_size < pool->max_size); +} + #endif diff --git a/crypto/async/arch/async_win.h b/crypto/async/arch/async_win.h index 6c2a31007d..4ecaa02af6 100644 --- a/crypto/async/arch/async_win.h +++ b/crypto/async/arch/async_win.h @@ -62,7 +62,7 @@ # define ASYNC_ARCH # include <windows.h> -# include "cryptlib.h" +# include "internal/cryptlib.h" typedef struct async_fibre_st { LPVOID fibre; diff --git a/crypto/async/async.c b/crypto/async/async.c index c1f9b22478..ed3ed739ea 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -295,6 +295,16 @@ int ASYNC_in_job(void) return 0; } +static void async_empty_pool(STACK_OF(ASYNC_JOB) *pool) +{ + ASYNC_JOB *job; + + do { + job = sk_ASYNC_JOB_pop(pool); + ASYNC_JOB_free(job); + } while (job); +} + int ASYNC_init_pool(size_t max_size, size_t init_size) { STACK_OF(ASYNC_JOB) *pool; @@ -326,23 +336,24 @@ int ASYNC_init_pool(size_t max_size, size_t init_size) } } - async_set_pool(pool, curr_size, max_size); + if (!async_set_pool(pool, curr_size, max_size)) { + async_empty_pool(pool); + sk_ASYNC_JOB_free(pool); + return 0; + } return 1; } void ASYNC_free_pool(void) { - ASYNC_JOB *job; STACK_OF(ASYNC_JOB) *pool; pool = async_get_pool(); if (pool == NULL) return; - do { - job = sk_ASYNC_JOB_pop(pool); - ASYNC_JOB_free(job); - } while (job); + + async_empty_pool(pool); async_release_pool(); } diff --git a/crypto/async/async_locl.h b/crypto/async/async_locl.h index 4bfc37fe20..ad85fa074e 100644 --- a/crypto/async/async_locl.h +++ b/crypto/async/async_locl.h @@ -80,8 +80,8 @@ DECLARE_STACK_OF(ASYNC_JOB) void ASYNC_start_func(void); STACK_OF(ASYNC_JOB) *async_get_pool(void); -void async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size, - size_t max_size); +int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size, + size_t max_size); void async_increment_pool_size(void); void async_release_job_to_pool(ASYNC_JOB *job); size_t async_pool_max_size(void); |