--- parser3/src/main/pa_sql_driver_manager.C 2003/01/27 16:19:11 1.69.2.2 +++ parser3/src/main/pa_sql_driver_manager.C 2003/03/17 14:48:06 1.69.4.1 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_SQL_DRIVER_MANAGER_C="$Date: 2003/01/27 16:19:11 $"; +static const char* IDENT_SQL_DRIVER_MANAGER_C="$Date: 2003/03/17 14:48:06 $"; #include "pa_sql_driver_manager.h" #include "ltdl.h" @@ -13,12 +13,13 @@ static const char* IDENT_SQL_DRIVER_MANA #include "pa_exception.h" #include "pa_common.h" #include "pa_threads.h" +#include "pa_stack.h" #include "pa_vhash.h" #include "pa_vtable.h" // globals -SQL_Driver_manager SQL_driver_manager; +SQL_Driver_manager *SQL_driver_manager; // consts @@ -27,7 +28,7 @@ const int CHECK_EXPIRED_CONNECTIONS_SECO // helpers -ConstStringPtr url_without_login(Pool& pool, ConstStringPtr url) { +const String& url_without_login(Pool& pool, const String& url) { String& result=*new(pool) String(pool); result << url.mid(0, url.pos(":")) << "://****"; @@ -41,11 +42,11 @@ ConstStringPtr url_without_login(Pool& p /// SQL_Driver_services Pooled implementation class SQL_Driver_services_impl : public SQL_Driver_services, public Pooled { public: - SQL_Driver_services_impl(Pool& apool, ConstStringPtr aurl) : Pooled(apool), + SQL_Driver_services_impl(Pool& apool, const String& aurl) : Pooled(apool), furl(aurl) { } - virtual void *malloc(size_t size) { return Pooled::malloc(size, 8); } + virtual void *malloc(size_t size) { return Pooled::malloc_atomic(size, 8); } virtual void *calloc(size_t size) { return Pooled::calloc(size); } /** @@ -82,7 +83,7 @@ public: } private: - ConstStringPtr furl; + const String& furl; Exception fexception; }; @@ -103,8 +104,10 @@ static void expire_connections(const Has // SQL_Driver_manager -SQL_Driver_manager::SQL_Driver_manager(): - prev_expiration_pass_time(0) { +SQL_Driver_manager::SQL_Driver_manager(Pool& apool) : Cache_manager(apool), + driver_cache(apool), + connection_cache(apool), + prev_expiration_pass_time(0) { } SQL_Driver_manager::~SQL_Driver_manager() { @@ -113,8 +116,8 @@ SQL_Driver_manager::~SQL_Driver_manager( } /// @param request_url protocol://[driver-dependent] -SQL_ConnectionPtr SQL_Driver_manager::get_connection(ConstStringPtr request_url, - ConstStringPtr request_origin, +SQL_Connection_ptr SQL_Driver_manager::get_connection(const String& request_url, + const String& request_origin, Table *protocol2driver_and_client) { Pool& pool=request_origin.pool(); // request pool @@ -149,7 +152,7 @@ SQL_ConnectionPtr SQL_Driver_manager::ge // make global_url C-string on global pool request_url_cstr=request_url.cstr(); - char *global_url_cstr=(char *)malloc(strlen(request_url_cstr)+1); + char *global_url_cstr=(char *)malloc_atomic(strlen(request_url_cstr)+1); strcpy(global_url_cstr, request_url_cstr); // make global_url string on global pool String& global_url=*new(this->pool()) String(this->pool(), global_url_cstr); @@ -159,7 +162,7 @@ SQL_ConnectionPtr SQL_Driver_manager::ge while(*request_url_cstr=='/') request_url_cstr++; // make global_protocol C-string on global pool - char *global_protocol_cstr=(char *)malloc(strlen(request_protocol_cstr)+1); + char *global_protocol_cstr=(char *)malloc_atomic(strlen(request_protocol_cstr)+1); strcpy(global_protocol_cstr, request_protocol_cstr); // make global_protocol string on global pool String& global_protocol=*new(this->pool()) String(this->pool(), @@ -242,10 +245,10 @@ SQL_ConnectionPtr SQL_Driver_manager::ge if(!connection->connected()) connection->connect(request_url_cstr); // return autoclosing object for it - return SQL_ConnectionPtr(connection); + return SQL_Connection_ptr(connection); } -void SQL_Driver_manager::close_connection(ConstStringPtr url, +void SQL_Driver_manager::close_connection(const String& url, SQL_Connection& connection) { // deassociate from services[request] connection.set_services(0); @@ -255,13 +258,13 @@ void SQL_Driver_manager::close_connectio // driver cache -SQL_Driver *SQL_Driver_manager::get_driver_from_cache(ConstStringPtr protocol) { +SQL_Driver *SQL_Driver_manager::get_driver_from_cache(const String& protocol) { SYNCHRONIZED; return static_cast(driver_cache.get(protocol)); } -void SQL_Driver_manager::put_driver_to_cache(ConstStringPtr protocol, +void SQL_Driver_manager::put_driver_to_cache(const String& protocol, SQL_Driver& driver) { SYNCHRONIZED; @@ -270,7 +273,7 @@ void SQL_Driver_manager::put_driver_to_c // connection cache /// @todo get rid of memory spending Stack [zeros deep inside got accumulated] -SQL_Connection *SQL_Driver_manager::get_connection_from_cache(ConstStringPtr url) { +SQL_Connection *SQL_Driver_manager::get_connection_from_cache(const String& url) { SYNCHRONIZED; if(Stack *connections=static_cast(connection_cache.get(url))) @@ -283,7 +286,7 @@ SQL_Connection *SQL_Driver_manager::get_ return 0; } -void SQL_Driver_manager::put_connection_to_cache(ConstStringPtr url, +void SQL_Driver_manager::put_connection_to_cache(const String& url, SQL_Connection& connection) { SYNCHRONIZED; @@ -320,7 +323,7 @@ static void add_connection_to_status_cac time_t time_used=connection.get_time_used(); const char *unsafe_time_cstr=ctime(&time_used); int time_buf_size=strlen(unsafe_time_cstr); - char *safe_time_buf=(char *)pool.malloc(time_buf_size); + char *safe_time_buf=(char *)pool.malloc_atomic(time_buf_size); memcpy(safe_time_buf, unsafe_time_cstr, time_buf_size); row+=new(pool) String(pool, safe_time_buf, time_buf_size); @@ -333,7 +336,7 @@ static void add_connections_to_status_ca for(int countdown=stack.top_index(); countdown-->=0; ) add_connection_to_status_cache_table(iter.next(), info); } -ValuePtr SQL_Driver_manager::get_status(Pool& pool, ConstStringPtr source) { +Value& SQL_Driver_manager::get_status(Pool& pool, const String *source) { VHash& result=*new(pool) VHash(pool); // cache