Skip to content

Commit

Permalink
[GLUTEN-6534] [VL] Fix ObjectStore::stores initialized twice issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xumingming committed Jul 22, 2024
1 parent 23af01d commit 77c86cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions cpp/core/utils/ObjectStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
#include <glog/logging.h>
#include <iostream>

// static
gluten::ResourceMap<gluten::ObjectStore*>& gluten::ObjectStore::stores() {
static gluten::ResourceMap<gluten::ObjectStore*> stores;
return stores;
}

gluten::ObjectStore::~ObjectStore() {
// destructing in reversed order (the last added object destructed first)
const std::lock_guard<std::mutex> lock(mtx_);
Expand Down
5 changes: 1 addition & 4 deletions cpp/core/utils/ObjectStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ class ObjectStore {
ObjectHandle save(std::shared_ptr<void> obj);

private:
static ResourceMap<ObjectStore*>& stores() {
static ResourceMap<ObjectStore*> stores;
return stores;
}
static ResourceMap<ObjectStore*>& stores();

ObjectHandle toObjHandle(ResourceHandle rh) {
ObjectHandle prefix = static_cast<ObjectHandle>(storeId_) << (sizeof(ResourceHandle) * 8);
Expand Down
7 changes: 5 additions & 2 deletions cpp/core/utils/ResourceMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ class ResourceMap {

void erase(ResourceHandle moduleId) {
const std::lock_guard<std::mutex> lock(mtx_);
GLUTEN_CHECK(map_.erase(moduleId) == 1, "Module not found in resource map: " + std::to_string(moduleId));
GLUTEN_CHECK(
map_.erase(moduleId) == 1,
"ResourceHandle not found in resource map when try to erase: " + std::to_string(moduleId));
}

TResource lookup(ResourceHandle moduleId) {
const std::lock_guard<std::mutex> lock(mtx_);
auto it = map_.find(moduleId);
GLUTEN_CHECK(it != map_.end(), "Module not found in resource map: " + std::to_string(moduleId));
GLUTEN_CHECK(
it != map_.end(), "ResourceHandle not found in resource map when try to lookup: " + std::to_string(moduleId));
return it->second;
}

Expand Down

0 comments on commit 77c86cc

Please sign in to comment.