pitrou commented on code in PR #40699:
URL: https://github.com/apache/arrow/pull/40699#discussion_r1537894269


##########
cpp/src/arrow/device.cc:
##########
@@ -268,4 +270,67 @@ std::shared_ptr<MemoryManager> 
CPUDevice::default_memory_manager() {
   return default_cpu_memory_manager();
 }
 
+namespace internal {
+
+class DeviceMemoryManagerRegistryImpl {
+ public:
+  DeviceMemoryManagerRegistryImpl() {}
+
+  Status RegisterDevice(DeviceAllocationType device_type, MemoryMapper 
memory_mapper) {
+    std::lock_guard<std::mutex> lock(lock_);
+    auto it = registry_.find(device_type);
+    if (it != registry_.end()) {
+      return Status::KeyError("Device type ", static_cast<int>(device_type),
+                              " is already registered");
+    }
+    registry_[device_type] = std::move(memory_mapper);

Review Comment:
   This is fine, but it can perhaps be shortened using 
https://en.cppreference.com/w/cpp/container/unordered_map/try_emplace :
   ```suggestion
       auto [_, inserted] = registry.try_emplace(device_type, 
std::move(memory_mapper));
       if (!inserted) {
         return Status::KeyError("Device type ", static_cast<int>(device_type),
                                 " is already registered");
       }
   ```



-- 
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]

Reply via email to