Remove frumious pool hack

This commit is contained in:
Steven Fackler 2014-04-22 22:10:06 -07:00
parent 47cb9b1c3e
commit 8eca3aecb6
2 changed files with 7 additions and 24 deletions

View File

@ -70,12 +70,12 @@ extern crate serialize;
extern crate sync; extern crate sync;
extern crate time; extern crate time;
extern crate phf; extern crate phf;
#[phase(syntax)]
extern crate phf_mac;
extern crate url; extern crate url;
#[phase(syntax, link)] #[phase(syntax, link)]
extern crate log; extern crate log;
extern crate uuid; extern crate uuid;
#[phase(syntax)]
extern crate phf_mac;
use collections::{Deque, HashMap, RingBuf}; use collections::{Deque, HashMap, RingBuf};
use url::{UserInfo, Url}; use url::{UserInfo, Url};

View File

@ -1,6 +1,5 @@
//! A simple connection pool //! A simple connection pool
use std::cast;
use sync::{Arc, Mutex}; use sync::{Arc, Mutex};
use {PostgresNotifications, use {PostgresNotifications,
@ -18,28 +17,13 @@ use types::ToSql;
struct InnerConnectionPool { struct InnerConnectionPool {
params: PostgresConnectParams, params: PostgresConnectParams,
ssl: SslMode, ssl: SslMode,
// Actually Vec<~PostgresConnection> pool: Vec<PostgresConnection>,
pool: Vec<*()>,
}
impl Drop for InnerConnectionPool {
fn drop(&mut self) {
loop {
match self.pool.pop() {
Some(conn) => unsafe {
let c: ~PostgresConnection = cast::transmute(conn);
drop(c);
},
None => break
}
}
}
} }
impl InnerConnectionPool { impl InnerConnectionPool {
fn add_connection(&mut self) -> Result<(), PostgresConnectError> { fn add_connection(&mut self) -> Result<(), PostgresConnectError> {
PostgresConnection::connect(self.params.clone(), &self.ssl) PostgresConnection::connect(self.params.clone(), &self.ssl)
.map(|c| unsafe { self.pool.push(cast::transmute(~c)); }) .map(|c| self.pool.push(c))
} }
} }
@ -101,7 +85,7 @@ impl PostgresConnectionPool {
PooledPostgresConnection { PooledPostgresConnection {
pool: self.clone(), pool: self.clone(),
conn: Some(unsafe { cast::transmute(pool.pool.pop().unwrap()) }) conn: Some(pool.pool.pop().unwrap())
} }
} }
} }
@ -113,14 +97,13 @@ impl PostgresConnectionPool {
pub struct PooledPostgresConnection { pub struct PooledPostgresConnection {
pool: PostgresConnectionPool, pool: PostgresConnectionPool,
// TODO remove the Option wrapper when drop takes self by value // TODO remove the Option wrapper when drop takes self by value
conn: Option<~PostgresConnection> conn: Option<PostgresConnection>
} }
impl Drop for PooledPostgresConnection { impl Drop for PooledPostgresConnection {
fn drop(&mut self) { fn drop(&mut self) {
let conn = unsafe { cast::transmute(self.conn.take_unwrap()) };
let mut pool = self.pool.pool.lock(); let mut pool = self.pool.pool.lock();
pool.pool.push(conn); pool.pool.push(self.conn.take_unwrap());
pool.cond.signal(); pool.cond.signal();
} }
} }