# if _POSIX_VERSION >= 200112L
-# define ASYNC_SYSV
+# define ASYNC_POSIX
# define ASYNC_ARCH
# include <ucontext.h>
# include <setjmp.h>
# include "e_os.h"
-extern __thread ASYNC_CTX *sysvctx;
+extern __thread async_ctx *sysvctx;
typedef struct async_fibre_st {
ucontext_t fibre;
jmp_buf env;
int env_init;
-} ASYNC_FIBRE;
+} async_fibre;
-# define ASYNC_set_ctx(nctx) (sysvctx = (nctx))
-# define ASYNC_get_ctx() (sysvctx)
+# define async_set_ctx(nctx) (sysvctx = (nctx))
+# 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;
return 1;
}
-# define ASYNC_FIBRE_makecontext(c) \
- (ASYNC_FIBRE_init(c) \
+# define async_fibre_makecontext(c) \
+ (async_fibre_init(c) \
&& !getcontext(&(c)->fibre) \
- && (makecontext(&(c)->fibre, ASYNC_start_func, 0), 1))
-# define ASYNC_FIBRE_init_dispatcher(d)
+ && (makecontext(&(c)->fibre, async_start_func, 0), 1))
+# define async_fibre_init_dispatcher(d)
-int ASYNC_FIBRE_init(ASYNC_FIBRE *fibre);
-void ASYNC_FIBRE_free(ASYNC_FIBRE *fibre);
+int async_fibre_init(async_fibre *fibre);
+void async_fibre_free(async_fibre *fibre);
# endif
#endif
typedef struct async_fibre_st {
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)))
-# define ASYNC_get_ctx() \
- ((ASYNC_CTX *)CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_CTX))
-# define ASYNC_FIBRE_swapcontext(o,n,r) \
+# define async_get_ctx() \
+ ((async_ctx *)CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_CTX))
+# define async_fibre_swapcontext(o,n,r) \
(SwitchToFiber((n)->fibre), 1)
-# define ASYNC_FIBRE_makecontext(c) \
- ((c)->fibre = CreateFiber(0, ASYNC_start_func_win, 0))
-# define ASYNC_FIBRE_free(f) (DeleteFiber((f)->fibre))
+# define async_fibre_makecontext(c) \
+ ((c)->fibre = CreateFiber(0, async_start_func_win, 0))
+# define async_fibre_free(f) (DeleteFiber((f)->fibre))
-int ASYNC_FIBRE_init_dispatcher(ASYNC_FIBRE *fibre);
-VOID CALLBACK ASYNC_start_func_win(PVOID unused);
+int async_fibre_init_dispatcher(async_fibre *fibre);
+VOID CALLBACK async_start_func_win(PVOID unused);
#endif
#define ASYNC_JOB_PAUSED 2
#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 */
goto err;
}
- ASYNC_FIBRE_init_dispatcher(&nctx->dispatcher);
+ async_fibre_init_dispatcher(&nctx->dispatcher);
nctx->currjob = NULL;
- if(!ASYNC_set_ctx(nctx))
+ if(!async_set_ctx(nctx))
goto err;
return nctx;
return NULL;
}
-static int ASYNC_CTX_free(void)
+static int async_ctx_free(void)
{
- if(ASYNC_get_ctx()) {
- OPENSSL_free(ASYNC_get_ctx());
+ if(async_get_ctx()) {
+ OPENSSL_free(async_get_ctx());
}
- if(!ASYNC_set_ctx(NULL))
+ if(!async_set_ctx(NULL))
return 0;
return 1;
}
-static ASYNC_JOB *ASYNC_JOB_new(void)
+static ASYNC_JOB *async_job_new(void)
{
ASYNC_JOB *job = NULL;
int pipefds[2];
return job;
}
-static void ASYNC_JOB_free(ASYNC_JOB *job)
+static void async_job_free(ASYNC_JOB *job)
{
if(job) {
if(job->funcargs)
OPENSSL_free(job->funcargs);
- ASYNC_FIBRE_free(&job->fibrectx);
+ async_fibre_free(&job->fibrectx);
OPENSSL_free(job);
}
}
if (!async_pool_can_grow())
return NULL;
- job = ASYNC_JOB_new();
+ job = async_job_new();
if (job) {
- ASYNC_FIBRE_makecontext(&job->fibrectx);
+ async_fibre_makecontext(&job->fibrectx);
async_increment_pool_size();
}
}
async_release_job_to_pool(job);
}
-void ASYNC_start_func(void)
+void async_start_func(void)
{
ASYNC_JOB *job;
while (1) {
/* Run the job */
- job = ASYNC_get_ctx()->currjob;
+ job = async_get_ctx()->currjob;
job->ret = job->func(job->funcargs);
/* Stop the job */
job->status = ASYNC_JOB_STOPPING;
- if(!ASYNC_FIBRE_swapcontext(&job->fibrectx,
- &ASYNC_get_ctx()->dispatcher, 1)) {
+ if(!async_fibre_swapcontext(&job->fibrectx,
+ &async_get_ctx()->dispatcher, 1)) {
/*
* Should not happen. Getting here will close the thread...can't do much
* about it
int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
void *args, size_t size)
{
- if(!ASYNC_get_ctx() && !ASYNC_CTX_new()) {
+ if(!async_get_ctx() && !async_ctx_new()) {
return ASYNC_ERR;
}
if(*job) {
- ASYNC_get_ctx()->currjob = *job;
+ async_get_ctx()->currjob = *job;
}
for (;;) {
- if(ASYNC_get_ctx()->currjob) {
- if(ASYNC_get_ctx()->currjob->status == ASYNC_JOB_STOPPING) {
- *ret = ASYNC_get_ctx()->currjob->ret;
- async_release_job(ASYNC_get_ctx()->currjob);
- ASYNC_get_ctx()->currjob = NULL;
+ if(async_get_ctx()->currjob) {
+ if(async_get_ctx()->currjob->status == ASYNC_JOB_STOPPING) {
+ *ret = async_get_ctx()->currjob->ret;
+ async_release_job(async_get_ctx()->currjob);
+ async_get_ctx()->currjob = NULL;
*job = NULL;
return ASYNC_FINISH;
}
- if(ASYNC_get_ctx()->currjob->status == ASYNC_JOB_PAUSING) {
- *job = ASYNC_get_ctx()->currjob;
- ASYNC_get_ctx()->currjob->status = ASYNC_JOB_PAUSED;
- ASYNC_get_ctx()->currjob = NULL;
+ if(async_get_ctx()->currjob->status == ASYNC_JOB_PAUSING) {
+ *job = async_get_ctx()->currjob;
+ async_get_ctx()->currjob->status = ASYNC_JOB_PAUSED;
+ async_get_ctx()->currjob = NULL;
return ASYNC_PAUSE;
}
- if(ASYNC_get_ctx()->currjob->status == ASYNC_JOB_PAUSED) {
- ASYNC_get_ctx()->currjob = *job;
+ if(async_get_ctx()->currjob->status == ASYNC_JOB_PAUSED) {
+ async_get_ctx()->currjob = *job;
/* Resume previous job */
- if(!ASYNC_FIBRE_swapcontext(&ASYNC_get_ctx()->dispatcher,
- &ASYNC_get_ctx()->currjob->fibrectx, 1))
+ if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
+ &async_get_ctx()->currjob->fibrectx, 1))
goto err;
continue;
}
/* Should not happen */
- async_release_job(ASYNC_get_ctx()->currjob);
- ASYNC_get_ctx()->currjob = NULL;
+ async_release_job(async_get_ctx()->currjob);
+ async_get_ctx()->currjob = NULL;
*job = NULL;
return ASYNC_ERR;
}
/* 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;
}
if(args != NULL) {
- ASYNC_get_ctx()->currjob->funcargs = OPENSSL_malloc(size);
- if(!ASYNC_get_ctx()->currjob->funcargs) {
- async_release_job(ASYNC_get_ctx()->currjob);
- ASYNC_get_ctx()->currjob = NULL;
+ async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size);
+ if(!async_get_ctx()->currjob->funcargs) {
+ async_release_job(async_get_ctx()->currjob);
+ async_get_ctx()->currjob = NULL;
return ASYNC_ERR;
}
- memcpy(ASYNC_get_ctx()->currjob->funcargs, args, size);
+ memcpy(async_get_ctx()->currjob->funcargs, args, size);
} else {
- ASYNC_get_ctx()->currjob->funcargs = NULL;
+ async_get_ctx()->currjob->funcargs = NULL;
}
- ASYNC_get_ctx()->currjob->func = func;
- if(!ASYNC_FIBRE_swapcontext(&ASYNC_get_ctx()->dispatcher,
- &ASYNC_get_ctx()->currjob->fibrectx, 1))
+ async_get_ctx()->currjob->func = func;
+ if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher,
+ &async_get_ctx()->currjob->fibrectx, 1))
goto err;
}
err:
- async_release_job(ASYNC_get_ctx()->currjob);
- ASYNC_get_ctx()->currjob = NULL;
+ async_release_job(async_get_ctx()->currjob);
+ async_get_ctx()->currjob = NULL;
*job = NULL;
return ASYNC_ERR;
}
{
ASYNC_JOB *job;
- if(!ASYNC_get_ctx() || !ASYNC_get_ctx()->currjob)
+ if(!async_get_ctx() || !async_get_ctx()->currjob)
return 0;
- job = ASYNC_get_ctx()->currjob;
+ job = async_get_ctx()->currjob;
job->status = ASYNC_JOB_PAUSING;
- if(!ASYNC_FIBRE_swapcontext(&job->fibrectx,
- &ASYNC_get_ctx()->dispatcher, 1)) {
+ if(!async_fibre_swapcontext(&job->fibrectx,
+ &async_get_ctx()->dispatcher, 1)) {
/* Error */
return 0;
}
do {
job = sk_ASYNC_JOB_pop(pool);
- ASYNC_JOB_free(job);
+ async_job_free(job);
} while (job);
}
/* Pre-create jobs as required */
while (init_size) {
ASYNC_JOB *job;
- job = ASYNC_JOB_new();
+ job = async_job_new();
if (job) {
- ASYNC_FIBRE_makecontext(&job->fibrectx);
+ async_fibre_makecontext(&job->fibrectx);
job->funcargs = NULL;
sk_ASYNC_JOB_push(pool, job);
curr_size++;
async_empty_pool(pool);
async_release_pool();
- ASYNC_CTX_free();
+ async_ctx_free();
}
ASYNC_JOB *ASYNC_get_current_job(void)
{
- ASYNC_CTX *ctx;
- if((ctx = ASYNC_get_ctx()) == NULL)
+ async_ctx *ctx;
+ if((ctx = async_get_ctx()) == NULL)
return NULL;
return ctx->currjob;