786cf0099c1951a5278ea8149ef060ed271cbb77
[openssl.git] / crypto / async / async_locl.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 /*
11  * Must do this before including any header files, because on MacOS/X <stlib.h>
12  * includes <signal.h> which includes <ucontext.h>
13  */
14 #if defined(__APPLE__) && defined(__MACH__) && !defined(_XOPEN_SOURCE)
15 # define _XOPEN_SOURCE          /* Otherwise incomplete ucontext_t structure */
16 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
17 #endif
18
19 #include <internal/async.h>
20 #include <openssl/crypto.h>
21
22 typedef struct async_ctx_st async_ctx;
23 typedef struct async_pool_st async_pool;
24
25 #include "arch/async_win.h"
26 #include "arch/async_posix.h"
27 #include "arch/async_null.h"
28
29 struct async_ctx_st {
30     async_fibre dispatcher;
31     ASYNC_JOB *currjob;
32     unsigned int blocked;
33 };
34
35 struct async_job_st {
36     async_fibre fibrectx;
37     int (*func) (void *);
38     void *funcargs;
39     int ret;
40     int status;
41     ASYNC_WAIT_CTX *waitctx;
42 };
43
44 struct fd_lookup_st {
45     const void *key;
46     OSSL_ASYNC_FD fd;
47     void *custom_data;
48     void (*cleanup)(ASYNC_WAIT_CTX *, const void *, OSSL_ASYNC_FD, void *);
49     int add;
50     int del;
51     struct fd_lookup_st *next;
52 };
53
54 struct async_wait_ctx_st {
55     struct fd_lookup_st *fds;
56     size_t numadd;
57     size_t numdel;
58 };
59
60 DEFINE_STACK_OF(ASYNC_JOB)
61
62 struct async_pool_st {
63     STACK_OF(ASYNC_JOB) *jobs;
64     size_t curr_size;
65     size_t max_size;
66 };
67
68 void async_local_cleanup(void);
69 void async_start_func(void);
70 async_ctx *async_get_ctx(void);
71
72 void async_wait_ctx_reset_counts(ASYNC_WAIT_CTX *ctx);
73