rm5248 commented on a change in pull request #93:
URL: https://github.com/apache/logging-log4cxx/pull/93#discussion_r777154247



##########
File path: src/main/cpp/aprinitializer.cpp
##########
@@ -127,3 +127,21 @@ void APRInitializer::unregisterCleanup(FileWatchdog* 
watchdog)
        }
 }
 
+void APRInitializer::addObject(size_t key, const ObjectPtr& pObject)
+{
+#if APR_HAS_THREADS
+       std::unique_lock<std::mutex> lock(this->mutex);
+#endif
+    this->objects[key] = pObject;
+}
+
+const ObjectPtr& APRInitializer::findOrAddObject(size_t key, 
std::function<ObjectPtr()> creator)
+{
+#if APR_HAS_THREADS
+       std::unique_lock<std::mutex> lock(this->mutex);
+#endif
+    auto pItem = this->objects.find(key);
+    if (this->objects.end() == pItem)
+        pItem = this->objects.emplace(key, creator()).first;

Review comment:
       Depending on what it is used for, if I want to get an object of some 
kind from here there is currently no way to do that, we would have to either 
pass in a an invalid function, or create a new method `getObject<T>`, or 
something like that.  I'm not sure if we would ever want to do that.
   
   As it is, it isn't really "undefined behavior," since it would throw 
`std::bad_function_call` if an invalid function was passed.  We could just 
change `if (this->objects.end() == pItem)` to `if (this->objects.end() == pItem 
&& creator)` since `operator bool()` is provided.




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