Some oslCondition -> osl::Condition

Change-Id: I86cfbefd1cb8b22fca659a158b8e31d5c991de7a
This commit is contained in:
Stephan Bergmann
2015-08-18 08:15:29 +02:00
parent 5d6ef74eea
commit 2861d5bedc
4 changed files with 22 additions and 28 deletions

View File

@@ -28,19 +28,11 @@ namespace cppu_threadpool {
JobQueue::JobQueue() :
m_nToDo( 0 ),
m_bSuspended( false ),
m_cndWait( osl_createCondition() )
m_bSuspended( false )
{
osl_resetCondition( m_cndWait );
m_DisposedCallerAdmin = DisposedCallerAdmin::getInstance();
}
JobQueue::~JobQueue()
{
osl_destroyCondition( m_cndWait );
}
void JobQueue::add( void *pThreadSpecificData, RequestFun * doRequest )
{
MutexGuard guard( m_mutex );
@@ -48,7 +40,7 @@ namespace cppu_threadpool {
m_lstJob.push_back( job );
if( ! m_bSuspended )
{
osl_setCondition( m_cndWait );
m_cndWait.set();
}
m_nToDo ++;
}
@@ -78,7 +70,7 @@ namespace cppu_threadpool {
}
}
osl_waitCondition( m_cndWait , 0 );
m_cndWait.wait();
struct Job job={0,0};
{
@@ -92,7 +84,7 @@ namespace cppu_threadpool {
&& (m_lstCallstack.empty()
|| m_lstCallstack.front() != 0) )
{
osl_resetCondition( m_cndWait );
m_cndWait.reset();
}
break;
}
@@ -106,7 +98,7 @@ namespace cppu_threadpool {
if( m_lstJob.empty()
&& (m_lstCallstack.empty() || m_lstCallstack.front() != 0) )
{
osl_resetCondition( m_cndWait );
m_cndWait.reset();
}
}
@@ -150,7 +142,7 @@ namespace cppu_threadpool {
if( !m_lstCallstack.empty() && ! m_lstCallstack.front() )
{
// The thread is waiting for a disposed pCallerId, let it go
osl_setCondition( m_cndWait );
m_cndWait.set();
}
}
@@ -166,7 +158,7 @@ namespace cppu_threadpool {
m_bSuspended = false;
if( ! m_lstJob.empty() )
{
osl_setCondition( m_cndWait );
m_cndWait.set();
}
}

View File

@@ -23,7 +23,7 @@
#include <list>
#include <sal/types.h>
#include <osl/conditn.h>
#include <osl/conditn.hxx>
#include <osl/mutex.hxx>
#include <boost/shared_ptr.hpp>
@@ -49,7 +49,6 @@ namespace cppu_threadpool
{
public:
JobQueue();
~JobQueue();
void add( void *pThreadSpecificData, RequestFun * doRequest );
@@ -69,7 +68,7 @@ namespace cppu_threadpool
CallStackList m_lstCallstack;
sal_Int32 m_nToDo;
bool m_bSuspended;
oslCondition m_cndWait;
osl::Condition m_cndWait;
DisposedCallerAdminHolder m_DisposedCallerAdmin;
};
}

View File

@@ -39,6 +39,10 @@ using namespace ::rtl;
namespace cppu_threadpool
{
WaitingThread::WaitingThread(
rtl::Reference<ORequestThread> const & theThread): thread(theThread)
{}
struct theDisposedCallerAdmin :
public rtl::StaticWithInit< DisposedCallerAdminHolder, theDisposedCallerAdmin >
{
@@ -138,9 +142,7 @@ namespace cppu_threadpool
******************/
void ThreadPool::waitInPool( rtl::Reference< ORequestThread > const & pThread )
{
struct WaitingThread waitingThread;
waitingThread.condition = osl_createCondition();
waitingThread.thread = pThread;
WaitingThread waitingThread(pThread);
{
MutexGuard guard( m_mutexWaitingThreadList );
m_lstThreads.push_front( &waitingThread );
@@ -148,7 +150,7 @@ namespace cppu_threadpool
// let the thread wait 2 seconds
TimeValue time = { 2 , 0 };
osl_waitCondition( waitingThread.condition , &time );
waitingThread.condition.wait( &time );
{
MutexGuard guard ( m_mutexWaitingThreadList );
@@ -161,8 +163,6 @@ namespace cppu_threadpool
m_lstThreads.erase( ii );
}
}
osl_destroyCondition( waitingThread.condition );
}
void ThreadPool::joinWorkers()
@@ -174,7 +174,7 @@ namespace cppu_threadpool
++ ii )
{
// wake the threads up
osl_setCondition( (*ii)->condition );
(*ii)->condition.set();
}
}
m_aThreadAdmin.join();
@@ -198,7 +198,7 @@ namespace cppu_threadpool
m_lstThreads.pop_back();
// let the thread go
osl_setCondition( pWaitingThread->condition );
pWaitingThread->condition.set();
return true;
}
}

View File

@@ -23,7 +23,7 @@
#include <list>
#include <unordered_map>
#include <osl/conditn.h>
#include <osl/conditn.hxx>
#include <rtl/byteseq.hxx>
#include <rtl/ref.hxx>
@@ -70,8 +70,11 @@ namespace cppu_threadpool {
struct WaitingThread
{
oslCondition condition;
osl::Condition condition;
rtl::Reference< ORequestThread > thread;
explicit WaitingThread(
rtl::Reference<ORequestThread> const & theThread);
};
typedef ::std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList;