Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/llfio.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2018-07-12 12:00:14 +0300
committerNiall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com>2018-07-12 12:00:14 +0300
commitf743a7358ec186a3982d1a61dad2120ba9305180 (patch)
tree4bd8ca4422d7659e7224ae8343ea5d3b58b5a295 /include/llfio/v2.0
parent11d4f9dbc12a61a796c8c00f260924ee17aa3cc1 (diff)
Split algorithm::mapped_span<T> into map_view<T> and mapped<T>, as per the TS wording.
Diffstat (limited to 'include/llfio/v2.0')
-rw-r--r--include/llfio/v2.0/llfio.hpp3
-rw-r--r--include/llfio/v2.0/map_view.hpp87
-rw-r--r--include/llfio/v2.0/mapped.hpp108
-rw-r--r--include/llfio/v2.0/mapped_view.hpp124
4 files changed, 196 insertions, 126 deletions
diff --git a/include/llfio/v2.0/llfio.hpp b/include/llfio/v2.0/llfio.hpp
index b5399af6..4fee0f54 100644
--- a/include/llfio/v2.0/llfio.hpp
+++ b/include/llfio/v2.0/llfio.hpp
@@ -68,14 +68,13 @@ import LLFIO_MODULE_NAME;
#include "file_handle.hpp"
#endif
#include "directory_handle.hpp"
-#include "map_handle.hpp"
+#include "map_view.hpp"
#include "statfs.hpp"
#ifndef LLFIO_LEAN_AND_MEAN
#include "storage_profile.hpp"
#endif
#include "algorithm/cached_parent_handle_adapter.hpp"
-#include "algorithm/mapped_span.hpp"
#include "algorithm/shared_fs_mutex/atomic_append.hpp"
#include "algorithm/shared_fs_mutex/byte_ranges.hpp"
#include "algorithm/shared_fs_mutex/lock_files.hpp"
diff --git a/include/llfio/v2.0/map_view.hpp b/include/llfio/v2.0/map_view.hpp
new file mode 100644
index 00000000..b4811891
--- /dev/null
+++ b/include/llfio/v2.0/map_view.hpp
@@ -0,0 +1,87 @@
+/* A typed view of a mapped section
+(C) 2017-2018 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
+File Created: Aug 2017
+
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License in the accompanying file
+Licence.txt or at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file Licence.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+#ifndef LLFIO_MAP_VIEW_HPP
+#define LLFIO_MAP_VIEW_HPP
+
+#include "mapped.hpp"
+
+//! \file map_view.hpp Provides typed view of mapped section.
+
+LLFIO_V2_NAMESPACE_BEGIN
+
+/*! \brief Provides a lightweight typed view of a `map_handle`, a `mapped_file_handle`
+or a `mapped<T>` suitable for feeding to STL algorithms or the Ranges TS.
+
+This is the correct type to use when passing non-owning views of mapped data
+around between functions. Where you wish the view to be (possibly) owning,
+you may find the non-lightweight `mapped<T>` of more use.
+*/
+template <class T> class map_view : public span<T>
+{
+public:
+ //! The extent type.
+ using extent_type = typename section_handle::extent_type;
+ //! The size type.
+ using size_type = typename section_handle::size_type;
+
+public:
+ //! Default constructor
+ constexpr map_view() {} // NOLINT
+
+ /*! Implicitly construct a mapped view of the given mapped data.
+
+ \param map The mapped data to take a view upon.
+ \param length The number of items to map, use -1 to mean the length of the input view.
+ \param byteoffset The item offset into the mapped file handle.
+ */
+ map_view(mapped<T> &map, size_type length = (size_type) -1, size_type offset = 0) // NOLINT
+ : span<T>(map.begin() + offset, (length == (size_type) -1) ? (map.size() - offset) : length) // NOLINT
+ {
+ }
+ /*! Construct a mapped view of the given map handle.
+
+ \param mh The map handle to use.
+ \param length The number of items to map, use -1 to mean the length of the map handle divided by `sizeof(T)`.
+ \param byteoffset The byte offset into the map handle, this does not need to be a multiple of the page size.
+ */
+ explicit map_view(map_handle &mh, size_type length = (size_type) -1, extent_type byteoffset = 0) // NOLINT
+ : span<T>(reinterpret_cast<T *>(mh.address() + byteoffset), (length == (size_type) -1) ? ((mh.length() - byteoffset) / sizeof(T)) : length) // NOLINT
+ {
+ }
+ /*! Construct a mapped view of the given mapped file handle.
+
+ \param mfh The mapped file handle to take a view upon.
+ \param length The number of items to map, use -1 to mean the length of the section handle divided by `sizeof(T)`.
+ \param byteoffset The byte offset into the mapped file handle, this does not need to be a multiple of the page size.
+ */
+ explicit map_view(mapped_file_handle &mfh, size_type length = (size_type) -1, extent_type byteoffset = 0) // NOLINT
+ : span<T>(reinterpret_cast<T *>(mfh.address() + byteoffset), (length == (size_type) -1) ? ((mfh.maximum_extent().value() - byteoffset) / sizeof(T)) : length) // NOLINT
+ {
+ }
+};
+
+LLFIO_V2_NAMESPACE_END
+
+#endif
diff --git a/include/llfio/v2.0/mapped.hpp b/include/llfio/v2.0/mapped.hpp
new file mode 100644
index 00000000..6a023f23
--- /dev/null
+++ b/include/llfio/v2.0/mapped.hpp
@@ -0,0 +1,108 @@
+/* A typed view of a mapped section
+(C) 2017-2018 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
+File Created: Aug 2017
+
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License in the accompanying file
+Licence.txt or at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+Distributed under the Boost Software License, Version 1.0.
+ (See accompanying file Licence.txt or copy at
+ http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+#ifndef LLFIO_MAPPED_HPP
+#define LLFIO_MAPPED_HPP
+
+#include "mapped_file_handle.hpp"
+#include "utils.hpp"
+
+//! \file mapped.hpp Provides typed view of mapped section.
+
+LLFIO_V2_NAMESPACE_BEGIN
+
+/*! \brief Provides a map owning typed view of a `section_handle` suitable for feeding to STL algorithms
+or the Ranges TS by wrapping a `map_handle` into a `span<T>`.
+
+This opens a new `map_handle` onto the requested offset and length of the supplied source, and thus
+is an *owning* view of mapped memory. It can be moved, but not copied. If you wish to pass a non-owning
+view, see `map_view<T>`.
+
+Optionally can issue a blocking write barrier on destruction of the mapped view by setting the flag
+`section_handle::flag::barrier_on_close`, thus forcing any changes to data referred to by the view
+to storage before the destructor returns.
+*/
+template <class T> class mapped : public span<T>
+{
+public:
+ //! The extent type.
+ using extent_type = typename section_handle::extent_type;
+ //! The size type.
+ using size_type = typename section_handle::size_type;
+
+private:
+ map_handle _mapping;
+ mapped(extent_type page_offset, extent_type offset, section_handle &sh, size_type bytes, section_handle::flag _flag) // NOLINT
+ : _mapping(map_handle::map(sh, (bytes == 0) ? 0 : bytes + (offset - page_offset), page_offset, _flag).value())
+ {
+ offset -= page_offset;
+ byte *addr = _mapping.address() + offset;
+ size_t len = sh.length().value() - offset; // use section length, not mapped length as mapped length is rounded up to page size
+ if(bytes != 0 && bytes < len)
+ {
+ len = bytes;
+ }
+ static_cast<span<T> &>(*this) = span<T>(reinterpret_cast<T *>(addr), len / sizeof(T)); // NOLINT
+ }
+
+public:
+ //! Default constructor
+ constexpr mapped() {} // NOLINT
+
+ //! Returns a reference to the internal map handle
+ const map_handle &map_handle() const noexcept { return _mapping; }
+
+ /*! Create a view of new memory.
+
+ \param length The number of items to map.
+ \param _flag The flags to pass to `map_handle::map()`.
+ */
+ explicit mapped(size_type length, section_handle::flag _flag = section_handle::flag::readwrite)
+ : _mapping(map_handle::map(length * sizeof(T), _flag).value())
+ {
+ byte *addr = _mapping.address();
+ static_cast<span<T> &>(*this) = span<T>(reinterpret_cast<T *>(addr), length); // NOLINT
+ }
+ /*! Construct a mapped view of the given section handle.
+
+ \param sh The section handle to use as the data source for creating the map.
+ \param length The number of items to map, use -1 to mean the length of the section handle divided by `sizeof(T)`.
+ \param byteoffset The byte offset into the section handle, this does not need to be a multiple of the page size.
+ \param _flag The flags to pass to `map_handle::map()`.
+ */
+ explicit mapped(section_handle &sh, size_type length = (size_type) -1, extent_type byteoffset = 0, section_handle::flag _flag = section_handle::flag::readwrite) // NOLINT
+ : mapped((length == 0) ? mapped() : mapped(
+#ifdef _WIN32
+ byteoffset & ~65535,
+#else
+ utils::round_down_to_page_size(byteoffset),
+#endif
+ byteoffset, sh, (length == (size_type) -1) ? 0 : length * sizeof(T), _flag)) // NOLINT
+ {
+ }
+};
+
+LLFIO_V2_NAMESPACE_END
+
+#endif
diff --git a/include/llfio/v2.0/mapped_view.hpp b/include/llfio/v2.0/mapped_view.hpp
deleted file mode 100644
index 1bb0c84b..00000000
--- a/include/llfio/v2.0/mapped_view.hpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/* A typed view of a mapped section
-(C) 2017 Niall Douglas <http://www.nedproductions.biz/> (12 commits)
-File Created: Aug 2017
-
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License in the accompanying file
-Licence.txt or at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-
-Distributed under the Boost Software License, Version 1.0.
- (See accompanying file Licence.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-*/
-
-#ifndef LLFIO_MAPPED_VIEW_HPP
-#define LLFIO_MAPPED_VIEW_HPP
-
-#include "../mapped_file_handle.hpp"
-#include "../utils.hpp"
-
-//! \file mapped_span.hpp Provides typed view of mapped section.
-
-LLFIO_V2_NAMESPACE_BEGIN
-
-namespace algorithm
-{
- /*! \brief Provides a typed mapped view of a `section_handle` suitable for feeding to STL algorithms
- or the Ranges TS by wrapping a `map_handle` into a `span<T>`.
-
- Optionally can issue a blocking write barrier on destruction of the mapped view by setting the flag
- `section_handle::flag::barrier_on_close`, thus forcing any changes to data referred to by the view
- to storage before the destructor returns.
- */
- template <class T> class mapped_span : public span<T>
- {
- public:
- //! The extent type.
- using extent_type = typename section_handle::extent_type;
- //! The size type.
- using size_type = typename section_handle::size_type;
-
- private:
- map_handle _mapping;
- mapped_span(extent_type page_offset, extent_type offset, section_handle &sh, size_type bytes, section_handle::flag _flag) // NOLINT
- : _mapping(map_handle::map(sh, (bytes == 0) ? 0 : bytes + (offset - page_offset), page_offset, _flag).value())
- {
- offset -= page_offset;
- byte *addr = _mapping.address() + offset;
- size_t len = sh.length().value() - offset; // use section length, not mapped length as mapped length is rounded up to page size
- if(bytes != 0 && bytes < len)
- {
- len = bytes;
- }
- static_cast<span<T> &>(*this) = span<T>(reinterpret_cast<T *>(addr), len / sizeof(T)); // NOLINT
- }
-
- public:
- //! Default constructor
- constexpr mapped_span() {} // NOLINT
-
- /*! Create a view of new memory.
-
- \param length The number of items to map.
- \param _flag The flags to pass to `map_handle::map()`.
- */
- explicit mapped_span(size_type length, section_handle::flag _flag = section_handle::flag::readwrite)
- : _mapping(map_handle::map(length * sizeof(T), _flag).value())
- {
- byte *addr = _mapping.address();
- static_cast<span<T> &>(*this) = span<T>(reinterpret_cast<T *>(addr), length); // NOLINT
- }
- /*! Construct a mapped view of the given section handle.
-
- \param sh The section handle to use as the data source for creating the map.
- \param length The number of items to map, use -1 to mean the length of the section handle divided by `sizeof(T)`.
- \param byteoffset The byte offset into the section handle, this does not need to be a multiple of the page size.
- \param _flag The flags to pass to `map_handle::map()`.
- */
- explicit mapped_span(section_handle &sh, size_type length = (size_type) -1, extent_type byteoffset = 0, section_handle::flag _flag = section_handle::flag::readwrite) // NOLINT
- : mapped_span((length == 0) ? mapped_span() : mapped_span(
-#ifdef _WIN32
- byteoffset & ~65535,
-#else
- utils::round_down_to_page_size(byteoffset),
-#endif
- byteoffset, sh, (length == (size_type) -1) ? 0 : length * sizeof(T), _flag)) // NOLINT
- {
- }
- /*! Construct a mapped view of the given map handle.
-
- \param mh The map handle to use.
- \param length The number of items to map, use -1 to mean the length of the map handle divided by `sizeof(T)`.
- \param byteoffset The byte offset into the map handle, this does not need to be a multiple of the page size.
- */
- explicit mapped_span(map_handle &mh, size_type length = (size_type) -1, extent_type byteoffset = 0) // NOLINT
- : span<T>(reinterpret_cast<T *>(mh.address() + byteoffset), (length == (size_type) -1) ? ((mh.length() - byteoffset) / sizeof(T)) : length) // NOLINT
- {
- }
- /*! Construct a mapped view of the given mapped file handle.
-
- \param mfh The mapped file handle to use as the data source for creating the map.
- \param length The number of items to map, use -1 to mean the length of the section handle divided by `sizeof(T)`.
- \param byteoffset The byte offset into the mapped file handle, this does not need to be a multiple of the page size.
- */
- explicit mapped_span(mapped_file_handle &mfh, size_type length = (size_type) -1, extent_type byteoffset = 0) // NOLINT
- : span<T>(reinterpret_cast<T *>(mfh.address() + byteoffset), (length == (size_type) -1) ? ((mfh.maximum_extent().value() - byteoffset) / sizeof(T)) : length) // NOLINT
- {
- }
- };
-} // namespace algorithm
-
-LLFIO_V2_NAMESPACE_END
-
-#endif