This commit is contained in:
kssenii 2021-03-19 16:07:53 +00:00
parent a0f717619c
commit f374a71165
2 changed files with 6 additions and 7 deletions

View File

@ -49,18 +49,17 @@ class PostgreSQLConnectionHolder
{
using Pool = ConcurrentBoundedQueue<PostgreSQLConnectionPtr>;
using PoolPtr = std::shared_ptr<Pool>;
public:
PostgreSQLConnectionHolder(PostgreSQLConnectionPtr connection_, PoolPtr pool_)
PostgreSQLConnectionHolder(PostgreSQLConnectionPtr connection_, Pool & pool_)
: connection(std::move(connection_))
, pool(std::move(pool_))
, pool(pool_)
{
}
PostgreSQLConnectionHolder(const PostgreSQLConnectionHolder & other) = delete;
~PostgreSQLConnectionHolder() { pool->tryPush(connection); }
~PostgreSQLConnectionHolder() { pool.tryPush(connection); }
pqxx::connection & conn() const { return *connection->get(); }
@ -68,7 +67,7 @@ public:
private:
PostgreSQLConnectionPtr connection;
PoolPtr pool;
Pool & pool;
};
using PostgreSQLConnectionHolderPtr = std::shared_ptr<PostgreSQLConnectionHolder>;

View File

@ -48,11 +48,11 @@ PostgreSQLConnectionHolderPtr PostgreSQLConnectionPool::get()
PostgreSQLConnectionPtr connection;
if (pool->tryPop(connection, POSTGRESQL_POOL_WAIT_MS))
{
return std::make_shared<PostgreSQLConnectionHolder>(connection, pool);
return std::make_shared<PostgreSQLConnectionHolder>(connection, *pool);
}
connection = std::make_shared<PostgreSQLConnection>(connection_str, address);
return std::make_shared<PostgreSQLConnectionHolder>(connection, pool);
return std::make_shared<PostgreSQLConnectionHolder>(connection, *pool);
}