scheduler_operation.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // detail/scheduler_operation.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP
  11. #define BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/system/error_code.hpp>
  16. #include <boost/asio/detail/handler_tracking.hpp>
  17. #include <boost/asio/detail/op_queue.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. class scheduler;
  23. // Base class for all operations. A function pointer is used instead of virtual
  24. // functions to avoid the associated overhead.
  25. class scheduler_operation BOOST_ASIO_INHERIT_TRACKED_HANDLER
  26. {
  27. public:
  28. typedef scheduler_operation operation_type;
  29. void complete(void* owner, const boost::system::error_code& ec,
  30. std::size_t bytes_transferred)
  31. {
  32. func_(owner, this, ec, bytes_transferred);
  33. }
  34. void destroy()
  35. {
  36. func_(0, this, boost::system::error_code(), 0);
  37. }
  38. protected:
  39. typedef void (*func_type)(void*,
  40. scheduler_operation*,
  41. const boost::system::error_code&, std::size_t);
  42. scheduler_operation(func_type func)
  43. : next_(0),
  44. func_(func),
  45. task_result_(0)
  46. {
  47. }
  48. // Prevents deletion through this type.
  49. ~scheduler_operation()
  50. {
  51. }
  52. private:
  53. friend class op_queue_access;
  54. scheduler_operation* next_;
  55. func_type func_;
  56. protected:
  57. friend class scheduler;
  58. unsigned int task_result_; // Passed into bytes transferred.
  59. };
  60. } // namespace detail
  61. } // namespace asio
  62. } // namespace boost
  63. #include <boost/asio/detail/pop_options.hpp>
  64. #endif // BOOST_ASIO_DETAIL_SCHEDULER_OPERATION_HPP