Update Arc usage

This commit is contained in:
Steven Fackler 2014-02-18 21:16:26 -08:00
parent a42b096902
commit 20dc1046ee

View File

@ -80,15 +80,13 @@ impl PostgresConnectionPool {
/// ///
/// If all connections are in use, blocks until one becomes available. /// If all connections are in use, blocks until one becomes available.
pub fn get_connection(&self) -> PooledPostgresConnection { pub fn get_connection(&self) -> PooledPostgresConnection {
let conn = unsafe { let conn = self.pool.access_cond(|pool, cvar| {
self.pool.unsafe_access_cond(|pool, cvar| { while pool.pool.is_empty() {
while pool.pool.is_empty() { cvar.wait();
cvar.wait(); }
}
pool.pool.pop().unwrap() pool.pool.pop().unwrap()
}) });;
};
PooledPostgresConnection { PooledPostgresConnection {
pool: self.clone(), pool: self.clone(),
@ -109,12 +107,10 @@ pub struct PooledPostgresConnection {
impl Drop for PooledPostgresConnection { impl Drop for PooledPostgresConnection {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { let conn = RefCell::new(self.conn.take());
let conn = RefCell::new(self.conn.take()); self.pool.pool.access(|pool| {
self.pool.pool.unsafe_access(|pool| { pool.pool.push(conn.with_mut(|r| r.take_unwrap()));
pool.pool.push(conn.with_mut(|r| r.take_unwrap())); })
})
}
} }
} }