rm5248 commented on a change in pull request #68:
URL: https://github.com/apache/logging-log4cxx/pull/68#discussion_r695269717
##########
File path: src/main/include/log4cxx/helpers/threadutility.h
##########
@@ -0,0 +1,119 @@
+#ifndef _LOG4CXX_THREADUTILITY_H
+#define _LOG4CXX_THREADUTILITY_H
+
+#include <thread>
+#include <functional>
+#include <memory>
+
+#include "log4cxx/logstring.h"
+
+namespace log4cxx {
+namespace helpers {
+
+/**
+ * A function that will be called before a thread is started. This can
+ * be used to (for example) block all of the signals in the thread, so
+ * that when the thread is created it will have a correct signal mask.
+ */
+typedef std::function<void()> pre_thread_start;
+
+/**
+ * Called when a new thread has started. This can be used to set
+ * parameters for the thread in a platform-specific manner.
+ *
+ * @param threadName The name of the thread
+ * @param thread_id The ID of the thread as reported by std::thread::get_id
+ * @param native_handle The native handle of the thread, as reported by
+ * std::thread::native_handle
+ */
+typedef std::function<void( LogString threadName,
+ std::thread::id thread_id,
+ std::thread::native_handle_type native_handle
)> thread_started;
+
+/**
+ * Called after a thread has started. This can be used to (for example)
+ * unblock the signals in the thread.
+ */
+typedef std::function<void()> post_thread_start;
+
+class ThreadUtility;
+LOG4CXX_PTR_DEF(ThreadUtility);
+
+class LOG4CXX_EXPORT ThreadUtility {
+private:
+ ThreadUtility();
+
+ log4cxx::helpers::pre_thread_start preStartFunction();
+ log4cxx::helpers::thread_started threadStartedFunction();
+ log4cxx::helpers::post_thread_start postStartFunction();
+
+ struct priv_data;
+ std::unique_ptr<priv_data> m_priv;
+
+public:
+ ~ThreadUtility();
+
+ static std::shared_ptr<ThreadUtility> instance();
+
+ /**
+ * Configure the thread functions that log4cxx will use.
+ * Note that setting any of these parameters to nullptr is valid,
+ * and simply results in the callback not being called. *
+ */
+ void configureThreadFunctions( pre_thread_start pre_start,
+
thread_started started,
+
post_thread_start post_start );
+
+ /**
+ * A pre-start thread function that blocks signals to the new thread
+ * (if the system has pthreads). If the system does not have pthreads,
+ * is equivalent to preThreadDoNothing();
+ */
+ void preThreadBlockSignals();
+
+ /**
+ * A thread_started function that names the thread using the appropriate
+ * system call.
+ */
+ void threadStartedNameThread(LogString threadName,
+
std::thread::id thread_id,
+
std::thread::native_handle_type native_handle);
+
+ /**
+ * A post-start thread function that unblocks signals that
preThreadBlockSignals
+ * blocked before starting the thread. If the system does not have
pthreads,
+ * is equivalent to postThreadDoNothing();
Review comment:
Outdated comment; I originally had a method that did nothing, but then I
realized that just testing the `std::function` to see if it is valid does the
same thing.
--
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]