Use a Cell for next_portal_id

This commit is contained in:
Steven Fackler 2014-02-07 18:17:40 -08:00
parent 774533e1df
commit 26a0cdaae7

View File

@ -78,7 +78,7 @@ use extra::ringbuf::RingBuf;
use extra::url::{UserInfo, Url}; use extra::url::{UserInfo, Url};
use openssl::crypto::hash::{MD5, Hasher}; use openssl::crypto::hash::{MD5, Hasher};
use openssl::ssl::{SslStream, SslContext}; use openssl::ssl::{SslStream, SslContext};
use std::cell::RefCell; use std::cell::{Cell, RefCell};
use std::hashmap::HashMap; use std::hashmap::HashMap;
use std::io::{BufferedStream, IoResult}; use std::io::{BufferedStream, IoResult};
use std::io::net::ip::{Port, SocketAddr}; use std::io::net::ip::{Port, SocketAddr};
@ -572,7 +572,7 @@ impl InnerPostgresConnection {
name: stmt_name, name: stmt_name,
param_types: param_types, param_types: param_types,
result_desc: result_desc, result_desc: result_desc,
next_portal_id: RefCell::new(0) next_portal_id: Cell::new(0)
}) })
} }
@ -918,7 +918,7 @@ pub struct NormalPostgresStatement<'conn> {
priv name: ~str, priv name: ~str,
priv param_types: ~[PostgresType], priv param_types: ~[PostgresType],
priv result_desc: ~[ResultDescription], priv result_desc: ~[ResultDescription],
priv next_portal_id: RefCell<uint> priv next_portal_id: Cell<uint>
} }
#[unsafe_destructor] #[unsafe_destructor]
@ -984,7 +984,8 @@ impl<'conn> NormalPostgresStatement<'conn> {
fn try_lazy_query<'a>(&'a self, row_limit: uint, params: &[&ToSql]) fn try_lazy_query<'a>(&'a self, row_limit: uint, params: &[&ToSql])
-> Result<PostgresResult<'a>, PostgresError> { -> Result<PostgresResult<'a>, PostgresError> {
let id = self.next_portal_id.with_mut(|x| { *x += 1; *x - 1 }); let id = self.next_portal_id.get();
self.next_portal_id.set(id + 1);
let portal_name = format!("{}_portal_{}", self.name, id); let portal_name = format!("{}_portal_{}", self.name, id);
if_ok!(self.execute(portal_name, row_limit, params)); if_ok!(self.execute(portal_name, row_limit, params));