@@ -68,8 +68,8 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
6868 }
6969 }
7070
71- void open_connections (std::size_t num) {
72- boost::container::small_vector<std::future<ConType>, size_hint> futures;
71+ void open_connections (std::size_t num) {
72+ boost::container::small_vector<std::future<std::unique_ptr< ConType> >, size_hint> futures;
7373 futures.reserve (num);
7474
7575 for (std::size_t i = 0 ; i < num; ++i) {
@@ -106,7 +106,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
106106 if (!cd.error && !cd.sweep && !cd.empty_slot ) {
107107 if (cd.dirty && !return_clean ()) {
108108 try {
109- if (driver_.clean (cd.conn )) {
109+ if (driver_.clean (* cd.conn )) {
110110 cd.dirty = false ;
111111 } else {
112112 cd.sweep = true ;
@@ -116,6 +116,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
116116 if (log_cb_) {
117117 log_cb_ (Severity::DEBUG, " On connection clean: " s + e.what ());
118118 }
119+
119120 return false ;
120121 }
121122 }
@@ -128,9 +129,8 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
128129
129130 return false ;
130131 }
131-
132+
132133 std::optional<Connection<ConType>> get_connection () {
133- driver_.thread_enter ();
134134
135135#ifdef DEBUG_NO_THREADS
136136 manager_.run ();
@@ -149,7 +149,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
149149 res = std::ranges::find_if (pool_, [&](auto & arg) {
150150 return find_free_connection (arg);
151151 });
152-
152+
153153 if (res == pool_.end ()) {
154154 return std::nullopt ;
155155 }
@@ -161,19 +161,18 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
161161 this ->return_connection (arg);
162162 }, *res);
163163 }
164-
164+
165165public:
166166 Pool (Driver& driver, std::size_t min_size, std::size_t max_size,
167167 sc::seconds max_idle, sc::seconds interval = 15s)
168168 : driver_(driver),
169169 min_ (min_size),
170- max_(max_size),
170+ max_(max_size),
171171 manager_(this , interval, max_idle),
172172 pool_(max_size),
173173 pool_guards_(max_size),
174174 size_(0 ),
175175 closed_(false ) {
176- driver_.thread_enter ();
177176
178177 if (!max_size) {
179178 throw exception (" Max. database connections cannot be zero" );
@@ -203,15 +202,14 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
203202 BOOST_ASSERT_MSG (!c.checked_out , " Closed connection pool without returning all connections." );
204203
205204 try {
206- driver_.close (c.conn );
207- } catch (const std::exception& e) {
205+ driver_.close (std::move ( c.conn ) );
206+ } catch (const std::exception& e) {
208207 if (log_cb_) {
209208 log_cb_ (Severity::ERROR, " Closing pool, driver threw: " s + e.what ());
210209 }
211210 }
212211 }
213212
214- driver_.thread_exit ();
215213 }
216214
217215 void close () {
@@ -234,7 +232,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
234232 continue ;
235233 }
236234
237- driver_.close (c.conn );
235+ driver_.close (std::move ( c.conn ) );
238236 }
239237
240238 if (active) {
@@ -260,7 +258,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
260258 */
261259 Connection<ConType> acquire () {
262260 std::optional<Connection<ConType>> conn;
263-
261+
264262 while (!(conn = get_connection ())) {
265263 semaphore_.acquire ();
266264 }
@@ -283,7 +281,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
283281 while (!(conn = get_connection ())) {
284282 sc::milliseconds elapsed = sc::duration_cast<sc::milliseconds>
285283 (sc::high_resolution_clock::now () - start);
286-
284+
287285 if (elapsed >= duration) {
288286 throw no_free_connections ();
289287 }
@@ -301,7 +299,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
301299 auto & detail = connection.detail_ .get ();
302300
303301 if (return_clean ()) {
304- if (!driver_.clean (detail.conn )) {
302+ if (!driver_.clean (* detail.conn )) {
305303 detail.dirty = true ;
306304 detail.sweep = true ;
307305 }
@@ -314,7 +312,6 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
314312 std::atomic_thread_fence (std::memory_order_release);
315313 pool_guards_[detail.id ].store (false , std::memory_order_relaxed);
316314
317- driver_.thread_exit ();
318315 manager_.check_exceptions ();
319316 semaphore_.release ();
320317 }
@@ -340,4 +337,4 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
340337 }
341338};
342339
343- } // connection_pool, ember
340+ } // connection_pool, ember
0 commit comments