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
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/Thread.h#2 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/Thread.h#7 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// ThreadPool.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ThreadPool.h#2 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/ThreadPool.h#5 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@@ -179,8 +179,9 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
|
||||
//
|
||||
inline void ThreadPool::setStackSize(int stackSize)
|
||||
{
|
||||
_stackSize = stackSize;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// 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
|
||||
// Package: Threading
|
||||
@@ -108,6 +108,31 @@ protected:
|
||||
static int reverseMapPrio(int osPrio);
|
||||
|
||||
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
|
||||
{
|
||||
ThreadData():
|
||||
@@ -131,8 +156,7 @@ private:
|
||||
|
||||
AutoPtr<ThreadData> _pData;
|
||||
|
||||
static pthread_key_t _currentKey;
|
||||
static bool _haveCurrentKey;
|
||||
static CurrentThreadHolder _currentThreadHolder;
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
SignalHandler::JumpBufferVec _jumpBufferVec;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// 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
|
||||
// Package: Threading
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
@@ -116,13 +116,38 @@ protected:
|
||||
void threadCleanup();
|
||||
|
||||
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;
|
||||
CallbackData _callbackTarget;
|
||||
HANDLE _thread;
|
||||
int _prio;
|
||||
int _stackSize;
|
||||
|
||||
static DWORD _currentKey;
|
||||
static CurrentThreadHolder _currentThreadHolder;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Environment_WIN32.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Environment_WIN32.cpp#4 $
|
||||
// $Id: //poco/Main/Foundation/src/Environment_WIN32.cpp#15 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "Poco/Environment_WIN32.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include "Poco/UnWindows.h"
|
||||
#include <iphlpapi.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Thread.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Thread.cpp#2 $
|
||||
// $Id: //poco/Main/Foundation/src/Thread.cpp#16 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Thread_POSIX.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Foundation/src/Thread_POSIX.cpp#6 $
|
||||
// $Id: //poco/Main/Foundation/src/Thread_POSIX.cpp#20 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@@ -75,19 +75,12 @@ namespace
|
||||
namespace Poco {
|
||||
|
||||
|
||||
pthread_key_t ThreadImpl::_currentKey;
|
||||
bool ThreadImpl::_haveCurrentKey = false;
|
||||
ThreadImpl::CurrentThreadHolder ThreadImpl::_currentThreadHolder;
|
||||
|
||||
|
||||
ThreadImpl::ThreadImpl():
|
||||
_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()
|
||||
{
|
||||
if (_haveCurrentKey)
|
||||
return reinterpret_cast<ThreadImpl*>(pthread_getspecific(_currentKey));
|
||||
else
|
||||
return 0;
|
||||
return _currentThreadHolder.get();
|
||||
}
|
||||
|
||||
|
||||
void* ThreadImpl::runnableEntry(void* pThread)
|
||||
{
|
||||
pthread_setspecific(_currentKey, pThread);
|
||||
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
sigset_t sset;
|
||||
@@ -310,7 +300,7 @@ void* ThreadImpl::runnableEntry(void* pThread)
|
||||
|
||||
void* ThreadImpl::callableEntry(void* pThread)
|
||||
{
|
||||
pthread_setspecific(_currentKey, pThread);
|
||||
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
sigset_t sset;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Thread_WIN32.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Thread_WIN32.cpp#2 $
|
||||
// $Id: //poco/Main/Foundation/src/Thread_WIN32.cpp#17 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Threading
|
||||
@@ -43,7 +43,7 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
DWORD ThreadImpl::_currentKey = TLS_OUT_OF_INDEXES;
|
||||
ThreadImpl::CurrentThreadHolder ThreadImpl::_currentThreadHolder;
|
||||
|
||||
|
||||
ThreadImpl::ThreadImpl():
|
||||
@@ -52,12 +52,6 @@ ThreadImpl::ThreadImpl():
|
||||
_prio(PRIO_NORMAL_IMPL),
|
||||
_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()
|
||||
{
|
||||
if (_currentKey == TLS_OUT_OF_INDEXES)
|
||||
return 0;
|
||||
else
|
||||
return (ThreadImpl*) TlsGetValue(_currentKey);
|
||||
return _currentThreadHolder.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +182,7 @@ DWORD WINAPI ThreadImpl::runnableEntry(LPVOID pThread)
|
||||
unsigned __stdcall ThreadImpl::runnableEntry(void* pThread)
|
||||
#endif
|
||||
{
|
||||
TlsSetValue(_currentKey, pThread);
|
||||
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||
try
|
||||
{
|
||||
reinterpret_cast<ThreadImpl*>(pThread)->_pRunnableTarget->run();
|
||||
@@ -218,7 +209,7 @@ DWORD WINAPI ThreadImpl::callableEntry(LPVOID pThread)
|
||||
unsigned __stdcall ThreadImpl::callableEntry(void* pThread)
|
||||
#endif
|
||||
{
|
||||
TlsSetValue(_currentKey, pThread);
|
||||
_currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));
|
||||
try
|
||||
{
|
||||
ThreadImpl* pTI = reinterpret_cast<ThreadImpl*>(pThread);
|
||||
|
||||
Reference in New Issue
Block a user