Browse Source

Improve performance of lock contentions.

ticki 8 years ago
parent
commit
c6bccdcbac
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/sync.rs

+ 2 - 2
src/sync.rs

@@ -37,7 +37,7 @@ impl<T> Mutex<T> {
     pub fn lock(&self) -> MutexGuard<T> {
         // Lock the mutex.
         #[cfg(not(feature = "unsafe_no_mutex_lock"))]
-        while self.locked.compare_and_swap(false, true, atomic::Ordering::SeqCst) {
+        while self.locked.compare_and_swap(false, true, atomic::Ordering::Acquire) {
             // ,___,
             // {O,o}
             // |)``)
@@ -64,7 +64,7 @@ pub struct MutexGuard<'a, T: 'a> {
 impl<'a, T> Drop for MutexGuard<'a, T> {
     #[inline]
     fn drop(&mut self) {
-        self.mutex.locked.store(false, atomic::Ordering::SeqCst);
+        self.mutex.locked.store(false, atomic::Ordering::Release);
     }
 }