Use unique_ptr<> for connection_pool::pimpl_

Also don't duplicate connection_pool ctor and dtor in POSIX and Windows
branches as they are exactly the same for both of them.

No real changes.
This commit is contained in:
Vadim Zeitlin
2025-09-20 16:27:43 +02:00
parent 430a508702
commit e1b841f5bd
2 changed files with 9 additions and 21 deletions

View File

@@ -11,6 +11,7 @@
#include "soci/soci-platform.h"
// std
#include <cstddef>
#include <memory>
namespace soci
{
@@ -31,7 +32,7 @@ public:
private:
struct connection_pool_impl;
connection_pool_impl * pimpl_;
std::unique_ptr<connection_pool_impl> pimpl_;
SOCI_NOT_COPYABLE(connection_pool)
};

View File

@@ -98,16 +98,6 @@ struct connection_pool::connection_pool_impl : connection_pool_base_impl
pthread_cond_t cond_;
};
connection_pool::connection_pool(std::size_t size)
{
pimpl_ = new connection_pool_impl(size);
}
connection_pool::~connection_pool()
{
delete pimpl_;
}
bool connection_pool::try_lease(std::size_t & pos, int timeout)
{
struct timespec tm;
@@ -242,16 +232,6 @@ struct connection_pool::connection_pool_impl : connection_pool_base_impl
HANDLE sem_;
};
connection_pool::connection_pool(std::size_t size)
{
pimpl_ = new connection_pool_impl(size);
}
connection_pool::~connection_pool()
{
delete pimpl_;
}
bool connection_pool::try_lease(std::size_t & pos, int timeout)
{
DWORD cc = WaitForSingleObject(pimpl_->sem_,
@@ -308,6 +288,13 @@ void connection_pool::give_back(std::size_t pos)
#endif // _WIN32
connection_pool::connection_pool(std::size_t size)
: pimpl_(std::make_unique<connection_pool_impl>(size))
{
}
connection_pool::~connection_pool() = default;
session & connection_pool::at(std::size_t pos)
{
if (pos >= pimpl_->sessions_.size())