Skip to content

Commit

Permalink
Fix #80 by no longer exporting from a DLL map_handle_cache(). Thanks …
Browse files Browse the repository at this point in the history
…to awson for reporting this.

Also make map_handle_cache unique ptr based to avoid static deinit fiasco.
  • Loading branch information
ned14 committed Sep 14, 2021
1 parent 7238591 commit e9c8019
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions include/llfio/revision.hpp
Original file line number Diff line number Diff line change
@@ -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
24 changes: 13 additions & 11 deletions include/llfio/v2.0/detail/impl/map_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(...)
{
Expand All @@ -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

0 comments on commit e9c8019

Please sign in to comment.