gasync_context.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2019 Intel Corporation
  6. #ifndef OPENCV_GAPI_GASYNC_CONTEXT_HPP
  7. #define OPENCV_GAPI_GASYNC_CONTEXT_HPP
  8. #if !defined(GAPI_STANDALONE)
  9. # include <opencv2/core/cvdef.h>
  10. #else // Without OpenCV
  11. # include <opencv2/gapi/own/cvdefs.hpp>
  12. #endif // !defined(GAPI_STANDALONE)
  13. #include <opencv2/gapi/own/exports.hpp>
  14. namespace cv {
  15. namespace gapi{
  16. namespace wip {
  17. /**
  18. * @brief A class to group async requests to cancel them in a single shot.
  19. *
  20. * GAsyncContext is passed as an argument to async() and async_apply() functions
  21. */
  22. class GAPI_EXPORTS GAsyncContext{
  23. std::atomic<bool> cancelation_requested = {false};
  24. public:
  25. /**
  26. * @brief Start cancellation process for an associated request.
  27. *
  28. * User still has to wait for each individual request (either via callback or according std::future object) to make sure it actually canceled.
  29. *
  30. * @return true if it was a first request to cancel the context
  31. */
  32. bool cancel();
  33. /**
  34. * @brief Returns true if cancellation was requested for this context.
  35. *
  36. * @return true if cancellation was requested for this context
  37. */
  38. bool isCanceled() const;
  39. };
  40. class GAPI_EXPORTS GAsyncCanceled : public std::exception {
  41. public:
  42. virtual const char* what() const noexcept CV_OVERRIDE;
  43. };
  44. } // namespace wip
  45. } // namespace gapi
  46. } // namespace cv
  47. #endif //OPENCV_GAPI_GASYNC_CONTEXT_HPP