diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2019-10-19 21:01:38 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2019-10-19 21:01:38 +0300 |
commit | 1ebceb7e076b3d6d0f51f185f94d65493e26f192 (patch) | |
tree | fdc783b33e23f66fd0732828b999588fd25eed05 | |
parent | 12d3c21b9e95106e3f8fe859add7ac6001eaf3b6 (diff) |
Fix failure to build under C++ 20 with Concepts enabled.
-rw-r--r-- | include/llfio/v2.0/async_file_handle.hpp | 8 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/posix/map_handle.ipp | 71 | ||||
-rw-r--r-- | include/llfio/v2.0/map_handle.hpp | 14 |
3 files changed, 50 insertions, 43 deletions
diff --git a/include/llfio/v2.0/async_file_handle.hpp b/include/llfio/v2.0/async_file_handle.hpp index 07f3a075..351180b4 100644 --- a/include/llfio/v2.0/async_file_handle.hpp +++ b/include/llfio/v2.0/async_file_handle.hpp @@ -372,7 +372,7 @@ public: \return Either an io_state_ptr to the i/o in progress, or an error code. \param reqs A scatter-gather and offset request for what range to barrier. May be ignored on some platforms which always write barrier the entire file. Supplying a default initialised reqs write barriers the entire file. - \param completion A callable to call upon i/o completion. Spec is `void(async_file_handle *, io_result<const_buffers_type> &)`. + \param completion A callable to call upon i/o completion. Spec is `void(async_file_handle *, io_result<const_buffers_type> &&)`. Note that buffers returned may not be buffers input, see documentation for `barrier()`. \param kind Which kind of write reordering barrier to perform. \param mem Optional span of memory to use to avoid using `calloc()`. Note span MUST be all bits zero on entry. @@ -382,7 +382,7 @@ public: */ LLFIO_MAKE_FREE_FUNCTION template <class CompletionRoutine> // - LLFIO_REQUIRES(detail::is_invocable_r<void, CompletionRoutine, async_file_handle *, io_result<const_buffers_type> &>::value) // + LLFIO_REQUIRES(detail::is_invocable_r<void, CompletionRoutine, async_file_handle *, io_result<const_buffers_type> &&>::value) // result<io_state_ptr> async_barrier(io_request<const_buffers_type> reqs, CompletionRoutine &&completion, barrier_kind kind = barrier_kind::nowait_data_only, span<char> mem = {}) noexcept { LLFIO_LOG_FUNCTION_CALL(this); @@ -439,7 +439,7 @@ public: */ LLFIO_MAKE_FREE_FUNCTION template <class CompletionRoutine> // - LLFIO_REQUIRES(detail::is_invocable_r<void, CompletionRoutine, async_file_handle *, io_result<buffers_type> &>::value) // + LLFIO_REQUIRES(detail::is_invocable_r<void, CompletionRoutine, async_file_handle *, io_result<buffers_type> &&>::value) // result<io_state_ptr> async_read(io_request<buffers_type> reqs, CompletionRoutine &&completion, span<char> mem = {}) noexcept { LLFIO_LOG_FUNCTION_CALL(this); @@ -483,7 +483,7 @@ public: */ LLFIO_MAKE_FREE_FUNCTION template <class CompletionRoutine> // - LLFIO_REQUIRES(detail::is_invocable_r<void, CompletionRoutine, async_file_handle *, io_result<const_buffers_type> &>::value) // + LLFIO_REQUIRES(detail::is_invocable_r<void, CompletionRoutine, async_file_handle *, io_result<const_buffers_type> &&>::value) // result<io_state_ptr> async_write(io_request<const_buffers_type> reqs, CompletionRoutine &&completion, span<char> mem = {}) noexcept { LLFIO_LOG_FUNCTION_CALL(this); diff --git a/include/llfio/v2.0/detail/impl/posix/map_handle.ipp b/include/llfio/v2.0/detail/impl/posix/map_handle.ipp index bf843c64..b094b0fa 100644 --- a/include/llfio/v2.0/detail/impl/posix/map_handle.ipp +++ b/include/llfio/v2.0/detail/impl/posix/map_handle.ipp @@ -481,12 +481,12 @@ result<map_handle::buffer_type> map_handle::decommit(buffer_type region) noexcep return errc::invalid_argument; } region = utils::round_to_page_size(region, _pagesize); - // Tell the kernel to kick these pages into storage - if(-1 == ::madvise(region.data(), region.size(), MADV_DONTNEED)) + // If decommitting a mapped file, tell the kernel to kick these pages back to storage + if(_section != nullptr && -1 == ::madvise(region.data(), region.size(), MADV_DONTNEED)) { return posix_error(); } - // Set permissions on the pages to no access + // Remap these pages with ones having no access extent_type offset = _offset + (region.data() - _addr); size_type bytes = region.size(); OUTCOME_TRYV(do_mmap(_v, region.data(), MAP_FIXED, _section, _pagesize, bytes, offset, section_handle::flag::none)); @@ -580,38 +580,39 @@ map_handle::io_result<map_handle::const_buffers_type> map_handle::write(io_reque LLFIO_LOG_FUNCTION_CALL(this); byte *addr = _addr + reqs.offset; size_type togo = reqs.offset < _length ? static_cast<size_type>(_length - reqs.offset) : 0; - if(QUICKCPPLIB_NAMESPACE::signal_guard::signal_guard(QUICKCPPLIB_NAMESPACE::signal_guard::signalc_set::undefined_memory_access, - [&] { - for(size_t i = 0; i < reqs.buffers.size(); i++) - { - const_buffer_type &req = reqs.buffers[i]; - if(req.size() > togo) - { - memcpy(addr, req.data(), togo); - req = {addr, togo}; - reqs.buffers = {reqs.buffers.data(), i + 1}; - return false; - } - else - { - memcpy(addr, req.data(), req.size()); - req = {addr, req.size()}; - addr += req.size(); - togo -= req.size(); - } - } - return false; - }, - [&](const QUICKCPPLIB_NAMESPACE::signal_guard::raised_signal_info *info) { - auto *causingaddr = (byte *) info->addr; - if(causingaddr < _addr || causingaddr >= (_addr + _reservation)) - { - // Not caused by this map - thrd_raise_signal(info->signo, info->raw_info, info->raw_context); - abort(); - } - return true; - })) + if(QUICKCPPLIB_NAMESPACE::signal_guard::signal_guard( + QUICKCPPLIB_NAMESPACE::signal_guard::signalc_set::undefined_memory_access, + [&] { + for(size_t i = 0; i < reqs.buffers.size(); i++) + { + const_buffer_type &req = reqs.buffers[i]; + if(req.size() > togo) + { + memcpy(addr, req.data(), togo); + req = {addr, togo}; + reqs.buffers = {reqs.buffers.data(), i + 1}; + return false; + } + else + { + memcpy(addr, req.data(), req.size()); + req = {addr, req.size()}; + addr += req.size(); + togo -= req.size(); + } + } + return false; + }, + [&](const QUICKCPPLIB_NAMESPACE::signal_guard::raised_signal_info *info) { + auto *causingaddr = (byte *) info->addr; + if(causingaddr < _addr || causingaddr >= (_addr + _reservation)) + { + // Not caused by this map + thrd_raise_signal(info->signo, info->raw_info, info->raw_context); + abort(); + } + return true; + })) { return errc::no_space_on_device; } diff --git a/include/llfio/v2.0/map_handle.hpp b/include/llfio/v2.0/map_handle.hpp index 906764af..b42dd08b 100644 --- a/include/llfio/v2.0/map_handle.hpp +++ b/include/llfio/v2.0/map_handle.hpp @@ -503,6 +503,11 @@ public: LLFIO_MAKE_FREE_FUNCTION size_type length() const noexcept { return _length; } + //! The memory map as a span of bytes. + span<byte> as_span() noexcept { return {_addr, _length}; } + //! \overload + span<const byte> as_span() const noexcept { return {_addr, _length}; } + //! The page size used by the map, in bytes. size_type page_size() const noexcept { return _pagesize; } @@ -653,15 +658,16 @@ namespace in_place_attach_detach template <> struct disable_attached_for<LLFIO_V2_NAMESPACE::map_handle> : public std::true_type { }; - } -} + } // namespace traits +} // namespace in_place_attach_detach QUICKCPPLIB_NAMESPACE_END LLFIO_V2_NAMESPACE_EXPORT_BEGIN //! \brief Declare `map_handle` as a suitable source for P1631 `attached<T>`. -template <class T> constexpr inline span<T> in_place_attach(map_handle& mh) noexcept { - return span<T>{reinterpret_cast<T *>(mh.address()), mh.length()/sizeof(T)}; +template <class T> constexpr inline span<T> in_place_attach(map_handle &mh) noexcept +{ + return span<T>{reinterpret_cast<T *>(mh.address()), mh.length() / sizeof(T)}; } // BEGIN make_free_functions.py |