From d490503c25a4fa5da4e434579f35cdba24b50253 Mon Sep 17 00:00:00 2001 From: Ryan Kelly Date: Mon, 11 Jan 2021 11:37:04 +1100 Subject: [PATCH] Fix Rust Beta warning about deprecated `AtomicBool` method. When compiling on Rust Beta, we're generating a warning about: warning: use of deprecated associated function `std::sync::atomic::AtomicBool::compare_and_swap`: Use `compare_exchange` or `compare_exchange_weak` instead This commit does as advised in the hope of eliminating the warning. --- components/places/src/api/places_api.rs | 30 +++++++++++-------------- components/viaduct/src/backend/ffi.rs | 18 ++++++++------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/components/places/src/api/places_api.rs b/components/places/src/api/places_api.rs index 0bb39569a5..5775b8909e 100644 --- a/components/places/src/api/places_api.rs +++ b/components/places/src/api/places_api.rs @@ -179,23 +179,19 @@ impl PlacesApi { } pub fn open_sync_connection(&self) -> Result> { - let prev_value = self - .sync_conn_active - .compare_and_swap(false, true, Ordering::SeqCst); - if prev_value { - Err(ErrorKind::ConnectionAlreadyOpen.into()) - } else { - let db = PlacesDb::open( - self.db_name.clone(), - ConnectionType::Sync, - self.id, - self.coop_tx_lock.clone(), - )?; - Ok(SyncConn { - db, - flag: &self.sync_conn_active, - }) - } + self.sync_conn_active + .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) + .map_err(|_| ErrorKind::ConnectionAlreadyOpen)?; + let db = PlacesDb::open( + self.db_name.clone(), + ConnectionType::Sync, + self.id, + self.coop_tx_lock.clone(), + )?; + Ok(SyncConn { + db, + flag: &self.sync_conn_active, + }) } /// Close a connection to the database. If the connection is the write diff --git a/components/viaduct/src/backend/ffi.rs b/components/viaduct/src/backend/ffi.rs index 072df40b82..ea1d7b0602 100644 --- a/components/viaduct/src/backend/ffi.rs +++ b/components/viaduct/src/backend/ffi.rs @@ -154,15 +154,17 @@ mod callback_holder { /// Set the function pointer to the FetchCallback. Returns false if we did nothing because the callback had already been initialized pub(super) fn set_callback(h: FetchCallback) -> bool { let as_usize = h as usize; - let old_ptr = CALLBACK_PTR.compare_and_swap(0, as_usize, Ordering::SeqCst); - if old_ptr != 0 { - // This is an internal bug, the other side of the FFI should ensure - // it sets this only once. Note that this is actually going to be - // before logging is initialized in practice, so there's not a lot - // we can actually do here. - log::error!("Bug: Initialized CALLBACK_PTR multiple times"); + match CALLBACK_PTR.compare_exchange(0, as_usize, Ordering::SeqCst, Ordering::SeqCst) { + Ok(_) => true, + Err(_) => { + // This is an internal bug, the other side of the FFI should ensure + // it sets this only once. Note that this is actually going to be + // before logging is initialized in practice, so there's not a lot + // we can actually do here. + log::error!("Bug: Initialized CALLBACK_PTR multiple times"); + false + } } - old_ptr == 0 } }