Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:39

0001 //
0002 // detail/handler_tracking.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
0012 #define BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 namespace boost {
0021 namespace asio {
0022 
0023 class execution_context;
0024 
0025 } // namespace asio
0026 } // namespace boost
0027 
0028 #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING)
0029 # include BOOST_ASIO_CUSTOM_HANDLER_TRACKING
0030 #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0031 # include <boost/system/error_code.hpp>
0032 # include <boost/asio/detail/cstdint.hpp>
0033 # include <boost/asio/detail/static_mutex.hpp>
0034 # include <boost/asio/detail/tss_ptr.hpp>
0035 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0036 
0037 #include <boost/asio/detail/push_options.hpp>
0038 
0039 namespace boost {
0040 namespace asio {
0041 namespace detail {
0042 
0043 #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING)
0044 
0045 // The user-specified header must define the following macros:
0046 // - BOOST_ASIO_INHERIT_TRACKED_HANDLER
0047 // - BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
0048 // - BOOST_ASIO_HANDLER_TRACKING_INIT
0049 // - BOOST_ASIO_HANDLER_CREATION(args)
0050 // - BOOST_ASIO_HANDLER_COMPLETION(args)
0051 // - BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args)
0052 // - BOOST_ASIO_HANDLER_INVOCATION_END
0053 // - BOOST_ASIO_HANDLER_OPERATION(args)
0054 // - BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args)
0055 // - BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args)
0056 // - BOOST_ASIO_HANDLER_REACTOR_READ_EVENT
0057 // - BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT
0058 // - BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT
0059 // - BOOST_ASIO_HANDLER_REACTOR_EVENTS(args)
0060 // - BOOST_ASIO_HANDLER_REACTOR_OPERATION(args)
0061 
0062 # if !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0063 #  define BOOST_ASIO_ENABLE_HANDLER_TRACKING 1
0064 # endif /// !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0065 
0066 #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0067 
0068 class handler_tracking
0069 {
0070 public:
0071   class completion;
0072 
0073   // Base class for objects containing tracked handlers.
0074   class tracked_handler
0075   {
0076   private:
0077     // Only the handler_tracking class will have access to the id.
0078     friend class handler_tracking;
0079     friend class completion;
0080     uint64_t id_;
0081 
0082   protected:
0083     // Constructor initialises with no id.
0084     tracked_handler() : id_(0) {}
0085 
0086     // Prevent deletion through this type.
0087     ~tracked_handler() {}
0088   };
0089 
0090   // Initialise the tracking system.
0091   BOOST_ASIO_DECL static void init();
0092 
0093   class location
0094   {
0095   public:
0096     // Constructor adds a location to the stack.
0097     BOOST_ASIO_DECL explicit location(const char* file,
0098         int line, const char* func);
0099 
0100     // Destructor removes a location from the stack.
0101     BOOST_ASIO_DECL ~location();
0102 
0103   private:
0104     // Disallow copying and assignment.
0105     location(const location&) = delete;
0106     location& operator=(const location&) = delete;
0107 
0108     friend class handler_tracking;
0109     const char* file_;
0110     int line_;
0111     const char* func_;
0112     location* next_;
0113   };
0114 
0115   // Record the creation of a tracked handler.
0116   BOOST_ASIO_DECL static void creation(
0117       execution_context& context, tracked_handler& h,
0118       const char* object_type, void* object,
0119       uintmax_t native_handle, const char* op_name);
0120 
0121   class completion
0122   {
0123   public:
0124     // Constructor records that handler is to be invoked with no arguments.
0125     BOOST_ASIO_DECL explicit completion(const tracked_handler& h);
0126 
0127     // Destructor records only when an exception is thrown from the handler, or
0128     // if the memory is being freed without the handler having been invoked.
0129     BOOST_ASIO_DECL ~completion();
0130 
0131     // Records that handler is to be invoked with no arguments.
0132     BOOST_ASIO_DECL void invocation_begin();
0133 
0134     // Records that handler is to be invoked with one arguments.
0135     BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec);
0136 
0137     // Constructor records that handler is to be invoked with two arguments.
0138     BOOST_ASIO_DECL void invocation_begin(
0139         const boost::system::error_code& ec, std::size_t bytes_transferred);
0140 
0141     // Constructor records that handler is to be invoked with two arguments.
0142     BOOST_ASIO_DECL void invocation_begin(
0143         const boost::system::error_code& ec, int signal_number);
0144 
0145     // Constructor records that handler is to be invoked with two arguments.
0146     BOOST_ASIO_DECL void invocation_begin(
0147         const boost::system::error_code& ec, const char* arg);
0148 
0149     // Record that handler invocation has ended.
0150     BOOST_ASIO_DECL void invocation_end();
0151 
0152   private:
0153     friend class handler_tracking;
0154     uint64_t id_;
0155     bool invoked_;
0156     completion* next_;
0157   };
0158 
0159   // Record an operation that is not directly associated with a handler.
0160   BOOST_ASIO_DECL static void operation(execution_context& context,
0161       const char* object_type, void* object,
0162       uintmax_t native_handle, const char* op_name);
0163 
0164   // Record that a descriptor has been registered with the reactor.
0165   BOOST_ASIO_DECL static void reactor_registration(execution_context& context,
0166       uintmax_t native_handle, uintmax_t registration);
0167 
0168   // Record that a descriptor has been deregistered from the reactor.
0169   BOOST_ASIO_DECL static void reactor_deregistration(execution_context& context,
0170       uintmax_t native_handle, uintmax_t registration);
0171 
0172   // Record a reactor-based operation that is associated with a handler.
0173   BOOST_ASIO_DECL static void reactor_events(execution_context& context,
0174       uintmax_t registration, unsigned events);
0175 
0176   // Record a reactor-based operation that is associated with a handler.
0177   BOOST_ASIO_DECL static void reactor_operation(
0178       const tracked_handler& h, const char* op_name,
0179       const boost::system::error_code& ec);
0180 
0181   // Record a reactor-based operation that is associated with a handler.
0182   BOOST_ASIO_DECL static void reactor_operation(
0183       const tracked_handler& h, const char* op_name,
0184       const boost::system::error_code& ec, std::size_t bytes_transferred);
0185 
0186   // Write a line of output.
0187   BOOST_ASIO_DECL static void write_line(const char* format, ...);
0188 
0189 private:
0190   struct tracking_state;
0191   BOOST_ASIO_DECL static tracking_state* get_state();
0192 };
0193 
0194 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \
0195   : public boost::asio::detail::handler_tracking::tracked_handler
0196 
0197 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \
0198   , public boost::asio::detail::handler_tracking::tracked_handler
0199 
0200 # define BOOST_ASIO_HANDLER_TRACKING_INIT \
0201   boost::asio::detail::handler_tracking::init()
0202 
0203 # define BOOST_ASIO_HANDLER_LOCATION(args) \
0204   boost::asio::detail::handler_tracking::location tracked_location args
0205 
0206 # define BOOST_ASIO_HANDLER_CREATION(args) \
0207   boost::asio::detail::handler_tracking::creation args
0208 
0209 # define BOOST_ASIO_HANDLER_COMPLETION(args) \
0210   boost::asio::detail::handler_tracking::completion tracked_completion args
0211 
0212 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \
0213   tracked_completion.invocation_begin args
0214 
0215 # define BOOST_ASIO_HANDLER_INVOCATION_END \
0216   tracked_completion.invocation_end()
0217 
0218 # define BOOST_ASIO_HANDLER_OPERATION(args) \
0219   boost::asio::detail::handler_tracking::operation args
0220 
0221 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) \
0222   boost::asio::detail::handler_tracking::reactor_registration args
0223 
0224 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) \
0225   boost::asio::detail::handler_tracking::reactor_deregistration args
0226 
0227 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 1
0228 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 2
0229 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 4
0230 
0231 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) \
0232   boost::asio::detail::handler_tracking::reactor_events args
0233 
0234 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) \
0235   boost::asio::detail::handler_tracking::reactor_operation args
0236 
0237 #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0238 
0239 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER
0240 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
0241 # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0
0242 # define BOOST_ASIO_HANDLER_LOCATION(loc) (void)0
0243 # define BOOST_ASIO_HANDLER_CREATION(args) (void)0
0244 # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0
0245 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
0246 # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0
0247 # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0
0248 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) (void)0
0249 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) (void)0
0250 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 0
0251 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 0
0252 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 0
0253 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) (void)0
0254 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) (void)0
0255 
0256 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
0257 
0258 } // namespace detail
0259 } // namespace asio
0260 } // namespace boost
0261 
0262 #include <boost/asio/detail/pop_options.hpp>
0263 
0264 #if defined(BOOST_ASIO_HEADER_ONLY)
0265 # include <boost/asio/detail/impl/handler_tracking.ipp>
0266 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0267 
0268 #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP