mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 02:53:10 +01:00
trunk/branch integration: VxWorks & Wince
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread.cpp
|
// Thread.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/src/Thread.cpp#16 $
|
// $Id: //poco/1.4/Foundation/src/Thread.cpp#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -47,6 +47,8 @@
|
|||||||
#else
|
#else
|
||||||
#include "Thread_WIN32.cpp"
|
#include "Thread_WIN32.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined(POCO_VXWORKS)
|
||||||
|
#include "Thread_VX.cpp"
|
||||||
#else
|
#else
|
||||||
#include "Thread_POSIX.cpp"
|
#include "Thread_POSIX.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,14 +16,14 @@
|
|||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// execute, and transmit the Software, and to prepare derivative works of the
|
||||||
// Software, and to permit third-parties to whom the Software is furnished to
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction and the following disclaimer,
|
// the above license grant, this restriction and the following disclaimer,
|
||||||
// must be included in all copies of the Software, in whole or in part, and
|
// must be included in all copies of the Software, in whole or in part, and
|
||||||
// all derivative works of the Software, unless such copies or derivative
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
@@ -79,11 +79,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PooledThread::PooledThread(const std::string& name, int stackSize):
|
PooledThread::PooledThread(const std::string& name, int stackSize):
|
||||||
_idle(true),
|
_idle(true),
|
||||||
_idleTime(0),
|
_idleTime(0),
|
||||||
_pTarget(0),
|
_pTarget(0),
|
||||||
_name(name),
|
_name(name),
|
||||||
_thread(name),
|
_thread(name),
|
||||||
_targetCompleted(false)
|
_targetCompleted(false)
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,7 @@ void PooledThread::start()
|
|||||||
void PooledThread::start(Thread::Priority priority, Runnable& target)
|
void PooledThread::start(Thread::Priority priority, Runnable& target)
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
poco_assert (_pTarget == 0);
|
poco_assert (_pTarget == 0);
|
||||||
|
|
||||||
_pTarget = ⌖
|
_pTarget = ⌖
|
||||||
@@ -138,7 +138,7 @@ void PooledThread::start(Thread::Priority priority, Runnable& target, const std:
|
|||||||
}
|
}
|
||||||
_thread.setName(fullName);
|
_thread.setName(fullName);
|
||||||
_thread.setPriority(priority);
|
_thread.setPriority(priority);
|
||||||
|
|
||||||
poco_assert (_pTarget == 0);
|
poco_assert (_pTarget == 0);
|
||||||
|
|
||||||
_pTarget = ⌖
|
_pTarget = ⌖
|
||||||
@@ -177,7 +177,7 @@ void PooledThread::join()
|
|||||||
void PooledThread::activate()
|
void PooledThread::activate()
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
poco_assert (_idle);
|
poco_assert (_idle);
|
||||||
_idle = false;
|
_idle = false;
|
||||||
_targetCompleted.reset();
|
_targetCompleted.reset();
|
||||||
@@ -188,19 +188,19 @@ void PooledThread::release()
|
|||||||
{
|
{
|
||||||
const long JOIN_TIMEOUT = 10000;
|
const long JOIN_TIMEOUT = 10000;
|
||||||
|
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
_pTarget = 0;
|
_pTarget = 0;
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
// In case of a statically allocated thread pool (such
|
// In case of a statically allocated thread pool (such
|
||||||
// as the default thread pool), Windows may have already
|
// as the default thread pool), Windows may have already
|
||||||
// terminated the thread before we got here.
|
// terminated the thread before we got here.
|
||||||
if (_thread.isRunning())
|
if (_thread.isRunning())
|
||||||
_targetReady.set();
|
_targetReady.set();
|
||||||
|
|
||||||
if (_thread.tryJoin(JOIN_TIMEOUT))
|
if (_thread.tryJoin(JOIN_TIMEOUT))
|
||||||
{
|
{
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -255,9 +255,9 @@ void PooledThread::run()
|
|||||||
ThreadPool::ThreadPool(int minCapacity,
|
ThreadPool::ThreadPool(int minCapacity,
|
||||||
int maxCapacity,
|
int maxCapacity,
|
||||||
int idleTime,
|
int idleTime,
|
||||||
int stackSize):
|
int stackSize):
|
||||||
_minCapacity(minCapacity),
|
_minCapacity(minCapacity),
|
||||||
_maxCapacity(maxCapacity),
|
_maxCapacity(maxCapacity),
|
||||||
_idleTime(idleTime),
|
_idleTime(idleTime),
|
||||||
_serial(0),
|
_serial(0),
|
||||||
_age(0),
|
_age(0),
|
||||||
@@ -280,8 +280,8 @@ ThreadPool::ThreadPool(const std::string& name,
|
|||||||
int idleTime,
|
int idleTime,
|
||||||
int stackSize):
|
int stackSize):
|
||||||
_name(name),
|
_name(name),
|
||||||
_minCapacity(minCapacity),
|
_minCapacity(minCapacity),
|
||||||
_maxCapacity(maxCapacity),
|
_maxCapacity(maxCapacity),
|
||||||
_idleTime(idleTime),
|
_idleTime(idleTime),
|
||||||
_serial(0),
|
_serial(0),
|
||||||
_age(0),
|
_age(0),
|
||||||
@@ -421,15 +421,15 @@ void ThreadPool::housekeep()
|
|||||||
ThreadVec activeThreads;
|
ThreadVec activeThreads;
|
||||||
idleThreads.reserve(_threads.size());
|
idleThreads.reserve(_threads.size());
|
||||||
activeThreads.reserve(_threads.size());
|
activeThreads.reserve(_threads.size());
|
||||||
|
|
||||||
for (ThreadVec::iterator it = _threads.begin(); it != _threads.end(); ++it)
|
for (ThreadVec::iterator it = _threads.begin(); it != _threads.end(); ++it)
|
||||||
{
|
{
|
||||||
if ((*it)->idle())
|
if ((*it)->idle())
|
||||||
{
|
{
|
||||||
if ((*it)->idleTime() < _idleTime)
|
if ((*it)->idleTime() < _idleTime)
|
||||||
idleThreads.push_back(*it);
|
idleThreads.push_back(*it);
|
||||||
else
|
else
|
||||||
expiredThreads.push_back(*it);
|
expiredThreads.push_back(*it);
|
||||||
}
|
}
|
||||||
else activeThreads.push_back(*it);
|
else activeThreads.push_back(*it);
|
||||||
}
|
}
|
||||||
@@ -467,17 +467,17 @@ PooledThread* ThreadPool::getThread()
|
|||||||
{
|
{
|
||||||
if (_threads.size() < _maxCapacity)
|
if (_threads.size() < _maxCapacity)
|
||||||
{
|
{
|
||||||
pThread = createThread();
|
pThread = createThread();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pThread->start();
|
pThread->start();
|
||||||
_threads.push_back(pThread);
|
_threads.push_back(pThread);
|
||||||
}
|
}
|
||||||
catch(SystemException& e)
|
catch (...)
|
||||||
{
|
{
|
||||||
delete pThread;
|
delete pThread;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else throw NoThreadAvailableException();
|
else throw NoThreadAvailableException();
|
||||||
}
|
}
|
||||||
@@ -508,7 +508,7 @@ public:
|
|||||||
ThreadPool* pool()
|
ThreadPool* pool()
|
||||||
{
|
{
|
||||||
FastMutex::ScopedLock lock(_mutex);
|
FastMutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
if (!_pPool)
|
if (!_pPool)
|
||||||
{
|
{
|
||||||
_pPool = new ThreadPool("default");
|
_pPool = new ThreadPool("default");
|
||||||
@@ -517,7 +517,7 @@ public:
|
|||||||
}
|
}
|
||||||
return _pPool;
|
return _pPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ThreadPool* _pPool;
|
ThreadPool* _pPool;
|
||||||
FastMutex _mutex;
|
FastMutex _mutex;
|
||||||
|
|||||||
@@ -161,13 +161,15 @@ void ThreadImpl::setStackSizeImpl(int size)
|
|||||||
{
|
{
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
// we must round up to a multiple of the memory page size
|
// we must round up to a multiple of the memory page size
|
||||||
const int PAGE_SIZE = 4096;
|
const int PAGE_SIZE = 4096;
|
||||||
size = ((size + PAGE_SIZE - 1)/PAGE_SIZE)*PAGE_SIZE;
|
size = ((size + PAGE_SIZE - 1)/PAGE_SIZE)*PAGE_SIZE;
|
||||||
#endif
|
#endif
|
||||||
if (size < PTHREAD_STACK_MIN)
|
#if !defined(POCO_ANDROID)
|
||||||
size = PTHREAD_STACK_MIN;
|
if (size < PTHREAD_STACK_MIN)
|
||||||
}
|
size = PTHREAD_STACK_MIN;
|
||||||
_pData->stackSize = size;
|
#endif
|
||||||
|
}
|
||||||
|
_pData->stackSize = size;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,11 +141,12 @@ void ThreadImpl::startImpl(Runnable& target)
|
|||||||
|
|
||||||
void ThreadImpl::startImpl(Callable target, void* pData)
|
void ThreadImpl::startImpl(Callable target, void* pData)
|
||||||
{
|
{
|
||||||
if (isRunningImpl())
|
if (isRunningImpl())
|
||||||
throw SystemException("thread already running");
|
throw SystemException("thread already running");
|
||||||
|
|
||||||
_callbackTarget.callback = target;
|
threadCleanup();
|
||||||
_callbackTarget.pData = pData;
|
_callbackTarget.callback = target;
|
||||||
|
_callbackTarget.pData = pData;
|
||||||
|
|
||||||
createImpl(callableEntry, this);
|
createImpl(callableEntry, this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user