Skip to content

Commit

Permalink
Fix Rust Beta warning about deprecated AtomicBool method.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rfk committed Jan 11, 2021
1 parent 1d739d7 commit 7ab94dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
30 changes: 13 additions & 17 deletions components/places/src/api/places_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,19 @@ impl PlacesApi {
}

pub fn open_sync_connection(&self) -> Result<SyncConn<'_>> {
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
Expand Down
8 changes: 5 additions & 3 deletions components/viaduct/src/backend/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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
}
}

Expand Down

0 comments on commit 7ab94dc

Please sign in to comment.