24#include <osl/diagnose.h>
28#include <com/sun/star/util/XJobManager.hpp>
39 : mrThreadJoiner( rThreadJoiner ),
40 mnThreadIDCounter( 0 ),
41 maStartNewThreadIdle(
"SW ThreadManager StartNewThreadIdle"),
42 mbStartingOfThreadsSuspended( false )
74 std::unique_lock aGuard(
maMutex);
85 aThreadData.
pThread->setPriority( osl_Thread_PriorityBelowNormal );
116 const bool bThreadFinished )
119 std::unique_lock aGuard(
maMutex);
121 std::deque< tThreadData >::iterator aIter =
131 if ( bThreadFinished )
134 css::uno::Reference< css::util::XJobManager > rThreadJoiner(
mrThreadJoiner );
135 if ( rThreadJoiner.is() )
137 rThreadJoiner->releaseJob( aTmpThreadData.
aJob );
141 OSL_FAIL(
"<ThreadManager::RemoveThread(..)> - ThreadJoiner already gone!" );
147 TryToStartNewThread(
nullptr );
178 bool bThreadStarted(
false );
180 if ( rThreadData.
pThread->create() )
183 bThreadStarted =
true;
188 css::uno::Reference< css::util::XJobManager > rThreadJoiner(
mrThreadJoiner );
189 if ( rThreadJoiner.is() )
191 rThreadJoiner->registerJob( rThreadData.
aJob );
195 OSL_FAIL(
"<ThreadManager::StartThread(..)> - ThreadJoiner already gone!" );
204 return bThreadStarted;
209 std::unique_lock aGuard(
maMutex);
211 if ( mbStartingOfThreadsSuspended )
215 if ( !StartWaitingThread() )
220 if ( maStartedThreads.empty() && !maWaitingForStartThreads.empty() )
222 maStartNewThreadIdle.Start();
229 std::unique_lock aGuard(
maMutex);
virtual void Start(bool bStartTimer=true) override
void SetPriority(TaskPriority ePriority)
std::deque< tThreadData > maStartedThreads
std::shared_ptr< ThreadListener > mpThreadListener
bool StartThread(const tThreadData &aThreadData)
oslInterlockedCount mnThreadIDCounter
std::deque< tThreadData > maWaitingForStartThreads
void ResumeStartingOfThreads()
continues the starting of threads after it has been suspended
css::uno::WeakReference< css::util::XJobManager > mrThreadJoiner
bool StartWaitingThread()
static const std::deque< tThreadData >::size_type snStartedSize
class to manage threads
ThreadManager(css::uno::Reference< css::util::XJobManager > const &rThreadJoiner)
oslInterlockedCount AddThread(const ::rtl::Reference< ObservableThread > &rThread)
add thread to the thread manager and taking ownership for the thread
void Init()
initialization
Idle maStartNewThreadIdle
bool mbStartingOfThreadsSuspended
std::weak_ptr< IFinishedThreadListener > GetThreadListenerWeakRef() const
void NotifyAboutFinishedThread(const oslInterlockedCount nThreadID)
void RemoveThread(const oslInterlockedCount nThreadID, const bool bThreadFinished=false)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
#define LINK(Instance, Class, Member)
css::uno::Reference< css::util::XCancellable > aJob
::rtl::Reference< ObservableThread > pThread
oslInterlockedCount nThreadID
IMPL_LINK_NOARG(ThreadManager, TryToStartNewThread, Timer *, void)