diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2019-11-18 14:14:56 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2019-11-18 14:14:56 +0300 |
commit | e66a774d599804a31ebbb701874ca2dde5e36e10 (patch) | |
tree | 6630d2fbbf2b9634190deea9c3f9a51e401d4023 /include/llfio/v2.0/algorithm/handle_adapter/combining.hpp | |
parent | b6c21fdf2dcf0f7c72e117cfc8396fdbb9d5973c (diff) |
As per WG21 guidance, moved byte range locking API out of io_handle, and into an extension to file_handle. This makes space to make a future lockable_io_handle to model SharedMutex, which locks an inode like a std::shared_mutex. Note that the new .lock_range() API no longer does special semantics if you pass in zero length to lock the whole file.develop
Diffstat (limited to 'include/llfio/v2.0/algorithm/handle_adapter/combining.hpp')
-rw-r--r-- | include/llfio/v2.0/algorithm/handle_adapter/combining.hpp | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp b/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp index 5c794503..bf2661eb 100644 --- a/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp +++ b/include/llfio/v2.0/algorithm/handle_adapter/combining.hpp @@ -305,37 +305,63 @@ namespace algorithm } return std::move(reqs.buffers); } + }; + template <template <class, class> class Op, class Target, class Source> class combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, true> : public combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false> + { + using _base = combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false>; + + protected: + static constexpr bool _have_source = _base::_have_source; + + public: + using path_type = io_handle::path_type; + using extent_type = io_handle::extent_type; + using size_type = io_handle::size_type; + using mode = io_handle::mode; + using creation = io_handle::creation; + using caching = io_handle::caching; + using flag = io_handle::flag; + using buffer_type = io_handle::buffer_type; + using const_buffer_type = io_handle::const_buffer_type; + using buffers_type = io_handle::buffers_type; + using const_buffers_type = io_handle::const_buffers_type; + template <class T> using io_request = io_handle::io_request<T>; + template <class T> using io_result = io_handle::io_result<T>; + + combining_handle_adapter_base() = default; + using _base::_base; - using extent_guard = typename Base::extent_guard; + using lock_kind = typename _base::lock_kind; + using extent_guard = typename _base::extent_guard; private: struct _extent_guard : public extent_guard { friend class combining_handle_adapter; _extent_guard() = default; - constexpr _extent_guard(io_handle *h, extent_type offset, extent_type length, bool exclusive) - : extent_guard(h, offset, length, exclusive) + constexpr _extent_guard(file_handle *h, extent_type offset, extent_type length, lock_kind kind) + : extent_guard(h, offset, length, kind) { } }; public: //! \brief Lock the given extent in one or both of the attached handles. Any second handle is always locked for shared. - LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_guard> lock(extent_type offset, extent_type bytes, bool exclusive = true, deadline d = deadline()) noexcept override + LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_guard> lock_range(extent_type offset, extent_type bytes, lock_kind kind, deadline d = deadline()) noexcept override { optional<result<extent_guard>> _locks[2]; #if !defined(LLFIO_DISABLE_OPENMP) && defined(_OPENMP) -#pragma omp parallel for if(_have_source && (_flags &flag::disable_parallelism) == 0) +#pragma omp parallel for if(_have_source && (_flags & flag::disable_parallelism) == 0) #endif for(size_t n = 0; n < 2; n++) { if(n == 0) { - _locks[n] = _target->lock(offset, bytes, exclusive, d); + _locks[n] = this->_target->lock_range(offset, bytes, kind, d); } else if(_have_source) { - _locks[n] = _source->lock(offset, bytes, false, d); + _locks[n] = this->_source->lock_range(offset, bytes, lock_kind::shared, d); } } // Handle any errors @@ -348,42 +374,17 @@ namespace algorithm OUTCOME_TRY(_, std::move(*_locks[1])); _.release(); } - return _extent_guard(this, offset, bytes, exclusive); + return _extent_guard(this, offset, bytes, kind); } //! \brief Unlock the given extent in one or both of the attached handles. - LLFIO_HEADERS_ONLY_VIRTUAL_SPEC void unlock(extent_type offset, extent_type bytes) noexcept override + LLFIO_HEADERS_ONLY_VIRTUAL_SPEC void unlock_range(extent_type offset, extent_type bytes) noexcept override { - _target->unlock(offset, bytes); + this->_target->unlock_range(offset, bytes); if(_have_source) { - _source->unlock(offset, bytes); + this->_source->unlock_range(offset, bytes); } } - }; - template <template <class, class> class Op, class Target, class Source> class combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, true> : public combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false> - { - using _base = combining_handle_adapter_base<Op, Target, Source, file_handle_wrapper, false>; - - protected: - static constexpr bool _have_source = _base::_have_source; - - public: - using path_type = io_handle::path_type; - using extent_type = io_handle::extent_type; - using size_type = io_handle::size_type; - using mode = io_handle::mode; - using creation = io_handle::creation; - using caching = io_handle::caching; - using flag = io_handle::flag; - using buffer_type = io_handle::buffer_type; - using const_buffer_type = io_handle::const_buffer_type; - using buffers_type = io_handle::buffers_type; - using const_buffers_type = io_handle::const_buffers_type; - template <class T> using io_request = io_handle::io_request<T>; - template <class T> using io_result = io_handle::io_result<T>; - - combining_handle_adapter_base() = default; - using _base::_base; //! \brief Return the lesser of one or both of the attached handles LLFIO_HEADERS_ONLY_VIRTUAL_SPEC result<extent_type> maximum_extent() const noexcept override |