diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2018-06-30 01:05:44 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2018-06-30 01:05:44 +0300 |
commit | bd06afea35d760e6de395b047a9524c55bf44588 (patch) | |
tree | 2564d484d67c3955900b1e010ad16f9e71baa1e8 | |
parent | 6321c6aa08472a02862f0aa1b66cdc4bbf0a891b (diff) |
Add begin and end to buffer types so Ranges can iterate their bytes.
Add warning about gather write use case.
Restore detail::append_path_info().
-rw-r--r-- | example/use_cases.cpp | 6 | ||||
-rw-r--r-- | include/afio/revision.hpp | 6 | ||||
-rw-r--r-- | include/afio/v2.0/io_handle.hpp | 34 | ||||
-rw-r--r-- | include/afio/v2.0/logging.hpp | 43 | ||||
-rw-r--r-- | include/afio/v2.0/status_code.hpp | 1 | ||||
-rw-r--r-- | programs/benchmark-iostreams/main.cpp | 11 |
6 files changed, 93 insertions, 8 deletions
diff --git a/example/use_cases.cpp b/example/use_cases.cpp index 1df10604..b8f93bee 100644 --- a/example/use_cases.cpp +++ b/example/use_cases.cpp @@ -153,6 +153,12 @@ void read_entire_file2() void scatter_write() { + /* WARNING: This example cannot possibly work because files opened with caching::only_metadata + are required by the operating system to be supplied with buffers aligned to, and be a multiple of, + the device's native block size (often 4Kb). So the gather buffers below would need to be each 4Kb + long, and aligned to 4Kb boundaries. If you would like this example to work as-is, change the + caching::only_metadata to caching::all. + */ //! [scatter_write] namespace afio = AFIO_V2_NAMESPACE; diff --git a/include/afio/revision.hpp b/include/afio/revision.hpp index bac272df..010d0d38 100644 --- a/include/afio/revision.hpp +++ b/include/afio/revision.hpp @@ -1,4 +1,4 @@ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define AFIO_PREVIOUS_COMMIT_REF 4547cc6a15ddb63e0dbe337d166ed9a817c65a92 -#define AFIO_PREVIOUS_COMMIT_DATE "2018-06-24 16:29:15 +00:00" -#define AFIO_PREVIOUS_COMMIT_UNIQUE 4547cc6a +#define AFIO_PREVIOUS_COMMIT_REF 6321c6aa08472a02862f0aa1b66cdc4bbf0a891b +#define AFIO_PREVIOUS_COMMIT_DATE "2018-06-25 08:42:40 +00:00" +#define AFIO_PREVIOUS_COMMIT_UNIQUE 6321c6aa diff --git a/include/afio/v2.0/io_handle.hpp b/include/afio/v2.0/io_handle.hpp index 8f46c622..2ada9efa 100644 --- a/include/afio/v2.0/io_handle.hpp +++ b/include/afio/v2.0/io_handle.hpp @@ -55,6 +55,10 @@ public: { //! Type of the pointer to memory. using pointer = byte *; + //! Type of the iterator to memory. + using iterator = byte *; + //! Type of the iterator to memory. + using const_iterator = const byte *; //! Type of the length of memory. using size_type = size_t; @@ -62,12 +66,29 @@ public: pointer data; //! The number of bytes to fill into this address. Try to make this a 64 byte multiple, or ideally, a whole multiple of `page_size()`. size_type len; + + //! Returns an iterator to the beginning of the buffer + constexpr iterator begin() { return data; } + //! Returns an iterator to the beginning of the buffer + constexpr const_iterator begin() const { return data; } + //! Returns an iterator to the beginning of the buffer + constexpr const_iterator cbegin() const { return data; } + //! Returns an iterator to after the end of the buffer + constexpr iterator end() { return data + len; } + //! Returns an iterator to after the end of the buffer + constexpr const_iterator end() const { return data + len; } + //! Returns an iterator to after the end of the buffer + constexpr const_iterator cend() const { return data + len; } }; //! The gather buffer type used by this handle. Guaranteed to be `TrivialType` and `StandardLayoutType`. struct const_buffer_type { //! Type of the pointer to memory. using pointer = const byte *; + //! Type of the iterator to memory. + using iterator = const byte *; + //! Type of the iterator to memory. + using const_iterator = const byte *; //! Type of the length of memory. using size_type = size_t; @@ -75,6 +96,19 @@ public: pointer data; //! The number of bytes to write from this address. Try to make this a 64 byte multiple, or ideally, a whole multiple of `page_size()`. size_type len; + + //! Returns an iterator to the beginning of the buffer + constexpr iterator begin() { return data; } + //! Returns an iterator to the beginning of the buffer + constexpr const_iterator begin() const { return data; } + //! Returns an iterator to the beginning of the buffer + constexpr const_iterator cbegin() const { return data; } + //! Returns an iterator to after the end of the buffer + constexpr iterator end() { return data + len; } + //! Returns an iterator to after the end of the buffer + constexpr const_iterator end() const { return data + len; } + //! Returns an iterator to after the end of the buffer + constexpr const_iterator cend() const { return data + len; } }; #ifndef NDEBUG static_assert(std::is_trivial<buffer_type>::value, "buffer_type is not a trivial type!"); diff --git a/include/afio/v2.0/logging.hpp b/include/afio/v2.0/logging.hpp index cd638563..76030684 100644 --- a/include/afio/v2.0/logging.hpp +++ b/include/afio/v2.0/logging.hpp @@ -290,4 +290,47 @@ AFIO_V2_NAMESPACE_END #define AFIO_LOG_ALL(inst, message) #endif + +#if !AFIO_EXPERIMENTAL_STATUS_CODE +#ifndef AFIO_DISABLE_PATHS_IN_FAILURE_INFO +AFIO_V2_NAMESPACE_BEGIN + +namespace detail +{ + template <class Src> inline void append_path_info(Src &src, std::string &ret) + { + if(QUICKCPPLIB_NAMESPACE::utils::thread::this_thread_id() == src._thread_id) + { + auto &tls = detail::tls_errored_results(); + const char *path1 = tls.get(src._tls_path_id1), *path2 = tls.get(src._tls_path_id2); + if(path1 != nullptr) + { + ret.append(" [path1 = "); + ret.append(path1); + if(path2 != nullptr) + { + ret.append(", path2 = "); + ret.append(path2); + } + ret.append("]"); + } + } +#if AFIO_LOGGING_LEVEL >= 2 + if(src._log_id != static_cast<uint32_t>(-1)) + { + if(log().valid(src._log_id)) + { + ret.append(" [location = "); + ret.append(location(log()[src._log_id])); + ret.append("]"); + } + } +#endif + } +} + +AFIO_V2_NAMESPACE_END +#endif +#endif + #endif diff --git a/include/afio/v2.0/status_code.hpp b/include/afio/v2.0/status_code.hpp index 3b86db31..14b089f1 100644 --- a/include/afio/v2.0/status_code.hpp +++ b/include/afio/v2.0/status_code.hpp @@ -345,6 +345,7 @@ AFIO_V2_NAMESPACE_BEGIN namespace detail { template <class Dest, class Src> inline void fill_failure_info(Dest &dest, const Src &src); + template <class Src> inline void append_path_info(Src &src, std::string &ret); } struct error_info; diff --git a/programs/benchmark-iostreams/main.cpp b/programs/benchmark-iostreams/main.cpp index 58012955..8c680a14 100644 --- a/programs/benchmark-iostreams/main.cpp +++ b/programs/benchmark-iostreams/main.cpp @@ -22,7 +22,8 @@ Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt) */ -#define MAXBLOCKSIZE (256 * 1024) +#define MINBLOCKSIZE (4096) +#define MAXBLOCKSIZE (4096) #define REGIONSIZE (100 * 1024 * 1024) #include "../../include/afio/afio.hpp" @@ -102,9 +103,9 @@ template <class F> inline void run_test(const char *csv, off_t max_extent, F &&f char buffer[MAXBLOCKSIZE]; std::vector<std::pair<unsigned, unsigned>> offsets(512 * 1024); std::vector<std::vector<unsigned>> results; - for(size_t blocksize = 1; blocksize <= MAXBLOCKSIZE; blocksize <<= 1) + for(size_t blocksize = MINBLOCKSIZE; blocksize <= MAXBLOCKSIZE; blocksize <<= 1) { - size_t scale = blocksize / 16; + size_t scale = (512 * 1024) / (REGIONSIZE / blocksize) / 10; // On average tap each block ten times if(scale < 1) scale = 1; small_prng rand; @@ -127,7 +128,7 @@ template <class F> inline void run_test(const char *csv, off_t max_extent, F &&f } } std::ofstream out(csv); - for(size_t blocksize = 1; blocksize <= MAXBLOCKSIZE; blocksize <<= 1) + for(size_t blocksize = MINBLOCKSIZE; blocksize <= MAXBLOCKSIZE; blocksize <<= 1) { out << "," << blocksize; } @@ -135,7 +136,7 @@ template <class F> inline void run_test(const char *csv, off_t max_extent, F &&f for(size_t n = 0; n < offsets.size(); n++) { auto it = results.cbegin(); - for(size_t blocksize = 1; blocksize <= MAXBLOCKSIZE; blocksize <<= 1, ++it) + for(size_t blocksize = MINBLOCKSIZE; blocksize <= MAXBLOCKSIZE; blocksize <<= 1, ++it) { if(n < it->size()) out << "," << it->at(n); |