diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2021-09-14 22:55:41 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2021-09-14 22:55:41 +0300 |
commit | e9c80196d3c5e290409dbe88e6a9b7cfbe2f0945 (patch) | |
tree | 727e4fc364479acaa35baaa8cc75a72c7e0db864 | |
parent | 7238591f99132d8c0b223c144f21276e952c8e3f (diff) |
Fix #80 by no longer exporting from a DLL map_handle_cache(). Thanks to awson for reporting this.
Also make map_handle_cache unique ptr based to avoid static deinit fiasco.
-rw-r--r-- | include/llfio/revision.hpp | 6 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/map_handle.ipp | 24 |
2 files changed, 16 insertions, 14 deletions
diff --git a/include/llfio/revision.hpp b/include/llfio/revision.hpp index d7f4cf22..3ac1584e 100644 --- a/include/llfio/revision.hpp +++ b/include/llfio/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 LLFIO_PREVIOUS_COMMIT_REF bcc600db9feb6aa50e0880422a071d0e39ae74aa -#define LLFIO_PREVIOUS_COMMIT_DATE "2021-08-30 15:08:05 +00:00" -#define LLFIO_PREVIOUS_COMMIT_UNIQUE bcc600db +#define LLFIO_PREVIOUS_COMMIT_REF 7238591f99132d8c0b223c144f21276e952c8e3f +#define LLFIO_PREVIOUS_COMMIT_DATE "2021-09-14 19:42:09 +00:00" +#define LLFIO_PREVIOUS_COMMIT_UNIQUE 7238591f diff --git a/include/llfio/v2.0/detail/impl/map_handle.ipp b/include/llfio/v2.0/detail/impl/map_handle.ipp index 50d46ae8..70c12822 100644 --- a/include/llfio/v2.0/detail/impl/map_handle.ipp +++ b/include/llfio/v2.0/detail/impl/map_handle.ipp @@ -171,10 +171,10 @@ namespace detail return ret; } }; - extern inline QUICKCPPLIB_SYMBOL_EXPORT map_handle_cache_t &map_handle_cache() + extern inline QUICKCPPLIB_SYMBOL_VISIBLE map_handle_cache_t *map_handle_cache() { - static map_handle_cache_t v; - return v; + static auto v = std::make_unique<map_handle_cache_t>(); + return v.get(); } } // namespace detail @@ -184,8 +184,8 @@ result<map_handle> map_handle::_recycled_map(size_type bytes, section_handle::fl { return errc::argument_out_of_domain; } - auto &c = detail::map_handle_cache(); - if(c.is_disabled()) + auto *c = detail::map_handle_cache(); + if(c == nullptr || c->is_disabled()) { return _new_map(bytes, false, _flag); } @@ -194,7 +194,7 @@ result<map_handle> map_handle::_recycled_map(size_type bytes, section_handle::fl OUTCOME_TRY(auto &&pagesize, detail::pagesize_from_flags(ret.value()._flag)); bytes = utils::round_up_to_page_size(bytes, pagesize); LLFIO_LOG_FUNCTION_CALL(&ret); - void *addr = c.get(bytes, pagesize); + void *addr = c->get(bytes, pagesize); if(addr == nullptr) { return _new_map(bytes, false, _flag); @@ -250,8 +250,8 @@ bool map_handle::_recycle_map() noexcept try { LLFIO_LOG_FUNCTION_CALL(this); - auto &c = detail::map_handle_cache(); - if(c.is_disabled()) + auto *c = detail::map_handle_cache(); + if(c == nullptr || c->is_disabled()) { return false; } @@ -284,7 +284,7 @@ bool map_handle::_recycle_map() noexcept } #endif #endif - return c.add(_reservation, _pagesize, _addr); + return c->add(_reservation, _pagesize, _addr); } catch(...) { @@ -294,12 +294,14 @@ bool map_handle::_recycle_map() noexcept map_handle::cache_statistics map_handle::trim_cache(std::chrono::steady_clock::time_point older_than, size_t max_items) noexcept { - return detail::map_handle_cache().trim_cache(older_than, max_items); + auto *c = detail::map_handle_cache(); + return (c != nullptr) ? c->trim_cache(older_than, max_items) : cache_statistics{}; } bool map_handle::set_cache_disabled(bool disabled) noexcept { - return detail::map_handle_cache().set_cache_disabled(disabled); + auto *c = detail::map_handle_cache(); + return (c != nullptr) ? set_cache_disabled(disabled) : true; } LLFIO_V2_NAMESPACE_END |