PHILO-HE commented on code in PR #7478:
URL: https://github.com/apache/incubator-gluten/pull/7478#discussion_r1797643002


##########
cpp/core/utils/Registry.h:
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <mutex>
+#include <string>
+#include <unordered_map>
+
+#include "utils/Exception.h"
+
+namespace gluten {
+template <typename T>
+class Registry {
+ public:
+  void registerObj(const std::string& kind, T t) {
+    std::lock_guard<std::mutex> l(mutex_);
+    GLUTEN_CHECK(map_.find(kind) == map_.end(), "Already registered for " + 
kind);
+    map_[kind] = std::move(t);
+  }
+
+  T& get(const std::string& kind) {
+    std::lock_guard<std::mutex> l(mutex_);

Review Comment:
   I note these are code refactors. Does read operation deserve to be optimized 
with `std::shared_lock` to allow concurrency?



##########
cpp/core/memory/MemoryManager.cc:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "MemoryManager.h"
+#include "utils/Registry.h"
+
+namespace gluten {
+
+namespace {
+Registry<MemoryManager::Factory>& memoryManagerFactories() {
+  static Registry<MemoryManager::Factory> registry;
+  return registry;
+}
+} // namespace
+
+void MemoryManager::registerFactory(
+    const std::string& kind,
+    std::function<MemoryManager*(std::unique_ptr<AllocationListener>)> 
factory) {

Review Comment:
   Nit: use MemoryManager::Factory for brevity?



##########
cpp/core/memory/MemoryManager.h:
##########
@@ -19,11 +19,17 @@
 
 #include "arrow/memory_pool.h"
 #include "memory.pb.h"
+#include "memory/AllocationListener.h"
 
 namespace gluten {
 
 class MemoryManager {
  public:
+  using Factory = 
std::function<MemoryManager*(std::unique_ptr<AllocationListener> listener)>;

Review Comment:
   Nit: remove unnecessary `listener`.



##########
cpp/core/utils/Registry.h:
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <mutex>
+#include <string>
+#include <unordered_map>
+
+#include "utils/Exception.h"
+
+namespace gluten {
+template <typename T>
+class Registry {
+ public:
+  void registerObj(const std::string& kind, T t) {
+    std::lock_guard<std::mutex> l(mutex_);

Review Comment:
   Nit: better to name it `lock` or some other name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to