2015-02-17 13:30:22 +00:00
|
|
|
/*
|
2016-05-17 18:24:46 +00:00
|
|
|
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2015-02-17 13:30:22 +00:00
|
|
|
*
|
2016-05-17 18:24:46 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2015-02-17 13:30:22 +00:00
|
|
|
*/
|
2016-05-17 18:24:46 +00:00
|
|
|
|
2015-11-22 01:14:43 +00:00
|
|
|
#ifndef OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
|
|
|
|
#define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
|
2015-02-17 13:30:22 +00:00
|
|
|
#include <openssl/e_os2.h>
|
|
|
|
|
2016-05-01 11:35:31 +00:00
|
|
|
#if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) && defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) && !defined(__ANDROID__)
|
2015-02-17 13:30:22 +00:00
|
|
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
|
|
|
# if _POSIX_VERSION >= 200112L
|
|
|
|
|
2015-11-13 23:54:44 +00:00
|
|
|
# include <pthread.h>
|
|
|
|
|
2015-10-06 10:25:16 +00:00
|
|
|
# define ASYNC_POSIX
|
2015-02-17 13:30:22 +00:00
|
|
|
# define ASYNC_ARCH
|
|
|
|
|
|
|
|
# include <ucontext.h>
|
2015-05-05 14:08:39 +00:00
|
|
|
# include <setjmp.h>
|
|
|
|
# include "e_os.h"
|
2015-02-17 13:30:22 +00:00
|
|
|
|
|
|
|
typedef struct async_fibre_st {
|
|
|
|
ucontext_t fibre;
|
2015-05-05 14:08:39 +00:00
|
|
|
jmp_buf env;
|
|
|
|
int env_init;
|
2015-10-06 10:25:16 +00:00
|
|
|
} async_fibre;
|
2015-02-17 13:30:22 +00:00
|
|
|
|
2015-10-06 10:25:16 +00:00
|
|
|
static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
|
2015-05-05 14:08:39 +00:00
|
|
|
{
|
|
|
|
o->env_init = 1;
|
|
|
|
|
2015-10-09 14:55:01 +00:00
|
|
|
if (!r || !_setjmp(o->env)) {
|
2015-05-05 14:08:39 +00:00
|
|
|
if (n->env_init)
|
2015-10-09 14:55:01 +00:00
|
|
|
_longjmp(n->env, 1);
|
2015-05-05 14:08:39 +00:00
|
|
|
else
|
|
|
|
setcontext(&n->fibre);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:25:16 +00:00
|
|
|
# define async_fibre_init_dispatcher(d)
|
2015-02-17 13:30:22 +00:00
|
|
|
|
2015-11-22 01:14:43 +00:00
|
|
|
int async_fibre_makecontext(async_fibre *fibre);
|
2015-10-06 10:25:16 +00:00
|
|
|
void async_fibre_free(async_fibre *fibre);
|
2015-02-17 13:30:22 +00:00
|
|
|
|
|
|
|
# endif
|
|
|
|
#endif
|
2015-11-22 01:14:43 +00:00
|
|
|
#endif /* OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H */
|