]> git.lizzy.rs Git - rust.git/commitdiff
Implement TryEnterCriticalSection
authorDavid Cook <divergentdave@gmail.com>
Sat, 28 Mar 2020 15:16:08 +0000 (10:16 -0500)
committerDavid Cook <divergentdave@gmail.com>
Sun, 5 Apr 2020 15:33:32 +0000 (10:33 -0500)
src/shims/foreign_items/windows.rs
tests/run-pass/sync.rs

index cfc94bfd9b71d8dc2ce884d2cbaa1d25c4f318c0..3c819fddc410aa278e216489f949b524e1f7480e 100644 (file)
@@ -233,6 +233,11 @@ fn emulate_foreign_item_by_name(
                 // (Windows locks are reentrant, and we have only 1 thread,
                 // so not doing any futher checks here is at least not incorrect.)
             }
+            "TryEnterCriticalSection" if this.frame().instance.to_string().starts_with("std::sys::windows::")
+            => {
+                // There is only one thread, so this always succeeds and returns TRUE
+                this.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?;
+            }
 
             _ => throw_unsup_format!("can't call foreign function: {}", link_name),
         }
index 24d7b0be53420f8d5441f02b2e5958c83813babe..0ddf429fad9c6c69cf238d7bdfb35b3605aa19aa 100644 (file)
@@ -1,6 +1,6 @@
 #![feature(rustc_private)]
 
-use std::sync::{Mutex, RwLock, TryLockError};
+use std::sync::{Mutex, TryLockError};
 
 extern crate libc;
 
@@ -86,6 +86,7 @@ fn test_mutex_libc_static_initializer_recursive() {
 
 #[cfg(not(target_os = "windows"))]
 fn test_rwlock_stdlib() {
+    use std::sync::RwLock;
     let rw = RwLock::new(0);
     {
         let _read_guard = rw.read().unwrap();