api.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2019-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. #include <openssl/configuration.h>
  10. #include <openssl/thread.h>
  11. #include <internal/thread.h>
  12. uint32_t OSSL_get_thread_support_flags(void)
  13. {
  14. int support = 0;
  15. #if !defined(OPENSSL_NO_THREAD_POOL)
  16. support |= OSSL_THREAD_SUPPORT_FLAG_THREAD_POOL;
  17. #endif
  18. #if !defined(OPENSSL_NO_DEFAULT_THREAD_POOL)
  19. support |= OSSL_THREAD_SUPPORT_FLAG_DEFAULT_SPAWN;
  20. #endif
  21. return support;
  22. }
  23. #if defined(OPENSSL_NO_THREAD_POOL) || defined(OPENSSL_NO_DEFAULT_THREAD_POOL)
  24. int OSSL_set_max_threads(OSSL_LIB_CTX *ctx, uint64_t max_threads)
  25. {
  26. return 0;
  27. }
  28. uint64_t OSSL_get_max_threads(OSSL_LIB_CTX *ctx)
  29. {
  30. return 0;
  31. }
  32. #else
  33. uint64_t OSSL_get_max_threads(OSSL_LIB_CTX *ctx)
  34. {
  35. uint64_t ret = 0;
  36. OSSL_LIB_CTX_THREADS *tdata = OSSL_LIB_CTX_GET_THREADS(ctx);
  37. if (tdata == NULL)
  38. goto fail;
  39. ossl_crypto_mutex_lock(tdata->lock);
  40. ret = tdata->max_threads;
  41. ossl_crypto_mutex_unlock(tdata->lock);
  42. fail:
  43. return ret;
  44. }
  45. int OSSL_set_max_threads(OSSL_LIB_CTX *ctx, uint64_t max_threads)
  46. {
  47. OSSL_LIB_CTX_THREADS *tdata;
  48. tdata = OSSL_LIB_CTX_GET_THREADS(ctx);
  49. if (tdata == NULL)
  50. return 0;
  51. ossl_crypto_mutex_lock(tdata->lock);
  52. tdata->max_threads = max_threads;
  53. ossl_crypto_mutex_unlock(tdata->lock);
  54. return 1;
  55. }
  56. #endif