@@ -5,7 +5,7 @@ use lazy_static::lazy_static;
5
5
use rustc_codegen_spirv:: rspirv;
6
6
use std:: error:: Error ;
7
7
use std:: path:: { Path , PathBuf } ;
8
- use std:: sync:: Mutex ;
8
+ use std:: sync:: { Mutex , MutexGuard } ;
9
9
10
10
// https://github.com/colin-kiegel/rust-pretty-assertions/issues/24
11
11
#[ derive( PartialEq , Eq ) ]
@@ -25,6 +25,14 @@ lazy_static! {
25
25
static ref GLOBAL_MUTEX : Mutex <( ) > = Mutex :: new( ( ) ) ;
26
26
}
27
27
28
+ fn global_lock ( ) -> MutexGuard < ' static , ( ) > {
29
+ match GLOBAL_MUTEX . lock ( ) {
30
+ Ok ( guard) => guard,
31
+ // we don't care about poison - a previous test may have paniced, but that's okay
32
+ Err ( poisoned) => poisoned. into_inner ( ) ,
33
+ }
34
+ }
35
+
28
36
static CARGO_TOML : & str = r#"[package]
29
37
name = "test-project"
30
38
version = "0.1.0"
@@ -80,7 +88,7 @@ fn read_module(path: &Path) -> Result<rspirv::dr::Module, Box<dyn Error>> {
80
88
}
81
89
82
90
fn val ( src : & str ) {
83
- let _lock = GLOBAL_MUTEX . lock ( ) . unwrap ( ) ;
91
+ let _lock = global_lock ( ) ;
84
92
// spirv-val is included in building
85
93
build ( src) ;
86
94
}
@@ -102,7 +110,7 @@ fn assert_str_eq(expected: &str, result: &str) {
102
110
}
103
111
104
112
fn dis_fn ( src : & str , func : & str , expect : & str ) {
105
- let _lock = GLOBAL_MUTEX . lock ( ) . unwrap ( ) ;
113
+ let _lock = global_lock ( ) ;
106
114
let module = read_module ( & build ( src) ) . unwrap ( ) ;
107
115
let id = module
108
116
. debugs
0 commit comments