Cleanup openssl.ec
[openssl.git] / crypto / async / arch / async_posix.h
1 /*
2  * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
11 #define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
12 #include <openssl/e_os2.h>
13
14 #if (defined(OPENSSL_SYS_UNIX) || defined(OPENSSL_SYS_CYGWIN)) && defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) && !defined(__ANDROID__)
15
16 # include <unistd.h>
17
18 # if _POSIX_VERSION >= 200112L
19
20 # include <pthread.h>
21
22 #  define ASYNC_POSIX
23 #  define ASYNC_ARCH
24
25 #  include <ucontext.h>
26 #  include <setjmp.h>
27 #  include "e_os.h"
28
29 typedef struct async_fibre_st {
30     ucontext_t fibre;
31     jmp_buf env;
32     int env_init;
33 } async_fibre;
34
35 static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
36 {
37     o->env_init = 1;
38
39     if (!r || !_setjmp(o->env)) {
40         if (n->env_init)
41             _longjmp(n->env, 1);
42         else
43             setcontext(&n->fibre);
44     }
45
46     return 1;
47 }
48
49 #  define async_fibre_init_dispatcher(d)
50
51 int async_fibre_makecontext(async_fibre *fibre);
52 void async_fibre_free(async_fibre *fibre);
53
54 # endif
55 #endif
56 #endif /* OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H */