2
0

async_posix.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2015-2018 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. #ifndef OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
  10. #define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
  11. #include <openssl/e_os2.h>
  12. #if defined(OPENSSL_SYS_UNIX) \
  13. && defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) \
  14. && !defined(__ANDROID__) && !defined(__OpenBSD__)
  15. # include <unistd.h>
  16. # if _POSIX_VERSION >= 200112L \
  17. && (_POSIX_VERSION < 200809L || defined(__GLIBC__))
  18. # include <pthread.h>
  19. # define ASYNC_POSIX
  20. # define ASYNC_ARCH
  21. # include <ucontext.h>
  22. # include <setjmp.h>
  23. typedef struct async_fibre_st {
  24. ucontext_t fibre;
  25. jmp_buf env;
  26. int env_init;
  27. } async_fibre;
  28. static ossl_inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
  29. {
  30. o->env_init = 1;
  31. if (!r || !_setjmp(o->env)) {
  32. if (n->env_init)
  33. _longjmp(n->env, 1);
  34. else
  35. setcontext(&n->fibre);
  36. }
  37. return 1;
  38. }
  39. # define async_fibre_init_dispatcher(d)
  40. int async_fibre_makecontext(async_fibre *fibre);
  41. void async_fibre_free(async_fibre *fibre);
  42. # endif
  43. #endif
  44. #endif /* OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H */