Update Arc usage
This commit is contained in:
parent
a42b096902
commit
20dc1046ee
24
src/pool.rs
24
src/pool.rs
@ -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()));
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user