You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/01/02 00:11:22 UTC

[GitHub] [logging-log4cxx] swebb2066 commented on a change in pull request #93: Add a unit test for the automatic configuration feature

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



##########
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:
       As getRepositorySelector() is assumed in all calls to always succeed, an invalid `creator` is 'undefined behaviour'.
   
   Also, the `creator ` function is an object, not a pointer so it has to be provided (it should be a precondition).




-- 
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: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org