@@ -78,6 +78,7 @@ use std::collections::HashMap;
78
78
use std:: fmt;
79
79
use std:: io;
80
80
use std:: sync:: Arc ;
81
+ use std:: sync:: atomic:: { AtomicUsize , ATOMIC_USIZE_INIT , Ordering } ;
81
82
use std:: sync:: mpsc:: { self , Sender , Receiver } ;
82
83
use tokio_core:: reactor:: Handle ;
83
84
@@ -109,6 +110,8 @@ const TYPEINFO_QUERY: &'static str = "__typeinfo";
109
110
const TYPEINFO_ENUM_QUERY : & ' static str = "__typeinfo_enum" ;
110
111
const TYPEINFO_COMPOSITE_QUERY : & ' static str = "__typeinfo_composite" ;
111
112
113
+ static NEXT_STMT_ID : AtomicUsize = ATOMIC_USIZE_INIT ;
114
+
112
115
/// Specifies the TLS support required for a new connection.
113
116
pub enum TlsMode {
114
117
/// The connection must use TLS.
@@ -163,7 +166,6 @@ struct InnerConnection {
163
166
parameters : HashMap < String , String > ,
164
167
types : HashMap < Oid , Other > ,
165
168
cancel_data : CancelData ,
166
- next_stmt_id : u32 ,
167
169
has_typeinfo_query : bool ,
168
170
has_typeinfo_enum_query : bool ,
169
171
has_typeinfo_composite_query : bool ,
@@ -283,7 +285,6 @@ impl Connection {
283
285
process_id : 0 ,
284
286
secret_key : 0 ,
285
287
} ,
286
- next_stmt_id : 0 ,
287
288
has_typeinfo_query : false ,
288
289
has_typeinfo_enum_query : false ,
289
290
has_typeinfo_composite_query : false ,
@@ -969,9 +970,8 @@ impl Connection {
969
970
}
970
971
971
972
/// Creates a new prepared statement.
972
- pub fn prepare ( mut self , query : & str ) -> BoxFuture < ( Statement , Connection ) , Error > {
973
- let id = self . 0 . next_stmt_id ;
974
- self . 0 . next_stmt_id += 1 ;
973
+ pub fn prepare ( self , query : & str ) -> BoxFuture < ( Statement , Connection ) , Error > {
974
+ let id = NEXT_STMT_ID . fetch_add ( 1 , Ordering :: SeqCst ) ;
975
975
let name = format ! ( "s{}" , id) ;
976
976
self . raw_prepare ( & name, query)
977
977
. map ( |( params, columns, conn) | {
0 commit comments