mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-16 18:56:52 +02:00
trunk/branch integration: VxWorks & Wince
This commit is contained in:
@@ -45,7 +45,11 @@
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "Poco/Thread_WINCE.h"
|
||||
#else
|
||||
#include "Poco/Thread_WIN32.h"
|
||||
#endif
|
||||
#else
|
||||
#include "Poco/Thread_POSIX.h"
|
||||
#endif
|
||||
@@ -68,6 +72,8 @@ class Foundation_API Thread: private ThreadImpl
|
||||
/// The name of a thread can be changed at any time.
|
||||
{
|
||||
public:
|
||||
typedef ThreadImpl::TIDImpl TID;
|
||||
|
||||
using ThreadImpl::Callable;
|
||||
|
||||
enum Priority
|
||||
@@ -92,6 +98,9 @@ public:
|
||||
int id() const;
|
||||
/// Returns the unique thread ID of the thread.
|
||||
|
||||
TID tid() const;
|
||||
/// Returns the native thread ID of the thread.
|
||||
|
||||
std::string name() const;
|
||||
/// Returns the name of the thread.
|
||||
|
||||
@@ -118,6 +127,8 @@ public:
|
||||
int getOSPriority() const;
|
||||
/// Returns the thread's priority, expressed as an operating system
|
||||
/// specific priority value.
|
||||
///
|
||||
/// May return 0 if the priority has not been explicitly set.
|
||||
|
||||
static int getMinOSPriority();
|
||||
/// Returns the mininum operating system-specific priority value,
|
||||
@@ -172,6 +183,9 @@ public:
|
||||
/// Returns the Thread object for the currently active thread.
|
||||
/// If the current thread is the main thread, 0 is returned.
|
||||
|
||||
static TID currentTid();
|
||||
/// Returns the native thread ID for the current thread.
|
||||
|
||||
protected:
|
||||
ThreadLocalStorage& tls();
|
||||
/// Returns a reference to the thread's local storage.
|
||||
@@ -202,6 +216,12 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline Thread::TID Thread::tid() const
|
||||
{
|
||||
return tidImpl();
|
||||
}
|
||||
|
||||
|
||||
inline int Thread::id() const
|
||||
{
|
||||
return _id;
|
||||
@@ -284,6 +304,12 @@ inline int Thread::getStackSize() const
|
||||
}
|
||||
|
||||
|
||||
inline Thread::TID Thread::currentTid()
|
||||
{
|
||||
return currentTidImpl();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
@@ -73,12 +73,19 @@ public:
|
||||
int maxCapacity = 16,
|
||||
int idleTime = 60,
|
||||
int stackSize = POCO_THREAD_STACK_SIZE);
|
||||
/// Creates a thread pool with minCapacity threads.
|
||||
/// If required, up to maxCapacity threads are created
|
||||
/// a NoThreadAvailableException exception is thrown.
|
||||
/// If a thread is running idle for more than idleTime seconds,
|
||||
/// and more than minCapacity threads are running, the thread
|
||||
/// is killed. Threads are created with given stack size.
|
||||
|
||||
ThreadPool(const std::string& name,
|
||||
int minCapacity = 2,
|
||||
int maxCapacity = 16,
|
||||
int idleTime = 60,
|
||||
int stackSize = POCO_THREAD_STACK_SIZE);
|
||||
/// Creates a thread pool with minCapacity threads.
|
||||
/// Creates a thread pool with the given name and minCapacity threads.
|
||||
/// If required, up to maxCapacity threads are created
|
||||
/// a NoThreadAvailableException exception is thrown.
|
||||
/// If a thread is running idle for more than idleTime seconds,
|
||||
@@ -135,13 +142,25 @@ public:
|
||||
/// threads are available.
|
||||
|
||||
void stopAll();
|
||||
/// Stops all running threads.
|
||||
/// Stops all running threads and waits for their completion.
|
||||
///
|
||||
/// Will also delete all thread objects.
|
||||
/// If used, this method should be the last action before
|
||||
/// the thread pool is deleted.
|
||||
///
|
||||
/// Note: If a thread fails to stop within 10 seconds
|
||||
/// (due to a programming error, for example), the
|
||||
/// underlying thread object will not be deleted and
|
||||
/// this method will return anyway. This allows for a
|
||||
/// more or less graceful shutdown in case of a misbehaving
|
||||
/// thread.
|
||||
|
||||
void joinAll();
|
||||
/// Waits for all threads to complete.
|
||||
///
|
||||
/// Note that this will not actually join() the underlying
|
||||
/// thread, but rather wait for the thread's runnables
|
||||
/// to finish.
|
||||
|
||||
void collect();
|
||||
/// Stops and removes no longer used threads from the
|
||||
@@ -151,6 +170,11 @@ public:
|
||||
/// as the thread pool is also implicitly managed in
|
||||
/// calls to start(), addCapacity() and joinAll().
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name of the thread pool,
|
||||
/// or an empty string if no name has been
|
||||
/// specified in the constructor.
|
||||
|
||||
static ThreadPool& defaultPool();
|
||||
/// Returns a reference to the default
|
||||
/// thread pool.
|
||||
@@ -194,6 +218,12 @@ inline int ThreadPool::getStackSize() const
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& ThreadPool::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
@@ -1,104 +1,109 @@
|
||||
//
|
||||
// ThreadTarget.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ThreadTarget.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: ThreadTarget
|
||||
//
|
||||
// Definition of the ThreadTarget class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// 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
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// 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
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ThreadTarget_INCLUDED
|
||||
#define Foundation_ThreadTarget_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Runnable.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API ThreadTarget: public Runnable
|
||||
/// This adapter simplifies using static member functions as well as
|
||||
/// standalone functions as targets for threads.
|
||||
/// Note that it is possible to pass those entities directly to Thread::start().
|
||||
/// This adapter is provided as a convenience for higher abstraction level
|
||||
/// scenarios where Runnable abstract class is used.
|
||||
///
|
||||
/// Usage:
|
||||
/// class MyObject
|
||||
/// {
|
||||
/// static void doSomething() {}
|
||||
/// };
|
||||
/// ThreadTarget ra(&MyObject::doSomething));
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
///
|
||||
/// or:
|
||||
///
|
||||
/// void doSomething() {}
|
||||
///
|
||||
/// ThreadTarget ra(doSomething));
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
|
||||
{
|
||||
public:
|
||||
typedef void (*Callback)();
|
||||
|
||||
ThreadTarget(Callback method);
|
||||
|
||||
ThreadTarget(const ThreadTarget& te);
|
||||
|
||||
~ThreadTarget();
|
||||
|
||||
ThreadTarget& operator = (const ThreadTarget& te);
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
ThreadTarget();
|
||||
|
||||
Callback _method;
|
||||
};
|
||||
|
||||
|
||||
inline void ThreadTarget::run()
|
||||
{
|
||||
_method();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_ThreadTarget_INCLUDED
|
||||
//
|
||||
// ThreadTarget.h
|
||||
//
|
||||
// $Id: ThreadTarget.h 1327 2010-02-09 13:56:31Z obiltschnig $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
// Module: ThreadTarget
|
||||
//
|
||||
// Definition of the ThreadTarget class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// 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
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// 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
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_ThreadTarget_INCLUDED
|
||||
#define Foundation_ThreadTarget_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/Runnable.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API ThreadTarget: public Runnable
|
||||
/// This adapter simplifies using static member functions as well as
|
||||
/// standalone functions as targets for threads.
|
||||
/// Note that it is possible to pass those entities directly to Thread::start().
|
||||
/// This adapter is provided as a convenience for higher abstraction level
|
||||
/// scenarios where Runnable abstract class is used.
|
||||
///
|
||||
/// For using a non-static member function as a thread target, please
|
||||
/// see the RunnableAdapter class.
|
||||
///
|
||||
/// Usage:
|
||||
/// class MyObject
|
||||
/// {
|
||||
/// static void doSomething() {}
|
||||
/// };
|
||||
/// ThreadTarget ra(&MyObject::doSomething);
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
///
|
||||
/// or:
|
||||
///
|
||||
/// void doSomething() {}
|
||||
///
|
||||
/// ThreadTarget ra(doSomething);
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
{
|
||||
public:
|
||||
typedef void (*Callback)();
|
||||
|
||||
ThreadTarget(Callback method);
|
||||
|
||||
ThreadTarget(const ThreadTarget& te);
|
||||
|
||||
~ThreadTarget();
|
||||
|
||||
ThreadTarget& operator = (const ThreadTarget& te);
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
ThreadTarget();
|
||||
|
||||
Callback _method;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void ThreadTarget::run()
|
||||
{
|
||||
_method();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_ThreadTarget_INCLUDED
|
||||
|
@@ -47,10 +47,15 @@
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <pthread.h>
|
||||
// must be limits.h (not <climits>) for PTHREAD_STACK_MIN on Solaris
|
||||
#include <limits.h>
|
||||
#if !defined(POCO_NO_SYS_SELECT_H)
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#if defined(POCO_VXWORKS)
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -59,6 +64,7 @@ namespace Poco {
|
||||
class Foundation_API ThreadImpl
|
||||
{
|
||||
public:
|
||||
typedef pthread_t TIDImpl;
|
||||
typedef void (*Callable)(void*);
|
||||
|
||||
enum Priority
|
||||
@@ -82,7 +88,8 @@ public:
|
||||
|
||||
ThreadImpl();
|
||||
~ThreadImpl();
|
||||
|
||||
|
||||
TIDImpl tidImpl() const;
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio);
|
||||
@@ -100,6 +107,7 @@ public:
|
||||
static void sleepImpl(long milliseconds);
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
static TIDImpl currentTidImpl();
|
||||
|
||||
protected:
|
||||
static void* runnableEntry(void* pThread);
|
||||
@@ -140,9 +148,15 @@ private:
|
||||
pCallbackTarget(0),
|
||||
thread(0),
|
||||
prio(PRIO_NORMAL_IMPL),
|
||||
osPrio(0),
|
||||
done(false),
|
||||
stackSize(POCO_THREAD_STACK_SIZE)
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
// This workaround is for VxWorks 5.x where
|
||||
// pthread_init() won't properly initialize the thread.
|
||||
std::memset(&thread, 0, sizeof(thread));
|
||||
#endif
|
||||
}
|
||||
|
||||
Runnable* pRunnableTarget;
|
||||
@@ -158,7 +172,7 @@ private:
|
||||
|
||||
static CurrentThreadHolder _currentThreadHolder;
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
#if defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_VXWORKS)
|
||||
SignalHandler::JumpBufferVec _jumpBufferVec;
|
||||
friend class SignalHandler;
|
||||
#endif
|
||||
@@ -199,6 +213,12 @@ inline int ThreadImpl::getStackSizeImpl() const
|
||||
}
|
||||
|
||||
|
||||
inline ThreadImpl::TIDImpl ThreadImpl::tidImpl() const
|
||||
{
|
||||
return _pData->thread;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Thread_WIN32.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/Thread_WIN32.h#8 $
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Thread_WIN32.h#1 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@@ -51,6 +51,7 @@ namespace Poco {
|
||||
class Foundation_API ThreadImpl
|
||||
{
|
||||
public:
|
||||
typedef DWORD TIDImpl;
|
||||
typedef void (*Callable)(void*);
|
||||
|
||||
#if defined(_DLL)
|
||||
@@ -81,6 +82,7 @@ public:
|
||||
ThreadImpl();
|
||||
~ThreadImpl();
|
||||
|
||||
TIDImpl tidImpl() const;
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio);
|
||||
@@ -98,7 +100,8 @@ public:
|
||||
static void sleepImpl(long milliseconds);
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
|
||||
static TIDImpl currentTidImpl();
|
||||
|
||||
protected:
|
||||
#if defined(_DLL)
|
||||
static DWORD WINAPI runnableEntry(LPVOID pThread);
|
||||
@@ -144,6 +147,7 @@ private:
|
||||
Runnable* _pRunnableTarget;
|
||||
CallbackData _callbackTarget;
|
||||
HANDLE _thread;
|
||||
DWORD _threadId;
|
||||
int _prio;
|
||||
int _stackSize;
|
||||
|
||||
@@ -202,6 +206,12 @@ inline int ThreadImpl::getStackSizeImpl() const
|
||||
}
|
||||
|
||||
|
||||
inline ThreadImpl::TIDImpl ThreadImpl::tidImpl() const
|
||||
{
|
||||
return _threadId;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user