]> git.lizzy.rs Git - rust.git/commitdiff
Fix destroy assertions in mutex/rwlock/condvar
authorMichael Neumann <mneumann@ntecs.de>
Thu, 8 Jan 2015 18:04:34 +0000 (19:04 +0100)
committerMichael Neumann <mneumann@ntecs.de>
Thu, 8 Jan 2015 18:04:34 +0000 (19:04 +0100)
On DragonFly pthread_{mutex,rwlock,condvar}_destroy() returns EINVAL
when called on a pthread_{mutex,rwlock,condvar}_t that was just
initialized via PTHREAD_{MUTEX,RWLOCK,CONDVAR}_INITIALIZER and not used
in the meantime or initialized via pthread_{mutex,rwlock,condvar}_init().
Change the code to treat a return value of EINVAL on DragonFly as success.

src/libstd/sys/unix/condvar.rs
src/libstd/sys/unix/mutex.rs
src/libstd/sys/unix/rwlock.rs

index 3aa4825f3be99375abbc6478af4884b4446962cb..52dd261824fd43021825913644b8b489a358389c 100644 (file)
@@ -76,8 +76,20 @@ pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
     }
 
     #[inline]
+    #[cfg(not(target_os = "dragonfly"))]
     pub unsafe fn destroy(&self) {
         let r = ffi::pthread_cond_destroy(self.inner.get());
         debug_assert_eq!(r, 0);
     }
+
+    #[inline]
+    #[cfg(target_os = "dragonfly")]
+    pub unsafe fn destroy(&self) {
+        let r = ffi::pthread_cond_destroy(self.inner.get());
+        // On DragonFly pthread_cond_destroy() returns EINVAL if called on
+        // a condvar that was just initialized with
+        // ffi::PTHREAD_COND_INITIALIZER. Once it is used or
+        // pthread_cond_init() is called, this behaviour no longer occurs.
+        debug_assert!(r == 0 || r == libc::EINVAL);
+    }
 }
index ada8a7f2349bb6992de620e3c35bbc1cfbb31407..9e1527aef201abdfb0215143a18bdb46ef0bc4cd 100644 (file)
@@ -48,8 +48,20 @@ pub unsafe fn try_lock(&self) -> bool {
         ffi::pthread_mutex_trylock(self.inner.get()) == 0
     }
     #[inline]
+    #[cfg(not(target_os = "dragonfly"))]
     pub unsafe fn destroy(&self) {
         let r = ffi::pthread_mutex_destroy(self.inner.get());
         debug_assert_eq!(r, 0);
     }
+    #[inline]
+    #[cfg(target_os = "dragonfly")]
+    pub unsafe fn destroy(&self) {
+        use libc;
+        let r = ffi::pthread_mutex_destroy(self.inner.get());
+        // On DragonFly pthread_mutex_destroy() returns EINVAL if called on a
+        // mutex that was just initialized with ffi::PTHREAD_MUTEX_INITIALIZER.
+        // Once it is used (locked/unlocked) or pthread_mutex_init() is called,
+        // this behaviour no longer occurs.
+        debug_assert!(r == 0 || r == libc::EINVAL);
+    }
 }
index 0d63ff14ff26b892a3e0f346598dd60f2cd81b61..54523e0076dc3c47ce41897cb416b4b2f795b385 100644 (file)
@@ -50,8 +50,21 @@ pub unsafe fn read_unlock(&self) {
     #[inline]
     pub unsafe fn write_unlock(&self) { self.read_unlock() }
     #[inline]
+    #[cfg(not(target_os = "dragonfly"))]
     pub unsafe fn destroy(&self) {
         let r = ffi::pthread_rwlock_destroy(self.inner.get());
         debug_assert_eq!(r, 0);
     }
+
+    #[inline]
+    #[cfg(target_os = "dragonfly")]
+    pub unsafe fn destroy(&self) {
+        use libc;
+        let r = ffi::pthread_rwlock_destroy(self.inner.get());
+        // On DragonFly pthread_rwlock_destroy() returns EINVAL if called on a
+        // rwlock that was just initialized with
+        // ffi::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked)
+        // or pthread_rwlock_init() is called, this behaviour no longer occurs.
+        debug_assert!(r == 0 || r == libc::EINVAL);
+    }
 }