- POCO_THREAD_STACK_SIZE macro

- few Thread modifications
- ThreadPool configurable stack size
This commit is contained in:
Aleksandar Fabijanic
2008-04-20 23:28:41 +00:00
parent 537ec8aca3
commit 9fd70bade2
11 changed files with 90 additions and 40 deletions

View File

@@ -60,4 +60,9 @@
// #define POCO_NO_SHAREDMEMORY
// Define to desired default thread stack size
// Zero means OS default
#define POCO_THREAD_STACK_SIZE 0
#endif // Foundation_Config_INCLUDED

View File

@@ -51,7 +51,7 @@ class Foundation_API Runnable
/// must be implemented by classes that provide
/// an entry point for a thread.
{
public:
public:
Runnable();
virtual ~Runnable();

View File

@@ -127,13 +127,13 @@ public:
/// Returns the maximum operating system-specific priority value,
/// which can be passed to setOSPriority().
void setStackSize(std::size_t size);
void setStackSize(int size);
/// Sets the thread's stack size in bytes.
/// Setting the stack size to 0 will use the default stack size.
/// Typically, the real stack size is rounded up to the nearest
/// page size multiple.
std::size_t getStackSize() const;
int getStackSize() const;
/// Returns the thread's stack size in bytes.
/// If the default stack size is used, 0 is returned.
@@ -272,13 +272,13 @@ inline int Thread::getMaxOSPriority()
}
inline void Thread::setStackSize(std::size_t size)
inline void Thread::setStackSize(int size)
{
setStackSizeImpl(size);
}
inline std::size_t Thread::getStackSize() const
inline int Thread::getStackSize() const
{
return getStackSizeImpl();
}

View File

@@ -89,6 +89,13 @@ public:
int capacity() const;
/// Returns the maximum capacity of threads.
void setStackSize(int stackSize);
/// Sets the stack size for threads.
/// New stack size applies only for newly created threads.
int getStackSize() const;
/// Returns the stack size used to create new threads.
int used() const;
/// Returns the number of currently used threads.
@@ -159,11 +166,26 @@ private:
int _idleTime;
int _serial;
int _age;
int _stackSize;
ThreadVec _threads;
mutable FastMutex _mutex;
};
// inlines
inline void ThreadPool::setStackSize(int stackSize)
{
_stackSize = stackSize;
}
inline int ThreadPool::getStackSize() const
{
return _stackSize;
}
} // namespace Poco

View File

@@ -89,8 +89,8 @@ public:
int getOSPriorityImpl() const;
static int getMinOSPriorityImpl();
static int getMaxOSPriorityImpl();
void setStackSizeImpl(std::size_t size);
std::size_t getStackSizeImpl() const;
void setStackSizeImpl(int size);
int getStackSizeImpl() const;
void startImpl(Runnable& target);
void startImpl(Callback target, void* pData = 0);
@@ -116,7 +116,7 @@ private:
thread(0),
prio(PRIO_NORMAL_IMPL),
done(false),
stackSize(0)
stackSize(POCO_THREAD_STACK_SIZE)
{
}
@@ -186,13 +186,7 @@ inline void ThreadImpl::yieldImpl()
}
inline void ThreadImpl::setStackSizeImpl(std::size_t size)
{
_pData->stackSize = size;
}
inline std::size_t ThreadImpl::getStackSizeImpl() const
inline int ThreadImpl::getStackSizeImpl() const
{
return _pData->stackSize;
}

View File

@@ -87,8 +87,8 @@ public:
int getOSPriorityImpl() const;
static int getMinOSPriorityImpl();
static int getMaxOSPriorityImpl();
void setStackSizeImpl(std::size_t size);
std::size_t getStackSizeImpl() const;
void setStackSizeImpl(int size);
int getStackSizeImpl() const;
void startImpl(Runnable& target);
void startImpl(Callback target, void* pData = 0);
@@ -120,7 +120,7 @@ private:
CallbackData _callbackTarget;
HANDLE _thread;
int _prio;
std::size_t _stackSize;
int _stackSize;
static DWORD _currentKey;
};
@@ -165,13 +165,13 @@ inline void ThreadImpl::yieldImpl()
}
inline void ThreadImpl::setStackSizeImpl(std::size_t size)
inline void ThreadImpl::setStackSizeImpl(int size)
{
_stackSize = size;
}
inline std::size_t ThreadImpl::getStackSizeImpl() const
inline int ThreadImpl::getStackSizeImpl() const
{
return _stackSize;
}