rm5248 commented on code in PR #190:
URL: https://github.com/apache/logging-log4cxx/pull/190#discussion_r1096614870


##########
src/main/include/log4cxx/private/mutex.h:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+#ifndef LOG4CXX_PRIV_MUTEX_HDR_
+#define LOG4CXX_PRIV_MUTEX_HDR_
+#include <mutex>
+#include <log4cxx/helpers/loglog.h>
+#include <log4cxx/helpers/stringhelper.h>
+#if !defined(LOG4CXX)
+       #define LOG4CXX 1
+#endif
+#include <log4cxx/private/log4cxx_private.h>
+
+namespace log4cxx
+{
+
+using AppenderMutexType = std::mutex;
+using AppenderScopeGuard = std::lock_guard<AppenderMutexType>;
+using AppenderScopedLock = std::unique_lock<AppenderMutexType>;
+
+// Change mutex attributes to avoid priority inversion problems
+template <class M>
+       void
+EnablePriorityInheritance(M& m, helpers::Pool& p)

Review Comment:
   This was the best thing that I was able to find: 
https://linux.die.net/man/3/pthread_mutexattr_init
   
   I think part of what's confusing me is that the multiple if statements are a 
strange way of writing the code, it didn't really occur to me that all of the 
if statements would be executed.
   
   I suspect that the `pthread_mutex_destroy` and `pthread_mutex_init` on the 
native handle are technically undefined behavior though.  It probably won't 
cause issues now, but who knows what might change in the future?
   
   
   Would a lockfree queue work, and/or changing the `std::mutex` to a 
`shared_mutex` work better than messing around with the internal mutex?  The 
original patch that was added in used effectively a `shared_mutex` with the 
lockfree queue(see: https://issues.apache.org/jira/browse/LOGCXX-500).  I think 
I removed everything that used `shared_mutex` to make it C++11 compatible, but 
there's still a compile test to see if it there(so we can easily switch between 
`std::shared_mutex` or `boost::shared_mutex`).



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