SessionPoolContainer: added getPool() and FastMutex locking

This commit is contained in:
Aleksandar Fabijanic
2009-05-12 20:04:27 +00:00
parent 6fa5bcf09f
commit 0bd881fd5e
2 changed files with 21 additions and 3 deletions

View File

@@ -43,6 +43,9 @@
#include <algorithm>
using Poco::FastMutex;
namespace Poco {
namespace Data {
@@ -59,6 +62,7 @@ SessionPoolContainer::~SessionPoolContainer()
void SessionPoolContainer::add(SessionPool* pPool)
{
FastMutex::ScopedLock lock(_mutex);
poco_check_ptr (pPool);
if (_sessionPools.find(pPool->name()) != _sessionPools.end())
@@ -75,6 +79,7 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
int maxSessions,
int idleTime)
{
FastMutex::ScopedLock lock(_mutex);
std::string name = SessionPool::name(sessionKey, connectionString);
SessionPoolMap::Iterator it = _sessionPools.find(name);
@@ -92,6 +97,12 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
Session SessionPoolContainer::get(const std::string& name)
{
return getPool(name).get();
}
SessionPool& SessionPoolContainer::getPool(const std::string& name)
{
URI uri(name);
std::string path = uri.getPath();
@@ -99,7 +110,7 @@ Session SessionPoolContainer::get(const std::string& name)
std::string n = Session::uri(uri.getScheme(), path.substr(1));
SessionPoolMap::Iterator it = _sessionPools.find(n);
if (_sessionPools.end() == it) throw NotFoundException(n);
return it->second->get();
return *it->second;
}