You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

1 year ago
  1. #pragma once
  2. /**
  3. * @file IAsyncContext.h
  4. * @brief Async context interface
  5. * @copyright VisionLabs LLC
  6. * @date 30.05.2014
  7. * */
  8. #include <cstdint>
  9. #include "Def.h"
  10. #include "IRefCounted.h"
  11. #include "Types.h"
  12. namespace fsdk {
  13. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  14. DECLARE_SMARTPTR(IAsyncContext);
  15. #endif
  16. /**
  17. * @brief Interface for running tasks asynchronously.
  18. * @details Contains thread pool under hood.
  19. * */
  20. struct IAsyncContext
  21. : IRefCounted {
  22. /**
  23. * @brief Returns size of underlying thread pool.
  24. * @return Count of threads.
  25. * */
  26. virtual int8_t threads() const noexcept = 0;
  27. /**
  28. * @brief Tells validness of internal state
  29. * @return True if valid, false otherwise.
  30. * */
  31. virtual bool valid() const noexcept = 0;
  32. /**
  33. * @brief Clears tasks not yet taken by any thread.
  34. * @return True on success, false otherwise.
  35. * */
  36. virtual bool clearTaskQueue() noexcept = 0;
  37. /**
  38. * @brief Resizes internal thread pool to some new size
  39. * param newThreadCount New size of thread pool. Should not be less than 1
  40. * @return True on success, false otherwise.
  41. * */
  42. virtual bool resize(const int8_t newThreadCount) noexcept = 0;
  43. /**
  44. * @brief Waits for all already running tasks to complete, then stops
  45. * every thread. Do not use threadpool afterwards. Is called on destruction.
  46. * @return True on success, false otherwise.
  47. * */
  48. virtual bool stop() noexcept = 0;
  49. };
  50. }