123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- #ifndef ASIO_SYSTEM_EXECUTOR_HPP
- #define ASIO_SYSTEM_EXECUTOR_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #include "asio/detail/memory.hpp"
- #include "asio/execution.hpp"
- #include "asio/detail/push_options.hpp"
- namespace asio {
- class system_context;
- template <typename Blocking, typename Relationship, typename Allocator>
- class basic_system_executor
- {
- public:
-
- basic_system_executor() noexcept
- : allocator_(Allocator())
- {
- }
- #if !defined(GENERATING_DOCUMENTATION)
- private:
- friend struct asio_require_fn::impl;
- friend struct asio_prefer_fn::impl;
- #endif
-
-
- basic_system_executor<execution::blocking_t::possibly_t,
- Relationship, Allocator>
- require(execution::blocking_t::possibly_t) const
- {
- return basic_system_executor<execution::blocking_t::possibly_t,
- Relationship, Allocator>(allocator_);
- }
-
-
- basic_system_executor<execution::blocking_t::always_t,
- Relationship, Allocator>
- require(execution::blocking_t::always_t) const
- {
- return basic_system_executor<execution::blocking_t::always_t,
- Relationship, Allocator>(allocator_);
- }
-
-
- basic_system_executor<execution::blocking_t::never_t,
- Relationship, Allocator>
- require(execution::blocking_t::never_t) const
- {
- return basic_system_executor<execution::blocking_t::never_t,
- Relationship, Allocator>(allocator_);
- }
-
-
- basic_system_executor<Blocking,
- execution::relationship_t::continuation_t, Allocator>
- require(execution::relationship_t::continuation_t) const
- {
- return basic_system_executor<Blocking,
- execution::relationship_t::continuation_t, Allocator>(allocator_);
- }
-
-
- basic_system_executor<Blocking,
- execution::relationship_t::fork_t, Allocator>
- require(execution::relationship_t::fork_t) const
- {
- return basic_system_executor<Blocking,
- execution::relationship_t::fork_t, Allocator>(allocator_);
- }
-
-
- template <typename OtherAllocator>
- basic_system_executor<Blocking, Relationship, OtherAllocator>
- require(execution::allocator_t<OtherAllocator> a) const
- {
- return basic_system_executor<Blocking,
- Relationship, OtherAllocator>(a.value());
- }
-
-
- basic_system_executor<Blocking, Relationship, std::allocator<void>>
- require(execution::allocator_t<void>) const
- {
- return basic_system_executor<Blocking,
- Relationship, std::allocator<void>>();
- }
- #if !defined(GENERATING_DOCUMENTATION)
- private:
- friend struct asio_query_fn::impl;
- friend struct asio::execution::detail::blocking_t<0>;
- friend struct asio::execution::detail::mapping_t<0>;
- friend struct asio::execution::detail::outstanding_work_t<0>;
- friend struct asio::execution::detail::relationship_t<0>;
- #endif
-
-
- static constexpr execution::mapping_t query(
- execution::mapping_t) noexcept
- {
- return execution::mapping.thread;
- }
-
-
- static system_context& query(execution::context_t) noexcept;
-
-
- static constexpr execution::blocking_t query(
- execution::blocking_t) noexcept
- {
- return Blocking();
- }
-
-
- static constexpr execution::relationship_t query(
- execution::relationship_t) noexcept
- {
- return Relationship();
- }
-
-
- template <typename OtherAllocator>
- constexpr Allocator query(
- execution::allocator_t<OtherAllocator>) const noexcept
- {
- return allocator_;
- }
-
-
- constexpr Allocator query(
- execution::allocator_t<void>) const noexcept
- {
- return allocator_;
- }
-
-
-
- std::size_t query(execution::occupancy_t) const noexcept;
- public:
-
-
- friend bool operator==(const basic_system_executor&,
- const basic_system_executor&) noexcept
- {
- return true;
- }
-
-
- friend bool operator!=(const basic_system_executor&,
- const basic_system_executor&) noexcept
- {
- return false;
- }
-
- template <typename Function>
- void execute(Function&& f) const
- {
- this->do_execute(static_cast<Function&&>(f), Blocking());
- }
- #if !defined(ASIO_NO_TS_EXECUTORS)
- public:
-
- system_context& context() const noexcept;
-
-
- void on_work_started() const noexcept
- {
- }
-
-
- void on_work_finished() const noexcept
- {
- }
-
-
- template <typename Function, typename OtherAllocator>
- void dispatch(Function&& f, const OtherAllocator& a) const;
-
-
- template <typename Function, typename OtherAllocator>
- void post(Function&& f, const OtherAllocator& a) const;
-
-
- template <typename Function, typename OtherAllocator>
- void defer(Function&& f, const OtherAllocator& a) const;
- #endif
- private:
- template <typename, typename, typename> friend class basic_system_executor;
-
- basic_system_executor(const Allocator& a)
- : allocator_(a)
- {
- }
-
- template <typename Function>
- void do_execute(Function&& f,
- execution::blocking_t::possibly_t) const;
-
- template <typename Function>
- void do_execute(Function&& f,
- execution::blocking_t::always_t) const;
-
- template <typename Function>
- void do_execute(Function&& f,
- execution::blocking_t::never_t) const;
-
- Allocator allocator_;
- };
- typedef basic_system_executor<execution::blocking_t::possibly_t,
- execution::relationship_t::fork_t, std::allocator<void>>
- system_executor;
- #if !defined(GENERATING_DOCUMENTATION)
- namespace traits {
- #if !defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
- template <typename Blocking, typename Relationship, typename Allocator>
- struct equality_comparable<
- asio::basic_system_executor<Blocking, Relationship, Allocator>
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- };
- #endif
- #if !defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
- template <typename Blocking, typename Relationship,
- typename Allocator, typename Function>
- struct execute_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- Function
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef void result_type;
- };
- #endif
- #if !defined(ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
- template <typename Blocking, typename Relationship, typename Allocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::blocking_t::possibly_t
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<
- asio::execution::blocking_t::possibly_t,
- Relationship, Allocator> result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::blocking_t::always_t
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<
- asio::execution::blocking_t::always_t,
- Relationship, Allocator> result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::blocking_t::never_t
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<
- asio::execution::blocking_t::never_t,
- Relationship, Allocator> result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::relationship_t::fork_t
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<Blocking,
- asio::execution::relationship_t::fork_t,
- Allocator> result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::relationship_t::continuation_t
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<Blocking,
- asio::execution::relationship_t::continuation_t,
- Allocator> result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::allocator_t<void>
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<Blocking,
- Relationship, std::allocator<void>> result_type;
- };
- template <typename Blocking, typename Relationship,
- typename Allocator, typename OtherAllocator>
- struct require_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::allocator_t<OtherAllocator>
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = false;
- typedef asio::basic_system_executor<Blocking,
- Relationship, OtherAllocator> result_type;
- };
- #endif
- #if !defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
- template <typename Blocking, typename Relationship,
- typename Allocator, typename Property>
- struct query_static_constexpr_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- Property,
- typename asio::enable_if<
- asio::is_convertible<
- Property,
- asio::execution::mapping_t
- >::value
- >::type
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- typedef asio::execution::mapping_t::thread_t result_type;
- static constexpr result_type value() noexcept
- {
- return result_type();
- }
- };
- #endif
- #if !defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
- template <typename Blocking, typename Relationship,
- typename Allocator, typename Property>
- struct query_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- Property,
- typename asio::enable_if<
- asio::is_convertible<
- Property,
- asio::execution::blocking_t
- >::value
- >::type
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- typedef asio::execution::blocking_t result_type;
- };
- template <typename Blocking, typename Relationship,
- typename Allocator, typename Property>
- struct query_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- Property,
- typename asio::enable_if<
- asio::is_convertible<
- Property,
- asio::execution::relationship_t
- >::value
- >::type
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- typedef asio::execution::relationship_t result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct query_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::context_t
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- typedef asio::system_context& result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct query_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::allocator_t<void>
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- typedef Allocator result_type;
- };
- template <typename Blocking, typename Relationship, typename Allocator>
- struct query_member<
- asio::basic_system_executor<Blocking, Relationship, Allocator>,
- asio::execution::allocator_t<Allocator>
- >
- {
- static constexpr bool is_valid = true;
- static constexpr bool is_noexcept = true;
- typedef Allocator result_type;
- };
- #endif
- }
- #endif
- }
- #include "asio/detail/pop_options.hpp"
- #include "asio/impl/system_executor.hpp"
- #endif
|