async_win.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. /* This must be the first #include file */
  10. #include "../async_local.h"
  11. #ifdef ASYNC_WIN
  12. # include <windows.h>
  13. # include "internal/cryptlib.h"
  14. int ASYNC_is_capable(void)
  15. {
  16. return 1;
  17. }
  18. void async_local_cleanup(void)
  19. {
  20. async_ctx *ctx = async_get_ctx();
  21. if (ctx != NULL) {
  22. async_fibre *fibre = &ctx->dispatcher;
  23. if (fibre != NULL && fibre->fibre != NULL && fibre->converted) {
  24. ConvertFiberToThread();
  25. fibre->fibre = NULL;
  26. }
  27. }
  28. }
  29. int async_fibre_init_dispatcher(async_fibre *fibre)
  30. {
  31. # if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600
  32. fibre->fibre = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
  33. # else
  34. fibre->fibre = ConvertThreadToFiber(NULL);
  35. # endif
  36. if (fibre->fibre == NULL) {
  37. fibre->converted = 0;
  38. fibre->fibre = GetCurrentFiber();
  39. if (fibre->fibre == NULL)
  40. return 0;
  41. } else {
  42. fibre->converted = 1;
  43. }
  44. return 1;
  45. }
  46. VOID CALLBACK async_start_func_win(PVOID unused)
  47. {
  48. async_start_func();
  49. }
  50. #endif