Skip to content

Commit d213562

Browse files
committed
Simplify code
1 parent ee6e835 commit d213562

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/use_file.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,24 @@ fn get_rng_fd() -> Result<libc::c_int, Error> {
6363
}
6464
val => return Ok(val as libc::c_int),
6565
}
66-
let res = FD.compare_exchange_weak(
66+
67+
let xch_res = FD.compare_exchange_weak(
6768
FD_UNINIT,
6869
FD_ONGOING_INIT,
6970
Ordering::AcqRel,
7071
Ordering::Relaxed,
7172
);
72-
if res.is_err() {
73+
if xch_res.is_err() {
7374
continue;
7475
}
7576

76-
return match open_fd() {
77-
Ok(fd) => {
78-
FD.store(fd as usize, Ordering::Release);
79-
Ok(fd)
80-
}
81-
Err(err) => {
82-
FD.store(FD_UNINIT, Ordering::Release);
83-
Err(err)
84-
}
77+
let res = open_fd();
78+
let val = match res {
79+
Ok(fd) => fd as usize,
80+
Err(_) => FD_UNINIT,
8581
};
82+
FD.store(val, Ordering::Release);
83+
return res;
8684
}
8785
}
8886

0 commit comments

Comments
 (0)