mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-15 15:16:49 +02:00
Thread fixes for WinCE
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Runnable.h"
|
#include "Poco/Runnable.h"
|
||||||
|
#include "Poco/SharedPtr.h"
|
||||||
#include "Poco/UnWindows.h"
|
#include "Poco/UnWindows.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -40,16 +41,6 @@ public:
|
|||||||
typedef void (*Callable)(void*);
|
typedef void (*Callable)(void*);
|
||||||
typedef DWORD (WINAPI *Entry)(LPVOID);
|
typedef DWORD (WINAPI *Entry)(LPVOID);
|
||||||
|
|
||||||
struct CallbackData
|
|
||||||
{
|
|
||||||
CallbackData(): callback(0), pData(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Callable callback;
|
|
||||||
void* pData;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Priority
|
enum Priority
|
||||||
{
|
{
|
||||||
PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST,
|
PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST,
|
||||||
@@ -76,9 +67,7 @@ public:
|
|||||||
static int getMaxOSPriorityImpl(int policy);
|
static int getMaxOSPriorityImpl(int policy);
|
||||||
void setStackSizeImpl(int size);
|
void setStackSizeImpl(int size);
|
||||||
int getStackSizeImpl() const;
|
int getStackSizeImpl() const;
|
||||||
void startImpl(Runnable& target);
|
void startImpl(SharedPtr<Runnable> pTarget);
|
||||||
void startImpl(Callable target, void* pData = 0);
|
|
||||||
|
|
||||||
void joinImpl();
|
void joinImpl();
|
||||||
bool joinImpl(long milliseconds);
|
bool joinImpl(long milliseconds);
|
||||||
bool isRunningImpl() const;
|
bool isRunningImpl() const;
|
||||||
@@ -89,7 +78,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static DWORD WINAPI runnableEntry(LPVOID pThread);
|
static DWORD WINAPI runnableEntry(LPVOID pThread);
|
||||||
static DWORD WINAPI callableEntry(LPVOID pThread);
|
|
||||||
|
|
||||||
void createImpl(Entry ent, void* pData);
|
void createImpl(Entry ent, void* pData);
|
||||||
void threadCleanup();
|
void threadCleanup();
|
||||||
@@ -120,8 +108,7 @@ private:
|
|||||||
DWORD _slot;
|
DWORD _slot;
|
||||||
};
|
};
|
||||||
|
|
||||||
Runnable* _pRunnableTarget;
|
SharedPtr<Runnable> _pRunnableTarget;
|
||||||
CallbackData _callbackTarget;
|
|
||||||
HANDLE _thread;
|
HANDLE _thread;
|
||||||
DWORD _threadId;
|
DWORD _threadId;
|
||||||
int _prio;
|
int _prio;
|
||||||
|
@@ -61,29 +61,17 @@ void ThreadImpl::setOSPriorityImpl(int prio, int /* policy */)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ThreadImpl::startImpl(Runnable& target)
|
void ThreadImpl::startImpl(SharedPtr<Runnable> pTarget)
|
||||||
{
|
{
|
||||||
if (isRunningImpl())
|
if (isRunningImpl())
|
||||||
throw SystemException("thread already running");
|
throw SystemException("thread already running");
|
||||||
|
|
||||||
_pRunnableTarget = ⌖
|
_pRunnableTarget = pTarget;
|
||||||
|
|
||||||
createImpl(runnableEntry, this);
|
createImpl(runnableEntry, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ThreadImpl::startImpl(Callable target, void* pData)
|
|
||||||
{
|
|
||||||
if (isRunningImpl())
|
|
||||||
throw SystemException("thread already running");
|
|
||||||
|
|
||||||
_callbackTarget.callback = target;
|
|
||||||
_callbackTarget.pData = pData;
|
|
||||||
|
|
||||||
createImpl(callableEntry, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ThreadImpl::createImpl(Entry ent, void* pData)
|
void ThreadImpl::createImpl(Entry ent, void* pData)
|
||||||
{
|
{
|
||||||
_thread = CreateThread(NULL, _stackSize, ent, pData, 0, &_threadId);
|
_thread = CreateThread(NULL, _stackSize, ent, pData, 0, &_threadId);
|
||||||
@@ -180,28 +168,4 @@ DWORD WINAPI ThreadImpl::runnableEntry(LPVOID pThread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DWORD WINAPI ThreadImpl::callableEntry(LPVOID pThread)
|
|
||||||
{
|
|
||||||
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ThreadImpl* pTI = reinterpret_cast<ThreadImpl*>(pThread);
|
|
||||||
pTI->_callbackTarget.callback(pTI->_callbackTarget.pData);
|
|
||||||
}
|
|
||||||
catch (Exception& exc)
|
|
||||||
{
|
|
||||||
ErrorHandler::handle(exc);
|
|
||||||
}
|
|
||||||
catch (std::exception& exc)
|
|
||||||
{
|
|
||||||
ErrorHandler::handle(exc);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
ErrorHandler::handle();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
Reference in New Issue
Block a user