Normalise ASYNC naming

Tidied up the naming of functions and structures to be consistent

Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Matt Caswell 2015-10-06 11:25:16 +01:00
parent 134b28f883
commit 636ca4ff64
7 changed files with 98 additions and 99 deletions

View file

@ -63,15 +63,14 @@
typedef struct async_fibre_st { typedef struct async_fibre_st {
int dummy; int dummy;
} ASYNC_FIBRE; } async_fibre;
# define async_set_ctx(nctx) 0
# define ASYNC_set_ctx(nctx) 0 # define async_get_ctx() ((async_ctx *)NULL)
# define ASYNC_get_ctx() ((ASYNC_CTX *)NULL) # define async_fibre_swapcontext(o,n,r) 0
# define ASYNC_FIBRE_swapcontext(o,n,r) 0 # define async_fibre_makecontext(c)
# define ASYNC_FIBRE_makecontext(c) # define async_fibre_free(f)
# define ASYNC_FIBRE_free(f) # define async_fibre_init_dispatcher(f)
# define ASYNC_FIBRE_init_dispatcher(f)
#endif #endif

View file

@ -54,14 +54,14 @@
#include "../async_locl.h" #include "../async_locl.h"
#include <openssl/async.h> #include <openssl/async.h>
#ifdef ASYNC_SYSV #ifdef ASYNC_POSIX
# include <stddef.h> # include <stddef.h>
# include <ucontext.h> # include <ucontext.h>
# include <unistd.h> # include <unistd.h>
# include <openssl/crypto.h> # include <openssl/crypto.h>
# include <openssl/async.h> # include <openssl/async.h>
__thread ASYNC_CTX *sysvctx; __thread async_ctx *sysvctx;
#define STACKSIZE 32768 #define STACKSIZE 32768
@ -69,7 +69,7 @@ __thread size_t pool_max_size = 0;
__thread size_t pool_curr_size = 0; __thread size_t pool_curr_size = 0;
__thread STACK_OF(ASYNC_JOB) *pool = NULL; __thread STACK_OF(ASYNC_JOB) *pool = NULL;
int ASYNC_FIBRE_init(ASYNC_FIBRE *fibre) int async_fibre_init(async_fibre *fibre)
{ {
void *stack = NULL; void *stack = NULL;
@ -85,7 +85,7 @@ int ASYNC_FIBRE_init(ASYNC_FIBRE *fibre)
return 1; return 1;
} }
void ASYNC_FIBRE_free(ASYNC_FIBRE *fibre) void async_fibre_free(async_fibre *fibre)
{ {
if (fibre->fibre.uc_stack.ss_sp) if (fibre->fibre.uc_stack.ss_sp)
OPENSSL_free(fibre->fibre.uc_stack.ss_sp); OPENSSL_free(fibre->fibre.uc_stack.ss_sp);

View file

@ -58,25 +58,25 @@
# if _POSIX_VERSION >= 200112L # if _POSIX_VERSION >= 200112L
# define ASYNC_SYSV # define ASYNC_POSIX
# define ASYNC_ARCH # define ASYNC_ARCH
# include <ucontext.h> # include <ucontext.h>
# include <setjmp.h> # include <setjmp.h>
# include "e_os.h" # include "e_os.h"
extern __thread ASYNC_CTX *sysvctx; extern __thread async_ctx *sysvctx;
typedef struct async_fibre_st { typedef struct async_fibre_st {
ucontext_t fibre; ucontext_t fibre;
jmp_buf env; jmp_buf env;
int env_init; int env_init;
} ASYNC_FIBRE; } async_fibre;
# define ASYNC_set_ctx(nctx) (sysvctx = (nctx)) # define async_set_ctx(nctx) (sysvctx = (nctx))
# define ASYNC_get_ctx() (sysvctx) # define async_get_ctx() (sysvctx)
static inline int ASYNC_FIBRE_swapcontext(ASYNC_FIBRE *o, ASYNC_FIBRE *n, int r) static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
{ {
o->env_init = 1; o->env_init = 1;
@ -90,14 +90,14 @@ static inline int ASYNC_FIBRE_swapcontext(ASYNC_FIBRE *o, ASYNC_FIBRE *n, int r)
return 1; return 1;
} }
# define ASYNC_FIBRE_makecontext(c) \ # define async_fibre_makecontext(c) \
(ASYNC_FIBRE_init(c) \ (async_fibre_init(c) \
&& !getcontext(&(c)->fibre) \ && !getcontext(&(c)->fibre) \
&& (makecontext(&(c)->fibre, ASYNC_start_func, 0), 1)) && (makecontext(&(c)->fibre, async_start_func, 0), 1))
# define ASYNC_FIBRE_init_dispatcher(d) # define async_fibre_init_dispatcher(d)
int ASYNC_FIBRE_init(ASYNC_FIBRE *fibre); int async_fibre_init(async_fibre *fibre);
void ASYNC_FIBRE_free(ASYNC_FIBRE *fibre); void async_fibre_free(async_fibre *fibre);
# endif # endif
#endif #endif

View file

@ -64,9 +64,9 @@ struct winpool {
size_t max_size; size_t max_size;
}; };
void ASYNC_start_func(void); void async_start_func(void);
int ASYNC_FIBRE_init_dispatcher(ASYNC_FIBRE *fibre) int async_fibre_init_dispatcher(async_fibre *fibre)
{ {
LPVOID dispatcher; LPVOID dispatcher;
@ -82,9 +82,9 @@ int ASYNC_FIBRE_init_dispatcher(ASYNC_FIBRE *fibre)
return 1; return 1;
} }
VOID CALLBACK ASYNC_start_func_win(PVOID unused) VOID CALLBACK async_start_func_win(PVOID unused)
{ {
ASYNC_start_func(); async_start_func();
} }
int async_pipe(int *pipefds) int async_pipe(int *pipefds)

View file

@ -66,19 +66,19 @@
typedef struct async_fibre_st { typedef struct async_fibre_st {
LPVOID fibre; LPVOID fibre;
} ASYNC_FIBRE; } async_fibre;
# define ASYNC_set_ctx(nctx) \ # define async_set_ctx(nctx) \
(CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_CTX, (void *)(nctx))) (CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_CTX, (void *)(nctx)))
# define ASYNC_get_ctx() \ # define async_get_ctx() \
((ASYNC_CTX *)CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_CTX)) ((async_ctx *)CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_CTX))
# define ASYNC_FIBRE_swapcontext(o,n,r) \ # define async_fibre_swapcontext(o,n,r) \
(SwitchToFiber((n)->fibre), 1) (SwitchToFiber((n)->fibre), 1)
# define ASYNC_FIBRE_makecontext(c) \ # define async_fibre_makecontext(c) \
((c)->fibre = CreateFiber(0, ASYNC_start_func_win, 0)) ((c)->fibre = CreateFiber(0, async_start_func_win, 0))
# define ASYNC_FIBRE_free(f) (DeleteFiber((f)->fibre)) # define async_fibre_free(f) (DeleteFiber((f)->fibre))
int ASYNC_FIBRE_init_dispatcher(ASYNC_FIBRE *fibre); int async_fibre_init_dispatcher(async_fibre *fibre);
VOID CALLBACK ASYNC_start_func_win(PVOID unused); VOID CALLBACK async_start_func_win(PVOID unused);
#endif #endif

