From 1e78bdc724e95898c04a3409b0b192aa7f77780b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 15 Oct 2012 13:17:30 +0200 Subject: Implement early connection release --- odb/connection.cxx | 55 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'odb/connection.cxx') diff --git a/odb/connection.cxx b/odb/connection.cxx index f479131..2686887 100644 --- a/odb/connection.cxx +++ b/odb/connection.cxx @@ -4,6 +4,8 @@ #include #include +#include +#include #include // prepared_* using namespace std; @@ -13,16 +15,45 @@ namespace odb connection:: ~connection () { + assert (prepared_queries_ == 0); + assert (prepared_map_.empty ()); + } + + void connection:: + clear_prepared_map () + { for (prepared_map_type::iterator i (prepared_map_.begin ()), e (prepared_map_.end ()); i != e; ++i) { if (i->second.params != 0) i->second.params_deleter (i->second.params); } + + prepared_map_.clear (); + } + + void connection:: + recycle () + { + while (prepared_queries_ != 0) + { + prepared_queries_->stmt.reset (); + prepared_queries_->list_remove (); + } } void connection:: - cache_query_ (details::shared_ptr pq, + invalidate_results () + { + while (results_ != 0) + { + results_->invalidate (); + results_->list_remove (); + } + } + + void connection:: + cache_query_ (prepared_query_impl* pq, const type_info& ti, void* params, const type_info* params_info, @@ -37,19 +68,25 @@ namespace odb prepared_entry_type& e (r.first->second); - e.prep_query = pq; - e.type_info = &ti; - - // Mark the statement as cached. + // Mark this prepared query as cached , get its ref count to 1 + // (prepared_query instances now reference this impl object), + // and remove it from the invalidation list. // - pq->stmt->cached (true); + pq->cached = true; + + while (pq->_ref_count () > 1) + pq->_dec_ref (); + pq->list_remove (); + + e.prep_query.reset (pq); + e.type_info = &ti; e.params = params; e.params_info = params_info; e.params_deleter = params_deleter; } - details::shared_ptr connection:: + prepared_query_impl* connection:: lookup_query_ (const char* name, const type_info& ti, void** params, @@ -72,7 +109,7 @@ namespace odb } if (i == prepared_map_.end ()) - return details::shared_ptr (); + return 0; // Make sure the types match. // @@ -87,6 +124,6 @@ namespace odb *params = i->second.params; } - return i->second.prep_query; + return i->second.prep_query.get (); } } -- cgit v1.1