18#ifndef _LOG4CXX_THREADUTILITY_H
19#define _LOG4CXX_THREADUTILITY_H
53 , std::thread::id threadId
54 , std::thread::native_handle_type nativeHandle
72class LOG4CXX_EXPORT ThreadUtility
78 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(priv_data, m_priv)
106 template<
class Function,
class... Args>
113 ThreadStartContext ctx(
this);
114 std::thread t( f, args... );
115 ctx.setThreadName(name, t.get_id(), t.native_handle());
119 using Period = std::chrono::milliseconds;
157 struct LOG4CXX_EXPORT ThreadStartContext
159 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Impl, m_priv)
160 ThreadStartContext(ThreadUtility* parent);
161 ~ThreadStartContext();
164 , std::thread::id threadId
165 , std::thread::native_handle_type nativeHandle
Wraps any singleton object so it can be added to APRInitializer.
Definition singletonholder.h:32
static ManagerPtr instancePtr()
void removePeriodicTasksMatching(const LogString &namePrefix)
Remove any periodic task matching namePrefix.
void removePeriodicTask(const LogString &taskName)
Remove the taskName periodic task.
SingletonHolder< ThreadUtility > Manager
Definition threadutility.h:151
bool isProcessingThreadActive() const
Is the processing thread running?
void addPeriodicTask(const LogString &taskName, std::function< void()> f, const Period &delay)
Add the taskName periodic task.
std::chrono::milliseconds Period
Definition threadutility.h:119
static ThreadUtility * instance()
ThreadConfigurationType configureFuncs(ThreadStartPre pre_start, ThreadStarted set_name, ThreadStartPost post_start)
Set call-back functions to use when starting a thread.
void removeAllPeriodicTasks()
Remove all periodic tasks and stop the processing thread.
std::thread createThread(LogString name, Function &&f, Args &&... args)
Start a thread.
Definition threadutility.h:108
bool hasPeriodicTask(const LogString &taskName)
Has a taskName periodic task already been added?
static ThreadConfigurationType configure(ThreadConfigurationType new_value)
Use new_value as the behviour when starting a thread.
ThreadConfigurationType
Definition threadutility.h:65
@ NoConfiguration
Definition threadutility.h:66
@ BlockSignalsAndNameThread
Definition threadutility.h:69
@ NameThreadOnly
Definition threadutility.h:68
@ BlockSignalsOnly
Definition threadutility.h:67
std::function< void()> ThreadStartPre
A function that will be called before a thread is started.
Definition threadutility.h:39
std::function< void(LogString threadName, std::thread::id threadId, std::thread::native_handle_type nativeHandle) > ThreadStarted
Called when a new thread has started.
Definition threadutility.h:50
std::function< void()> ThreadStartPost
Called after a thread has started.
Definition threadutility.h:62
std::basic_string< logchar > LogString
Definition logstring.h:51