summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Instance.cpp13
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp2
-rw-r--r--cpp/src/Ice/ThreadPool.cpp35
-rw-r--r--cpp/src/Ice/ThreadPool.h3
4 files changed, 32 insertions, 21 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 5c7f00b2643..3b32c71d510 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -207,8 +207,7 @@ IceInternal::Instance::clientThreadPool()
if(!_clientThreadPool) // Lazy initialization.
{
- int threadNum = _properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Client.Size", 1);
- _clientThreadPool = new ThreadPool(this, threadNum, 0);
+ _clientThreadPool = new ThreadPool(this, "Ice.ThreadPool.Client", 0);
}
return _clientThreadPool;
@@ -223,9 +222,15 @@ IceInternal::Instance::serverThreadPool()
if(!_serverThreadPool) // Lazy initialization.
{
- int threadNum = _properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 10);
+ //
+ // Make sure that the server thread pool default is set
+ // correctly.
+ //
+ _properties->setProperty("Ice.ThreadPool.Server.Size",
+ _properties->getPropertyWithDefault("Ice.ThreadPool.Server.Size", "10"));
+
int timeout = _properties->getPropertyAsInt("Ice.ServerIdleTime");
- _serverThreadPool = new ThreadPool(this, threadNum, timeout);
+ _serverThreadPool = new ThreadPool(this, "Ice.ThreadPool.Server", timeout);
}
return _serverThreadPool;
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index 55ea400b532..4d8f559a058 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -612,7 +612,7 @@ Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const Communica
int threadNum = _instance->properties()->getPropertyAsInt(_name + ".ThreadPool.Size");
if(threadNum > 0)
{
- _threadPool = new ThreadPool(_instance, threadNum, 0);
+ _threadPool = new ThreadPool(_instance, _name + ".ThreadPool", 0);
}
}
catch(...)
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp
index 18d87f54159..78739923f8b 100644
--- a/cpp/src/Ice/ThreadPool.cpp
+++ b/cpp/src/Ice/ThreadPool.cpp
@@ -34,8 +34,7 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& p
_instance(instance),
_destroyed(false),
_lastFd(INVALID_SOCKET),
- _timeout(timeout),
- _multipleThreads(false)
+ _timeout(timeout)
{
SOCKET fds[2];
createPipe(fds);
@@ -48,23 +47,28 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& p
_maxFd = _fdIntrRead;
_minFd = _fdIntrRead;
- int threadNum = _instance->properties()->getPropertyAsInt(prefix + ".Size");
-
- if(threadNum < 1)
+ int size = _instance->properties()->getPropertyAsInt(prefix + ".Size");
+ if(size < 1)
{
- threadNum = 1;
+ size = 1;
_instance->properties()->setProperty(prefix + ".Size", "1");
}
+ const_cast<int&>(_size) = size;
- if(threadNum > 1)
+ int sizeMax = _instance->properties()->getPropertyAsIntWithDefault(prefix + ".SizeMax", _size * 5);
+ if(sizeMax < _size)
{
- _multipleThreads = true;
+ sizeMax = _size;
+ ostringstream str;
+ str << sizeMax;
+ _instance->properties()->setProperty(prefix + ".SizeMax", str.str());
}
+ const_cast<int&>(_sizeMax) = sizeMax;
__setNoDelete(true);
try
{
- for(int i = 0 ; i < threadNum ; ++i)
+ for(int i = 0 ; i < _size ; ++i)
{
IceUtil::ThreadPtr thread = new EventHandlerThread(this);
_threads.push_back(thread->start());
@@ -129,7 +133,7 @@ IceInternal::ThreadPool::unregister(SOCKET fd)
void
IceInternal::ThreadPool::promoteFollower()
{
- if(_multipleThreads)
+ if(_size > 1)
{
_threadMutex.unlock();
}
@@ -149,11 +153,12 @@ void
IceInternal::ThreadPool::joinWithAllThreads()
{
//
- // _threads is immutable after the initial creation in the
- // constructor, therefore no synchronization is
- // needed. (Synchronization wouldn't be possible here anyway,
- // because otherwise the other threads would never terminate.)
+ // _threads is immutable after destroy() has been called,
+ // therefore no synchronization is needed. (Synchronization
+ // wouldn't be possible here anyway, because otherwise the other
+ // threads would never terminate.)
//
+ assert(_destroyed);
for(vector<IceUtil::ThreadControl>::iterator p = _threads.begin(); p != _threads.end(); ++p)
{
p->join();
@@ -235,7 +240,7 @@ IceInternal::ThreadPool::run()
while(true)
{
- if(_multipleThreads)
+ if(_size > 1)
{
_threadMutex.lock();
}
diff --git a/cpp/src/Ice/ThreadPool.h b/cpp/src/Ice/ThreadPool.h
index d7c9ae1c5e9..626c56cb1e1 100644
--- a/cpp/src/Ice/ThreadPool.h
+++ b/cpp/src/Ice/ThreadPool.h
@@ -60,6 +60,8 @@ private:
InstancePtr _instance;
bool _destroyed;
+ const int _size;
+ const int _sizeMax;
SOCKET _maxFd;
SOCKET _minFd;
SOCKET _lastFd;
@@ -70,7 +72,6 @@ private:
std::map<SOCKET, EventHandlerPtr> _handlerMap;
int _timeout;
::IceUtil::Mutex _threadMutex;
- bool _multipleThreads;
class EventHandlerThread : public ::IceUtil::Thread
{