View file

@ -60,18 +60,18 @@
#define ASYNC_JOB_PAUSED 2 #define ASYNC_JOB_PAUSED 2
#define ASYNC_JOB_STOPPING 3 #define ASYNC_JOB_STOPPING 3
static ASYNC_CTX *ASYNC_CTX_new(void) static async_ctx *async_ctx_new(void)
{ {
ASYNC_CTX *nctx = NULL; async_ctx *nctx = NULL;
if(!(nctx = OPENSSL_malloc(sizeof (ASYNC_CTX)))) { if(!(nctx = OPENSSL_malloc(sizeof (async_ctx)))) {
/* Error here */ /* Error here */
goto err; goto err;
} }
ASYNC_FIBRE_init_dispatcher(&nctx->dispatcher); async_fibre_init_dispatcher(&nctx->dispatcher);
nctx->currjob = NULL; nctx->currjob = NULL;
if(!ASYNC_set_ctx(nctx)) if(!async_set_ctx(nctx))
goto err; goto err;
return nctx; return nctx;
@ -83,19 +83,19 @@ err:
return NULL; return NULL;
} }
static int ASYNC_CTX_free(void) static int async_ctx_free(void)
{ {
if(ASYNC_get_ctx()) { if(async_get_ctx()) {
OPENSSL_free(ASYNC_get_ctx()); OPENSSL_free(async_get_ctx());
} }
if(!ASYNC_set_ctx(NULL)) if(!async_set_ctx(NULL))
return 0; return 0;
return 1; return 1;
} }
static ASYNC_JOB *ASYNC_JOB_new(void) static ASYNC_JOB *async_job_new(void)
{ {
ASYNC_JOB *job = NULL; ASYNC_JOB *job = NULL;
int pipefds[2]; int pipefds[2];
@ -119,12 +119,12 @@ static ASYNC_JOB *ASYNC_JOB_new(void)
return job; return job;
} }
static void ASYNC_JOB_free(ASYNC_JOB *job) static void async_job_free(ASYNC_JOB *job)
{ {
if(job) { if(job) {
if(job->funcargs) if(job->funcargs)
OPENSSL_free(job->funcargs); OPENSSL_free(job->funcargs);
ASYNC_FIBRE_free(&job->fibrectx); async_fibre_free(&job->fibrectx);
OPENSSL_free(job); OPENSSL_free(job);
} }
} }
@ -150,9 +150,9 @@ static ASYNC_JOB *async_get_pool_job(void) {
if (!async_pool_can_grow()) if (!async_pool_can_grow())
return NULL; return NULL;
job = ASYNC_JOB_new(); job = async_job_new();
if (job) { if (job) {
ASYNC_FIBRE_makecontext(&job->fibrectx); async_fibre_makecontext(&job->fibrectx);
async_increment_pool_size(); async_increment_pool_size();
} }
} }
@ -167,19 +167,19 @@ static void async_release_job(ASYNC_JOB *job) {
async_release_job_to_pool(job); async_release_job_to_pool(job);
} }
void ASYNC_start_func(void) void async_start_func(void)
{ {
ASYNC_JOB *job; ASYNC_JOB *job;
while (1) { while (1) {
/* Run the job */ /* Run the job */
job = ASYNC_get_ctx()->currjob; job = async_get_ctx()->currjob;
job->ret = job->func(job->funcargs); job->ret = job->func(job->funcargs);
/* Stop the job */ /* Stop the job */
job->status = ASYNC_JOB_STOPPING; job->status = ASYNC_JOB_STOPPING;
if(!ASYNC_FIBRE_swapcontext(&job->fibrectx, if(!async_fibre_swapcontext(&job->fibrectx,
&ASYNC_get_ctx()->dispatcher, 1)) { &async_get_ctx()->dispatcher, 1)) {
/* /*
* Should not happen. Getting here will close the thread...can't do much * Should not happen. Getting here will close the thread...can't do much
* about it * about it
@ -191,73 +191,73 @@ void ASYNC_start_func(void)
int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *), int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
void *args, size_t size) void *args, size_t size)
{ {
if(!ASYNC_get_ctx() && !ASYNC_CTX_new()) { if(!async_get_ctx() && !async_ctx_new()) {
return ASYNC_ERR; return ASYNC_ERR;
} }
if(*job) { if(*job) {
ASYNC_get_ctx()->currjob = *job; async_get_ctx()->currjob = *job;
} }
for (;;) { for (;;) {
if(ASYNC_get_ctx()->currjob) { if(async_get_ctx()->currjob) {
if(ASYNC_get_ctx()->currjob->status == ASYNC_JOB_STOPPING) { if(async_get_ctx()->currjob->status == ASYNC_JOB_STOPPING) {
*ret = ASYNC_get_ctx()->currjob->ret; *ret = async_get_ctx()->currjob->ret;
async_release_job(ASYNC_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
ASYNC_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
*job = NULL; *job = NULL;
return ASYNC_FINISH; return ASYNC_FINISH;
} }
if(ASYNC_get_ctx()->currjob->status == ASYNC_JOB_PAUSING) { if(async_get_ctx()->currjob->status == ASYNC_JOB_PAUSING) {
*job = ASYNC_get_ctx()->currjob; *job = async_get_ctx()->currjob;
ASYNC_get_ctx()->currjob->status = ASYNC_JOB_PAUSED; async_get_ctx()->currjob->status = ASYNC_JOB_PAUSED;
ASYNC_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
return ASYNC_PAUSE; return ASYNC_PAUSE;
} }
if(ASYNC_get_ctx()->currjob->status == ASYNC_JOB_PAUSED) { if(async_get_ctx()->currjob->status == ASYNC_JOB_PAUSED) {
ASYNC_get_ctx()->currjob = *job; async_get_ctx()->currjob = *job;
/* Resume previous job */ /* Resume previous job */
if(!ASYNC_FIBRE_swapcontext(&ASYNC_get_ctx()->dispatcher, if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
&ASYNC_get_ctx()->currjob->fibrectx, 1)) &async_get_ctx()->currjob->fibrectx, 1))
goto err; goto err;
continue; continue;
} }
/* Should not happen */ /* Should not happen */
async_release_job(ASYNC_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
ASYNC_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
*job = NULL; *job = NULL;
return ASYNC_ERR; return ASYNC_ERR;
} }
/* Start a new job */ /* Start a new job */
if(!(ASYNC_get_ctx()->currjob = async_get_pool_job())) { if(!(async_get_ctx()->currjob = async_get_pool_job())) {
return ASYNC_NO_JOBS; return ASYNC_NO_JOBS;
} }
if(args != NULL) { if(args != NULL) {
ASYNC_get_ctx()->currjob->funcargs = OPENSSL_malloc(size); async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size);
if(!ASYNC_get_ctx()->currjob->funcargs) { if(!async_get_ctx()->currjob->funcargs) {
async_release_job(ASYNC_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
ASYNC_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
return ASYNC_ERR; return ASYNC_ERR;
} }
memcpy(ASYNC_get_ctx()->currjob->funcargs, args, size); memcpy(async_get_ctx()->currjob->funcargs, args, size);
} else { } else {
ASYNC_get_ctx()->currjob->funcargs = NULL; async_get_ctx()->currjob->funcargs = NULL;
} }
ASYNC_get_ctx()->currjob->func = func; async_get_ctx()->currjob->func = func;
if(!ASYNC_FIBRE_swapcontext(&ASYNC_get_ctx()->dispatcher, if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
&ASYNC_get_ctx()->currjob->fibrectx, 1)) &async_get_ctx()->currjob->fibrectx, 1))
goto err; goto err;
} }
err: err:
async_release_job(ASYNC_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
ASYNC_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
*job = NULL; *job = NULL;
return ASYNC_ERR; return ASYNC_ERR;
} }
@ -267,14 +267,14 @@ int ASYNC_pause_job(void)
{ {
ASYNC_JOB *job; ASYNC_JOB *job;
if(!ASYNC_get_ctx() || !ASYNC_get_ctx()->currjob) if(!async_get_ctx() || !async_get_ctx()->currjob)
return 0; return 0;
job = ASYNC_get_ctx()->currjob; job = async_get_ctx()->currjob;
job->status = ASYNC_JOB_PAUSING; job->status = ASYNC_JOB_PAUSING;
if(!ASYNC_FIBRE_swapcontext(&job->fibrectx, if(!async_fibre_swapcontext(&job->fibrectx,
&ASYNC_get_ctx()->dispatcher, 1)) { &async_get_ctx()->dispatcher, 1)) {
/* Error */ /* Error */
return 0; return 0;
} }
@ -288,7 +288,7 @@ static void async_empty_pool(STACK_OF(ASYNC_JOB) *pool)
do { do {
job = sk_ASYNC_JOB_pop(pool); job = sk_ASYNC_JOB_pop(pool);
ASYNC_JOB_free(job); async_job_free(job);
} while (job); } while (job);
} }
@ -307,9 +307,9 @@ int ASYNC_init_pool(size_t max_size, size_t init_size)
/* Pre-create jobs as required */ /* Pre-create jobs as required */
while (init_size) { while (init_size) {
ASYNC_JOB *job; ASYNC_JOB *job;
job = ASYNC_JOB_new(); job = async_job_new();
if (job) { if (job) {
ASYNC_FIBRE_makecontext(&job->fibrectx); async_fibre_makecontext(&job->fibrectx);
job->funcargs = NULL; job->funcargs = NULL;
sk_ASYNC_JOB_push(pool, job); sk_ASYNC_JOB_push(pool, job);
curr_size++; curr_size++;
@ -342,13 +342,13 @@ void ASYNC_free_pool(void)
async_empty_pool(pool); async_empty_pool(pool);
async_release_pool(); async_release_pool();
ASYNC_CTX_free(); async_ctx_free();
} }
ASYNC_JOB *ASYNC_get_current_job(void) ASYNC_JOB *ASYNC_get_current_job(void)
{ {
ASYNC_CTX *ctx; async_ctx *ctx;
if((ctx = ASYNC_get_ctx()) == NULL) if((ctx = async_get_ctx()) == NULL)
return NULL; return NULL;
return ctx->currjob; return ctx->currjob;

View file

@ -54,19 +54,19 @@
#include <openssl/async.h> #include <openssl/async.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
typedef struct async_ctx_st ASYNC_CTX; typedef struct async_ctx_st async_ctx;
#include "arch/async_win.h" #include "arch/async_win.h"
#include "arch/async_posix.h" #include "arch/async_posix.h"
#include "arch/async_null.h" #include "arch/async_null.h"
struct async_ctx_st { struct async_ctx_st {
ASYNC_FIBRE dispatcher; async_fibre dispatcher;
ASYNC_JOB *currjob; ASYNC_JOB *currjob;
}; };
struct async_job_st { struct async_job_st {
ASYNC_FIBRE fibrectx; async_fibre fibrectx;
int (*func) (void *); int (*func) (void *);
void *funcargs; void *funcargs;
int ret; int ret;
@ -78,7 +78,7 @@ struct async_job_st {
DECLARE_STACK_OF(ASYNC_JOB) DECLARE_STACK_OF(ASYNC_JOB)
void ASYNC_start_func(void); void async_start_func(void);
STACK_OF(ASYNC_JOB) *async_get_pool(void); STACK_OF(ASYNC_JOB) *async_get_pool(void);
int 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); size_t max_size);