aboutsummaryrefslogtreecommitdiff
path: root/crypto/async/arch
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2015-11-13 15:21:20 +0000
committerMatt Caswell <matt@openssl.org>2015-11-20 23:37:17 +0000
commit27949c353e68825f119410f8fd73ae1d667581c7 (patch)
tree8047b155949437358c5baed4769487472b2e70c7 /crypto/async/arch
parent2b2c78d4f0a73498739cfc0879299d7325c35160 (diff)
downloadopenssl-27949c353e68825f119410f8fd73ae1d667581c7.zip
openssl-27949c353e68825f119410f8fd73ae1d667581c7.tar.gz
openssl-27949c353e68825f119410f8fd73ae1d667581c7.tar.bz2
Simplify async pool handling
A lot of the pool handling code was in the arch specific files, but was actually boiler plate and the same across the implementations. This commit moves as much code as possible out of the arch specific files. Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/async/arch')
-rw-r--r--crypto/async/arch/async_null.c35
-rw-r--r--crypto/async/arch/async_null.h2
-rw-r--r--crypto/async/arch/async_posix.c59
-rw-r--r--crypto/async/arch/async_posix.h9
-rw-r--r--crypto/async/arch/async_win.c69
-rw-r--r--crypto/async/arch/async_win.h3
6 files changed, 33 insertions, 144 deletions
diff --git a/crypto/async/arch/async_null.c b/crypto/async/arch/async_null.c
index f015c90..8de50ed 100644
--- a/crypto/async/arch/async_null.c
+++ b/crypto/async/arch/async_null.c
@@ -56,41 +56,6 @@
#ifdef ASYNC_NULL
-STACK_OF(ASYNC_JOB) *async_get_pool(void)
-{
- return NULL;
-}
-
-int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size,
- size_t max_size)
-{
- return 0;
-}
-
-void async_increment_pool_size(void)
-{
- return;
-}
-
-void async_release_job_to_pool(ASYNC_JOB *job)
-{
- return;
-}
-
-size_t async_pool_max_size(void)
-{
- return 0;
-}
-
-void async_release_pool(void)
-{
- return;
-}
-
-int async_pool_can_grow(void) {
- return 0;
-}
-
int async_pipe(OSSL_ASYNC_FD *pipefds)
{
return -1;
diff --git a/crypto/async/arch/async_null.h b/crypto/async/arch/async_null.h
index e9344f5..684e373 100644
--- a/crypto/async/arch/async_null.h
+++ b/crypto/async/arch/async_null.h
@@ -72,5 +72,7 @@ typedef struct async_fibre_st {
# define async_fibre_makecontext(c)
# define async_fibre_free(f)
# define async_fibre_init_dispatcher(f)
+# define async_get_pool() NULL
+# define async_set_pool(p) 0
#endif
diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c
index 3f6cb62..541c8b3 100644
--- a/crypto/async/arch/async_posix.c
+++ b/crypto/async/arch/async_posix.c
@@ -61,17 +61,11 @@
# include <openssl/crypto.h>
# include <openssl/async.h>
-__thread async_ctx *sysvctx;
+__thread async_ctx *posixctx;
+__thread async_pool *posixpool;
#define STACKSIZE 32768
-extern __thread size_t posixpool_max_size;
-extern __thread size_t posixpool_curr_size;
-extern __thread STACK_OF(ASYNC_JOB) *posixpool;
-__thread size_t posixpool_max_size = 0;
-__thread size_t posixpool_curr_size = 0;
-__thread STACK_OF(ASYNC_JOB) *posixpool = NULL;
-
int async_fibre_init(async_fibre *fibre)
{
void *stack = NULL;
@@ -103,6 +97,14 @@ int async_pipe(OSSL_ASYNC_FD *pipefds)
return 0;
}
+int async_close_fd(OSSL_ASYNC_FD fd)
+{
+ if (close(fd) != 0)
+ return 0;
+
+ return 1;
+}
+
int async_write1(OSSL_ASYNC_FD fd, const void *buf)
{
if (write(fd, buf, 1) > 0)
@@ -119,45 +121,4 @@ int async_read1(OSSL_ASYNC_FD fd, void *buf)
return 0;
}
-STACK_OF(ASYNC_JOB) *async_get_pool(void)
-{
- return posixpool;
-}
-
-int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size,
- size_t max_size)
-{
- posixpool = poolin;
- posixpool_curr_size = curr_size;
- posixpool_max_size = max_size;
- return 1;
-}
-
-void async_increment_pool_size(void)
-{
- posixpool_curr_size++;
-}
-
-void async_release_job_to_pool(ASYNC_JOB *job)
-{
- sk_ASYNC_JOB_push(posixpool, job);
-}
-
-size_t async_pool_max_size(void)
-{
- return posixpool_max_size;
-}
-
-void async_release_pool(void)
-{
- sk_ASYNC_JOB_free(posixpool);
- posixpool = NULL;
-}
-
-int async_pool_can_grow(void)
-{
- return (posixpool_max_size == 0)
- || (posixpool_curr_size < posixpool_max_size);
-}
-
#endif
diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h
index d5b2399..9fdccf9 100644
--- a/crypto/async/arch/async_posix.h
+++ b/crypto/async/arch/async_posix.h
@@ -73,7 +73,8 @@
# include <setjmp.h>
# include "e_os.h"
-extern __thread async_ctx *sysvctx;
+extern __thread async_ctx *posixctx;
+extern __thread async_pool *posixpool;
typedef struct async_fibre_st {
ucontext_t fibre;
@@ -81,8 +82,10 @@ typedef struct async_fibre_st {
int env_init;
} async_fibre;
-# define async_set_ctx(nctx) (sysvctx = (nctx))
-# define async_get_ctx() (sysvctx)
+# define async_set_ctx(nctx) (posixctx = (nctx))
+# define async_get_ctx() (posixctx)
+# define async_set_pool(p) (posixpool = (p))
+# define async_get_pool() (posixpool)
static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
{
diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c
index 9841a9c..4eb449d 100644
--- a/crypto/async/arch/async_win.c
+++ b/crypto/async/arch/async_win.c
@@ -51,7 +51,7 @@
* ====================================================================
*/
-#include "async_win.h"
+#include "../async_locl.h"
#ifdef ASYNC_WIN
@@ -95,6 +95,14 @@ int async_pipe(OSSL_ASYNC_FD *pipefds)
return 1;
}
+int async_close_fd(OSSL_ASYNC_FD fd)
+{
+ if (CloseHandle(fd) == 0)
+ return 0;
+
+ return 1;
+}
+
int async_write1(OSSL_ASYNC_FD fd, const void *buf)
{
DWORD numwritten = 0;
@@ -115,70 +123,17 @@ int async_read1(OSSL_ASYNC_FD fd, void *buf)
return 0;
}
-STACK_OF(ASYNC_JOB) *async_get_pool(void)
+async_pool *async_get_pool(void)
{
- struct winpool *pool;
- pool = (struct winpool *)
+ return (async_pool *)
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)
+int async_set_pool(async_pool *pool)
{
- struct winpool *pool;
- pool = OPENSSL_malloc(sizeof *pool);
- if (pool == NULL)
- 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 42574a7..5e91732 100644
--- a/crypto/async/arch/async_win.h
+++ b/crypto/async/arch/async_win.h
@@ -81,4 +81,7 @@ typedef struct async_fibre_st {
int async_fibre_init_dispatcher(async_fibre *fibre);
VOID CALLBACK async_start_func_win(PVOID unused);
+async_pool *async_get_pool(void);
+int async_set_pool(async_pool *pool);
+
#endif