mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
integrated fixed from 1.3.4
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread.h
|
// Thread.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Thread.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/Thread.h#7 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// ThreadPool.h
|
// ThreadPool.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/ThreadPool.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/ThreadPool.h#5 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -179,8 +179,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
// inlines
|
// inlines
|
||||||
|
//
|
||||||
inline void ThreadPool::setStackSize(int stackSize)
|
inline void ThreadPool::setStackSize(int stackSize)
|
||||||
{
|
{
|
||||||
_stackSize = stackSize;
|
_stackSize = stackSize;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread_POSIX.h
|
// Thread_POSIX.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Thread_POSIX.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/Thread_POSIX.h#8 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -108,6 +108,31 @@ protected:
|
|||||||
static int reverseMapPrio(int osPrio);
|
static int reverseMapPrio(int osPrio);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class CurrentThreadHolder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CurrentThreadHolder()
|
||||||
|
{
|
||||||
|
if (pthread_key_create(&_key, NULL))
|
||||||
|
throw SystemException("cannot allocate thread context key");
|
||||||
|
}
|
||||||
|
~CurrentThreadHolder()
|
||||||
|
{
|
||||||
|
pthread_key_delete(_key);
|
||||||
|
}
|
||||||
|
ThreadImpl* get() const
|
||||||
|
{
|
||||||
|
return reinterpret_cast<ThreadImpl*>(pthread_getspecific(_key));
|
||||||
|
}
|
||||||
|
void set(ThreadImpl* pThread)
|
||||||
|
{
|
||||||
|
pthread_setspecific(_key, pThread);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
pthread_key_t _key;
|
||||||
|
};
|
||||||
|
|
||||||
struct ThreadData: public RefCountedObject
|
struct ThreadData: public RefCountedObject
|
||||||
{
|
{
|
||||||
ThreadData():
|
ThreadData():
|
||||||
@@ -131,8 +156,7 @@ private:
|
|||||||
|
|
||||||
AutoPtr<ThreadData> _pData;
|
AutoPtr<ThreadData> _pData;
|
||||||
|
|
||||||
static pthread_key_t _currentKey;
|
static CurrentThreadHolder _currentThreadHolder;
|
||||||
static bool _haveCurrentKey;
|
|
||||||
|
|
||||||
#if defined(POCO_OS_FAMILY_UNIX)
|
#if defined(POCO_OS_FAMILY_UNIX)
|
||||||
SignalHandler::JumpBufferVec _jumpBufferVec;
|
SignalHandler::JumpBufferVec _jumpBufferVec;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread_WIN32.h
|
// Thread_WIN32.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/include/Poco/Thread_WIN32.h#2 $
|
// $Id: //poco/Main/Foundation/include/Poco/Thread_WIN32.h#8 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//
|
//
|
||||||
// Definition of the ThreadImpl class for WIN32.
|
// Definition of the ThreadImpl class for WIN32.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2009, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
@@ -116,13 +116,38 @@ protected:
|
|||||||
void threadCleanup();
|
void threadCleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class CurrentThreadHolder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CurrentThreadHolder(): _slot(TlsAlloc())
|
||||||
|
{
|
||||||
|
if (_slot == TLS_OUT_OF_INDEXES)
|
||||||
|
throw SystemException("cannot allocate thread context key");
|
||||||
|
}
|
||||||
|
~CurrentThreadHolder()
|
||||||
|
{
|
||||||
|
TlsFree(_slot);
|
||||||
|
}
|
||||||
|
ThreadImpl* get() const
|
||||||
|
{
|
||||||
|
return reinterpret_cast<ThreadImpl*>(TlsGetValue(_slot));
|
||||||
|
}
|
||||||
|
void set(ThreadImpl* pThread)
|
||||||
|
{
|
||||||
|
TlsSetValue(_slot, pThread);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DWORD _slot;
|
||||||
|
};
|
||||||
|
|
||||||
Runnable* _pRunnableTarget;
|
Runnable* _pRunnableTarget;
|
||||||
CallbackData _callbackTarget;
|
CallbackData _callbackTarget;
|
||||||
HANDLE _thread;
|
HANDLE _thread;
|
||||||
int _prio;
|
int _prio;
|
||||||
int _stackSize;
|
int _stackSize;
|
||||||
|
|
||||||
static DWORD _currentKey;
|
static CurrentThreadHolder _currentThreadHolder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Environment_WIN32.cpp
|
// Environment_WIN32.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Foundation/src/Environment_WIN32.cpp#4 $
|
// $Id: //poco/Main/Foundation/src/Environment_WIN32.cpp#15 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Core
|
// Package: Core
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "Poco/Environment_WIN32.h"
|
#include "Poco/Environment_WIN32.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstring>
|
||||||
#include "Poco/UnWindows.h"
|
#include "Poco/UnWindows.h"
|
||||||
#include <iphlpapi.h>
|
#include <iphlpapi.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread.cpp
|
// Thread.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/Thread.cpp#2 $
|
// $Id: //poco/Main/Foundation/src/Thread.cpp#16 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread_POSIX.cpp
|
// Thread_POSIX.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Foundation/src/Thread_POSIX.cpp#6 $
|
// $Id: //poco/Main/Foundation/src/Thread_POSIX.cpp#20 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -75,19 +75,12 @@ namespace
|
|||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
pthread_key_t ThreadImpl::_currentKey;
|
ThreadImpl::CurrentThreadHolder ThreadImpl::_currentThreadHolder;
|
||||||
bool ThreadImpl::_haveCurrentKey = false;
|
|
||||||
|
|
||||||
|
|
||||||
ThreadImpl::ThreadImpl():
|
ThreadImpl::ThreadImpl():
|
||||||
_pData(new ThreadData)
|
_pData(new ThreadData)
|
||||||
{
|
{
|
||||||
if (!_haveCurrentKey)
|
|
||||||
{
|
|
||||||
if (pthread_key_create(&_currentKey, NULL))
|
|
||||||
throw SystemException("cannot allocate thread context key");
|
|
||||||
_haveCurrentKey = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -263,16 +256,13 @@ bool ThreadImpl::joinImpl(long milliseconds)
|
|||||||
|
|
||||||
ThreadImpl* ThreadImpl::currentImpl()
|
ThreadImpl* ThreadImpl::currentImpl()
|
||||||
{
|
{
|
||||||
if (_haveCurrentKey)
|
return _currentThreadHolder.get();
|
||||||
return reinterpret_cast<ThreadImpl*>(pthread_getspecific(_currentKey));
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* ThreadImpl::runnableEntry(void* pThread)
|
void* ThreadImpl::runnableEntry(void* pThread)
|
||||||
{
|
{
|
||||||
pthread_setspecific(_currentKey, pThread);
|
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||||
|
|
||||||
#if defined(POCO_OS_FAMILY_UNIX)
|
#if defined(POCO_OS_FAMILY_UNIX)
|
||||||
sigset_t sset;
|
sigset_t sset;
|
||||||
@@ -310,7 +300,7 @@ void* ThreadImpl::runnableEntry(void* pThread)
|
|||||||
|
|
||||||
void* ThreadImpl::callableEntry(void* pThread)
|
void* ThreadImpl::callableEntry(void* pThread)
|
||||||
{
|
{
|
||||||
pthread_setspecific(_currentKey, pThread);
|
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||||
|
|
||||||
#if defined(POCO_OS_FAMILY_UNIX)
|
#if defined(POCO_OS_FAMILY_UNIX)
|
||||||
sigset_t sset;
|
sigset_t sset;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// Thread_WIN32.h
|
// Thread_WIN32.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/svn/Foundation/src/Thread_WIN32.cpp#2 $
|
// $Id: //poco/Main/Foundation/src/Thread_WIN32.cpp#17 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Threading
|
// Package: Threading
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
namespace Poco {
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
DWORD ThreadImpl::_currentKey = TLS_OUT_OF_INDEXES;
|
ThreadImpl::CurrentThreadHolder ThreadImpl::_currentThreadHolder;
|
||||||
|
|
||||||
|
|
||||||
ThreadImpl::ThreadImpl():
|
ThreadImpl::ThreadImpl():
|
||||||
@@ -52,12 +52,6 @@ ThreadImpl::ThreadImpl():
|
|||||||
_prio(PRIO_NORMAL_IMPL),
|
_prio(PRIO_NORMAL_IMPL),
|
||||||
_stackSize(POCO_THREAD_STACK_SIZE)
|
_stackSize(POCO_THREAD_STACK_SIZE)
|
||||||
{
|
{
|
||||||
if (_currentKey == TLS_OUT_OF_INDEXES)
|
|
||||||
{
|
|
||||||
_currentKey = TlsAlloc();
|
|
||||||
if (_currentKey == TLS_OUT_OF_INDEXES)
|
|
||||||
throw SystemException("cannot allocate thread context key");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,10 +172,7 @@ void ThreadImpl::threadCleanup()
|
|||||||
|
|
||||||
ThreadImpl* ThreadImpl::currentImpl()
|
ThreadImpl* ThreadImpl::currentImpl()
|
||||||
{
|
{
|
||||||
if (_currentKey == TLS_OUT_OF_INDEXES)
|
return _currentThreadHolder.get();
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return (ThreadImpl*) TlsGetValue(_currentKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -191,7 +182,7 @@ DWORD WINAPI ThreadImpl::runnableEntry(LPVOID pThread)
|
|||||||
unsigned __stdcall ThreadImpl::runnableEntry(void* pThread)
|
unsigned __stdcall ThreadImpl::runnableEntry(void* pThread)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
TlsSetValue(_currentKey, pThread);
|
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
reinterpret_cast<ThreadImpl*>(pThread)->_pRunnableTarget->run();
|
reinterpret_cast<ThreadImpl*>(pThread)->_pRunnableTarget->run();
|
||||||
@@ -218,7 +209,7 @@ DWORD WINAPI ThreadImpl::callableEntry(LPVOID pThread)
|
|||||||
unsigned __stdcall ThreadImpl::callableEntry(void* pThread)
|
unsigned __stdcall ThreadImpl::callableEntry(void* pThread)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
TlsSetValue(_currentKey, pThread);
|
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ThreadImpl* pTI = reinterpret_cast<ThreadImpl*>(pThread);
|
ThreadImpl* pTI = reinterpret_cast<ThreadImpl*>(pThread);
|
||||||
|
|||||||
Reference in New Issue
Block a user