Fix bug on mgp dispatcher guard (#1225)
This commit is contained in:
parent
d9464c6ffd
commit
974a6e3027
@ -126,6 +126,12 @@ class MemoryDispatcher final {
|
|||||||
map_.erase(this_id);
|
map_.erase(this_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsThisThreadRegistered() noexcept {
|
||||||
|
const auto this_id = std::this_thread::get_id();
|
||||||
|
std::shared_lock lock(mut_);
|
||||||
|
return map_.contains(this_id);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::thread::id, mgp_memory *> map_;
|
std::unordered_map<std::thread::id, mgp_memory *> map_;
|
||||||
std::shared_mutex mut_;
|
std::shared_mutex mut_;
|
||||||
@ -136,7 +142,7 @@ class MemoryDispatcher final {
|
|||||||
// header. The use of the 'mgp_memory *memory' pointer is deprecated
|
// header. The use of the 'mgp_memory *memory' pointer is deprecated
|
||||||
// and will be removed in upcoming releases.
|
// and will be removed in upcoming releases.
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
inline extern MemoryDispatcher mrd{};
|
inline MemoryDispatcher mrd{};
|
||||||
|
|
||||||
// TODO - Once we deprecate this we should remove this
|
// TODO - Once we deprecate this we should remove this
|
||||||
// and make sure nothing relies on it anymore. This alone
|
// and make sure nothing relies on it anymore. This alone
|
||||||
@ -164,7 +170,7 @@ class MemoryDispatcherGuard final {
|
|||||||
// the mapping instead.
|
// the mapping instead.
|
||||||
template <typename Func, typename... Args>
|
template <typename Func, typename... Args>
|
||||||
inline decltype(auto) MemHandlerCallback(Func &&func, Args &&...args) {
|
inline decltype(auto) MemHandlerCallback(Func &&func, Args &&...args) {
|
||||||
if (memory) {
|
if (!mrd.IsThisThreadRegistered()) {
|
||||||
return std::forward<Func>(func)(std::forward<Args>(args)..., memory);
|
return std::forward<Func>(func)(std::forward<Args>(args)..., memory);
|
||||||
}
|
}
|
||||||
return std::forward<Func>(func)(std::forward<Args>(args)..., mrd.GetMemoryResource());
|
return std::forward<Func>(func)(std::forward<Args>(args)..., mrd.GetMemoryResource());
|
||||||
|
Loading…
Reference in New Issue
Block a user