From d652a7b2fadf18c0a88f24b297f6fe80472331db Mon Sep 17 00:00:00 2001 From: Marian Krivos Date: Mon, 22 Aug 2011 19:56:17 +0000 Subject: [PATCH] trunk/branch integration: new files --- Foundation/include/Poco/Event_VX.h | 71 +++++++ Foundation/include/Poco/Mutex_VX.h | 102 ++++++++++ Foundation/include/Poco/NamedEvent_Android.h | 62 +++++++ Foundation/include/Poco/NamedMutex_Android.h | 63 +++++++ Foundation/include/Poco/RWLock_Android.h | 119 ++++++++++++ Foundation/include/Poco/RWLock_WINCE.h | 83 +++++++++ Foundation/include/Poco/Semaphore_VX.h | 78 ++++++++ Foundation/include/Poco/Thread_VX.h | 186 +++++++++++++++++++ 8 files changed, 764 insertions(+) create mode 100644 Foundation/include/Poco/Event_VX.h create mode 100644 Foundation/include/Poco/Mutex_VX.h create mode 100644 Foundation/include/Poco/NamedEvent_Android.h create mode 100644 Foundation/include/Poco/NamedMutex_Android.h create mode 100644 Foundation/include/Poco/RWLock_Android.h create mode 100644 Foundation/include/Poco/RWLock_WINCE.h create mode 100644 Foundation/include/Poco/Semaphore_VX.h create mode 100644 Foundation/include/Poco/Thread_VX.h diff --git a/Foundation/include/Poco/Event_VX.h b/Foundation/include/Poco/Event_VX.h new file mode 100644 index 000000000..8ea1e3b57 --- /dev/null +++ b/Foundation/include/Poco/Event_VX.h @@ -0,0 +1,71 @@ +// +// Event_VX.h +// +// $Id: //poco/1.4/Foundation/include/Poco/Event_VX.h#1 $ +// +// Library: Foundation +// Package: Threading +// Module: Event +// +// Definition of the EventImpl class for VxWorks. +// +// 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_Event_VX_INCLUDED +#define Foundation_Event_VX_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { + + +class Foundation_API EventImpl +{ +protected: + EventImpl(bool autoReset); + ~EventImpl(); + void setImpl(); + void waitImpl(); + bool waitImpl(long milliseconds); + void resetImpl(); + +private: + bool _auto; + volatile bool _state; + SEM_ID _sem; +}; + + +} // namespace Poco + + +#endif // Foundation_Event_VX_INCLUDED diff --git a/Foundation/include/Poco/Mutex_VX.h b/Foundation/include/Poco/Mutex_VX.h new file mode 100644 index 000000000..c357f19c4 --- /dev/null +++ b/Foundation/include/Poco/Mutex_VX.h @@ -0,0 +1,102 @@ +// +// Mutex_VX.h +// +// $Id: //poco/1.4/Foundation/include/Poco/Mutex_VX.h#1 $ +// +// Library: Foundation +// Package: Threading +// Module: Mutex +// +// Definition of the MutexImpl and FastMutexImpl classes for VxWorks. +// +// Copyright (c) 2004-2011, 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_Mutex_VX_INCLUDED +#define Foundation_Mutex_VX_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Exception.h" +#include +#include + + +namespace Poco { + + +class Foundation_API MutexImpl +{ +protected: + MutexImpl(); + MutexImpl(bool fast); + ~MutexImpl(); + void lockImpl(); + bool tryLockImpl(); + bool tryLockImpl(long milliseconds); + void unlockImpl(); + +private: + SEM_ID _sem; +}; + + +class Foundation_API FastMutexImpl: public MutexImpl +{ +protected: + FastMutexImpl(); + ~FastMutexImpl(); +}; + + +// +// inlines +// +inline void MutexImpl::lockImpl() +{ + if (semTake(_sem, WAIT_FOREVER) != OK) + throw SystemException("cannot lock mutex"); +} + + +inline bool MutexImpl::tryLockImpl() +{ + return semTake(_sem, NO_WAIT) == OK; +} + + +inline void MutexImpl::unlockImpl() +{ + if (semGive(_sem) != OK) + throw SystemException("cannot unlock mutex"); +} + + +} // namespace Poco + + +#endif // Foundation_Mutex_VX_INCLUDED diff --git a/Foundation/include/Poco/NamedEvent_Android.h b/Foundation/include/Poco/NamedEvent_Android.h new file mode 100644 index 000000000..fd48d6153 --- /dev/null +++ b/Foundation/include/Poco/NamedEvent_Android.h @@ -0,0 +1,62 @@ +// +// NamedEvent_Android.h +// +// $Id: //poco/1.4/Foundation/include/Poco/NamedEvent_Android.h#1 $ +// +// Library: Foundation +// Package: Processes +// Module: NamedEvent +// +// Definition of the NamedEventImpl class for Android. +// +// Copyright (c) 2004-2011, 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_NamedEvent_Android_INCLUDED +#define Foundation_NamedEvent_Android_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +class Foundation_API NamedEventImpl +{ +protected: + NamedEventImpl(const std::string& name); + ~NamedEventImpl(); + void setImpl(); + void waitImpl(); +}; + + +} // namespace Poco + + +#endif // Foundation_NamedEvent_Android_INCLUDED diff --git a/Foundation/include/Poco/NamedMutex_Android.h b/Foundation/include/Poco/NamedMutex_Android.h new file mode 100644 index 000000000..dd98bb567 --- /dev/null +++ b/Foundation/include/Poco/NamedMutex_Android.h @@ -0,0 +1,63 @@ +// +// NamedMutex_Android.h +// +// $Id: //poco/1.4/Foundation/include/Poco/NamedMutex_Android.h#1 $ +// +// Library: Foundation +// Package: Processes +// Module: NamedMutex +// +// Definition of the NamedMutexImpl class for Android. +// +// Copyright (c) 2004-2011, 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_NamedMutex_Android_INCLUDED +#define Foundation_NamedMutex_Android_INCLUDED + + +#include "Poco/Foundation.h" + + +namespace Poco { + + +class Foundation_API NamedMutexImpl +{ +protected: + NamedMutexImpl(const std::string& name); + ~NamedMutexImpl(); + void lockImpl(); + bool tryLockImpl(); + void unlockImpl(); +}; + + +} // namespace Poco + + +#endif // Foundation_NamedMutex_Android_INCLUDED diff --git a/Foundation/include/Poco/RWLock_Android.h b/Foundation/include/Poco/RWLock_Android.h new file mode 100644 index 000000000..40b301ac9 --- /dev/null +++ b/Foundation/include/Poco/RWLock_Android.h @@ -0,0 +1,119 @@ +// +// RWLock_Android.h +// +// $Id: //poco/1.4/Foundation/include/Poco/RWLock_Android.h#1 $ +// +// Library: Foundation +// Package: Threading +// Module: RWLock +// +// Definition of the RWLockImpl class for Android Threads. +// +// Copyright (c) 2004-2011, 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_RWLock_Android_INCLUDED +#define Foundation_RWLock_Android_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Exception.h" +#include +#include + + +namespace Poco { + + +class Foundation_API RWLockImpl +{ +protected: + RWLockImpl(); + ~RWLockImpl(); + void readLockImpl(); + bool tryReadLockImpl(); + void writeLockImpl(); + bool tryWriteLockImpl(); + void unlockImpl(); + +private: + pthread_mutex_t _mutex; +}; + + +// +// inlines +// +inline void RWLockImpl::readLockImpl() +{ + if (pthread_mutex_lock(&_mutex)) + throw SystemException("cannot lock reader/writer lock"); +} + + +inline bool RWLockImpl::tryReadLockImpl() +{ + int rc = pthread_mutex_trylock(&_mutex); + if (rc == 0) + return true; + else if (rc == EBUSY) + return false; + else + throw SystemException("cannot lock reader/writer lock"); +} + + +inline void RWLockImpl::writeLockImpl() +{ + if (pthread_mutex_lock(&_mutex)) + throw SystemException("cannot lock reader/writer lock"); +} + + +inline bool RWLockImpl::tryWriteLockImpl() +{ + int rc = pthread_mutex_trylock(&_mutex); + if (rc == 0) + return true; + else if (rc == EBUSY) + return false; + else + throw SystemException("cannot lock reader/writer lock"); +} + + +inline void RWLockImpl::unlockImpl() +{ + if (pthread_mutex_unlock(&_mutex)) + throw SystemException("cannot unlock reader/writer lock"); +} + + +} // namespace Poco + + +#endif // Foundation_RWLock_Android_INCLUDED diff --git a/Foundation/include/Poco/RWLock_WINCE.h b/Foundation/include/Poco/RWLock_WINCE.h new file mode 100644 index 000000000..eb92ce6f3 --- /dev/null +++ b/Foundation/include/Poco/RWLock_WINCE.h @@ -0,0 +1,83 @@ +// +// RWLock_WINCE.h +// +// $Id: //poco/1.4/Foundation/include/Poco/RWLock_WINCE.h#1 $ +// +// Library: Foundation +// Package: Threading +// Module: RWLock +// +// Definition of the RWLockImpl class for WINCE. +// +// Copyright (c) 2009-2010, 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_RWLock_WINCE_INCLUDED +#define Foundation_RWLock_WINCE_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Exception.h" +#include "Poco/UnWindows.h" + + +namespace Poco { + + +class Foundation_API RWLockImpl + /// This implementation is based on the one from Stone Steps Inc, + /// licensed under the BSD license. + /// http://forums.stonesteps.ca/thread.asp?t=105 + /// + /// Note that with this implementation, writers always take + /// precedence over readers. +{ +protected: + RWLockImpl(); + ~RWLockImpl(); + void readLockImpl(); + bool tryReadLockImpl(DWORD timeout = 1); + void writeLockImpl(); + bool tryWriteLockImpl(DWORD timeout = 1); + void unlockImpl(); + +private: + DWORD _readerCount; + DWORD _readerWaiting; + DWORD _writerCount; + DWORD _writerWaiting; + HANDLE _readerGreen; + HANDLE _writerGreen; + CRITICAL_SECTION _cs; + bool _writeLock; +}; + + +} // namespace Poco + + +#endif // Foundation_RWLock_WINCE_INCLUDED diff --git a/Foundation/include/Poco/Semaphore_VX.h b/Foundation/include/Poco/Semaphore_VX.h new file mode 100644 index 000000000..011660053 --- /dev/null +++ b/Foundation/include/Poco/Semaphore_VX.h @@ -0,0 +1,78 @@ +// +// Semaphore_VX.h +// +// $Id: //poco/1.4/Foundation/include/Poco/Semaphore_VX.h#1 $ +// +// Library: Foundation +// Package: Threading +// Module: Semaphore +// +// Definition of the SemaphoreImpl class for VxWorks. +// +// Copyright (c) 2004-20011, 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_Semaphore_VX_INCLUDED +#define Foundation_Semaphore_VX_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Exception.h" +#include + + +namespace Poco { + + +class Foundation_API SemaphoreImpl +{ +protected: + SemaphoreImpl(int n, int max); + ~SemaphoreImpl(); + void setImpl(); + void waitImpl(); + bool waitImpl(long milliseconds); + +private: + SEM_ID _sem; +}; + + +// +// inlines +// +inline void SemaphoreImpl::setImpl() +{ + if (semGive(_sem) != OK) + throw SystemException("cannot signal semaphore"); +} + + +} // namespace Poco + + +#endif // Foundation_Semaphore_VX_INCLUDED diff --git a/Foundation/include/Poco/Thread_VX.h b/Foundation/include/Poco/Thread_VX.h new file mode 100644 index 000000000..083f7108a --- /dev/null +++ b/Foundation/include/Poco/Thread_VX.h @@ -0,0 +1,186 @@ +// +// Thread_VX.h +// +// $Id: //poco/1.4/Foundation/include/Poco/Thread_VX.h#1 $ +// +// Library: Foundation +// Package: Threading +// Module: Thread +// +// Definition of the ThreadImpl class for VxWorks tasks. +// +// Copyright (c) 2004-2011, 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_Thread_VX_INCLUDED +#define Foundation_Thread_VX_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Runnable.h" +#include "Poco/SignalHandler.h" +#include "Poco/Event.h" +#include "Poco/RefCountedObject.h" +#include "Poco/AutoPtr.h" +#include +#include + + +namespace Poco { + + +class Foundation_API ThreadImpl +{ +public: + typedef int TIDImpl; + typedef void (*Callable)(void*); + + enum Priority + { + PRIO_LOWEST_IMPL, + PRIO_LOW_IMPL, + PRIO_NORMAL_IMPL, + PRIO_HIGH_IMPL, + PRIO_HIGHEST_IMPL + }; + + enum + { + DEFAULT_THREAD_STACK_SIZE = 65536 + }; + + struct CallbackData: public RefCountedObject + { + CallbackData(): callback(0), pData(0) + { + } + + Callable callback; + void* pData; + }; + + ThreadImpl(); + ~ThreadImpl(); + + TIDImpl tidImpl() const; + void setPriorityImpl(int prio); + int getPriorityImpl() const; + void setOSPriorityImpl(int prio); + int getOSPriorityImpl() const; + static int getMinOSPriorityImpl(); + static int getMaxOSPriorityImpl(); + void setStackSizeImpl(int size); + int getStackSizeImpl() const; + void startImpl(Runnable& target); + void startImpl(Callable target, void* pData = 0); + + void joinImpl(); + bool joinImpl(long milliseconds); + bool isRunningImpl() const; + static void sleepImpl(long milliseconds); + static void yieldImpl(); + static ThreadImpl* currentImpl(); + static TIDImpl currentTidImpl(); + +protected: + static void runnableEntry(void* pThread, int, int, int, int, int, int, int, int, int); + static void callableEntry(void* pThread, int, int, int, int, int, int, int, int, int); + static int mapPrio(int prio); + static int reverseMapPrio(int osPrio); + + struct ThreadData: public RefCountedObject + { + ThreadData(): + pRunnableTarget(0), + pCallbackTarget(0), + task(0), + prio(PRIO_NORMAL_IMPL), + osPrio(0), + done(false), + stackSize(POCO_THREAD_STACK_SIZE) + { + } + + Runnable* pRunnableTarget; + AutoPtr pCallbackTarget; + int task; + int prio; + int osPrio; + Event done; + int stackSize; + }; + +private: + AutoPtr _pData; + static ThreadImpl* _pCurrent; +}; + + +// +// inlines +// +inline int ThreadImpl::getPriorityImpl() const +{ + return _pData->prio; +} + + +inline int ThreadImpl::getOSPriorityImpl() const +{ + return _pData->osPrio; +} + + +inline bool ThreadImpl::isRunningImpl() const +{ + return _pData->pRunnableTarget != 0 || + (_pData->pCallbackTarget.get() != 0 && _pData->pCallbackTarget->callback != 0); +} + + +inline void ThreadImpl::yieldImpl() +{ + taskDelay(0); +} + + +inline int ThreadImpl::getStackSizeImpl() const +{ + return _pData->stackSize; +} + + +inline ThreadImpl::TIDImpl ThreadImpl::tidImpl() const +{ + return _pData->task; +} + + +} // namespace Poco + + +#endif // Foundation_Thread_VX_INCLUDED