mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 03:03:23 +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,7 +1,7 @@
|
||||
//
|
||||
// ThreadTarget.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ThreadTarget.h#2 $
|
||||
// $Id: ThreadTarget.h 1327 2010-02-09 13:56:31Z obiltschnig $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
// Definition of the ThreadTarget class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
@@ -54,23 +54,25 @@ class Foundation_API ThreadTarget: public Runnable
|
||||
/// 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));
|
||||
/// ThreadTarget ra(&MyObject::doSomething);
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
///
|
||||
/// or:
|
||||
///
|
||||
/// void doSomething() {}
|
||||
/// void doSomething() {}
|
||||
///
|
||||
/// ThreadTarget ra(doSomething));
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
|
||||
/// ThreadTarget ra(doSomething);
|
||||
/// Thread thr;
|
||||
/// thr.start(ra);
|
||||
{
|
||||
public:
|
||||
typedef void (*Callback)();
|
||||
@@ -92,6 +94,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void ThreadTarget::run()
|
||||
{
|
||||
_method();
|
||||
|
@@ -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
|
||||
@@ -83,6 +89,7 @@ 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,6 +100,7 @@ public:
|
||||
static void sleepImpl(long milliseconds);
|
||||
static void yieldImpl();
|
||||
static ThreadImpl* currentImpl();
|
||||
static TIDImpl currentTidImpl();
|
||||
|
||||
protected:
|
||||
#if defined(_DLL)
|
||||
@@ -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