Browse Source

Remove the `leak` bound from `Mutex`

ticki 8 years ago
parent
commit
80f126cbf1
3 changed files with 13 additions and 14 deletions
  1. 0 2
      src/allocator.rs
  2. 5 2
      src/bookkeeper.rs
  3. 8 10
      src/sync.rs

+ 0 - 2
src/allocator.rs

@@ -102,5 +102,3 @@ impl Allocator {
         self.inner.assert_no_leak();
     }
 }
-
-impl Leak for Allocator {}

+ 5 - 2
src/bookkeeper.rs

@@ -479,8 +479,8 @@ impl Bookkeeper {
 
     /// Push two blocks to the block pool.
     ///
-    /// This will append a block entry to the end of the block pool (and merge if possible). Make
-    /// sure that this entry has a value higher than any of the elements in the list, to keep it
+    /// This will append the blocks to the end of the block pool (and merge if possible). Make sure
+    /// that these blocks has a value higher than any of the elements in the list, to keep it
     /// sorted.
     ///
     /// This guarantees linearity so that the blocks will be adjacent.
@@ -489,6 +489,9 @@ impl Bookkeeper {
         // Logging.
         log!(self.pool;self.pool.len(), "Pushing {:?} and {:?}.", block_a, block_b);
 
+        // Catch stupid bug...
+        debug_assert!(block_a <= block_b, "The first pushed block is not lower or equal to the second.");
+
         // Reserve extra elements.
         let len = self.pool.len();
         self.reserve(len + 2);

+ 8 - 10
src/sync.rs

@@ -1,7 +1,5 @@
 //! Synchronization primitives.
 
-use prelude::*;
-
 use sys;
 
 use core::cell::UnsafeCell;
@@ -13,7 +11,7 @@ use core::ops;
 /// This assures that only one holds mutability of the inner value. To get the inner value, you
 /// need acquire the "lock". If you try to lock it while a lock is already held elsewhere, it will
 /// block the thread until the lock is released.
-pub struct Mutex<T: Leak> {
+pub struct Mutex<T> {
     /// The inner value.
     inner: UnsafeCell<T>,
     /// The lock boolean.
@@ -25,19 +23,19 @@ pub struct Mutex<T: Leak> {
 /// A mutex guard.
 ///
 /// This acts as the lock.
-pub struct MutexGuard<'a, T: 'a + Leak> {
+pub struct MutexGuard<'a, T: 'a> {
     mutex: &'a Mutex<T>,
 }
 
 /// Release the mutex.
-impl<'a, T: Leak> Drop for MutexGuard<'a, T> {
+impl<'a, T> Drop for MutexGuard<'a, T> {
     #[inline]
     fn drop(&mut self) {
         self.mutex.locked.store(false, atomic::Ordering::SeqCst);
     }
 }
 
-impl<'a, T: Leak> ops::Deref for MutexGuard<'a, T> {
+impl<'a, T> ops::Deref for MutexGuard<'a, T> {
     type Target = T;
 
     #[inline]
@@ -48,7 +46,7 @@ impl<'a, T: Leak> ops::Deref for MutexGuard<'a, T> {
     }
 }
 
-impl<'a, T: Leak> ops::DerefMut for MutexGuard<'a, T> {
+impl<'a, T> ops::DerefMut for MutexGuard<'a, T> {
     fn deref_mut(&mut self) -> &mut T {
         unsafe {
             &mut *self.mutex.inner.get()
@@ -56,7 +54,7 @@ impl<'a, T: Leak> ops::DerefMut for MutexGuard<'a, T> {
     }
 }
 
-impl<T: Leak> Mutex<T> {
+impl<T> Mutex<T> {
     /// Create a new mutex with some inner value.
     #[inline]
     pub const fn new(inner: T) -> Mutex<T> {
@@ -87,8 +85,8 @@ impl<T: Leak> Mutex<T> {
     }
 }
 
-unsafe impl<T: Send + Leak> Send for Mutex<T> {}
-unsafe impl<T: Send + Leak> Sync for Mutex<T> {}
+unsafe impl<T: Send> Send for Mutex<T> {}
+unsafe impl<T: Send> Sync for Mutex<T> {}
 
 #[cfg(test)]
 mod test {