Skip to content

Commit

Permalink
Remove the sneaky bug from parking_lot usage in TLS dtors.
Browse files Browse the repository at this point in the history
This bug is a result from `parking_lot` not having a fallback for its
TLS variable. We replace it by the libstd mutex to get rid of this
issue.
  • Loading branch information
ticki committed May 23, 2017
1 parent 25f6639 commit 348a091
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions concurrent/src/global.rs
@@ -1,6 +1,6 @@
//! The global state.

use parking_lot::Mutex;
use std::sync::Mutex; // TODO: Use custom option-like thing.
use std::collections::HashSet;
use std::mem;
use {rand, hazard, mpsc};
Expand Down Expand Up @@ -107,7 +107,7 @@ impl State {
/// currently active in the hazards.
fn try_gc(&self) {
// Lock the "garbo" (the part of the state needed to GC).
if let Some(mut garbo) = self.garbo.try_lock() {
if let Ok(mut garbo) = self.garbo.try_lock() {
// Handle all the messages sent.
garbo.handle_all();
// Collect the garbage.
Expand Down
6 changes: 3 additions & 3 deletions concurrent/src/mpsc.rs
Expand Up @@ -8,7 +8,7 @@
//! although this is reasonably fast as the lock is only held for very short time, it is
//! sub-optimal, and blocking.

use parking_lot::Mutex;
use std::sync::Mutex;
use std::sync::Arc;
use std::mem;

Expand Down Expand Up @@ -36,7 +36,7 @@ impl<T> Sender<T> {
/// Send an item to this channel.
pub fn send(&self, item: T) {
// Lock the vector, and push.
self.inner.lock().push(item);
self.inner.lock().unwrap().push(item);
}
}

Expand All @@ -52,6 +52,6 @@ impl<T> Receiver<T> {
/// This takes all the elements and applies the given closure to them in an unspecified order.
pub fn recv_all(&self) -> Vec<T> {
// Lock the vector, and replace it by an empty vector, then iterate.
mem::replace(&mut *self.inner.lock(), Vec::new())
mem::replace(&mut *self.inner.lock().unwrap(), Vec::new())
}
}

0 comments on commit 348a091

Please sign in to comment.