mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 03:20:46 -05:00
Ban all unwrap usage in codebase
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use base::{ResultExt, new_daemon_thread};
|
||||
use nix::sys::signal::SigSet;
|
||||
use nix::unistd::{getpid, gettid};
|
||||
use std::sync::{Condvar, LazyLock, Mutex, WaitTimeoutResult};
|
||||
use std::sync::nonpoison::{Condvar, Mutex};
|
||||
use std::sync::{LazyLock, WaitTimeoutResult};
|
||||
use std::time::Duration;
|
||||
|
||||
static THREAD_POOL: LazyLock<ThreadPool> = LazyLock::new(ThreadPool::default);
|
||||
@@ -33,16 +34,16 @@ impl ThreadPool {
|
||||
|
||||
let task: Option<Box<dyn FnOnce() + Send>>;
|
||||
{
|
||||
let mut info = self.info.lock().unwrap();
|
||||
let mut info = self.info.lock();
|
||||
info.idle_threads += 1;
|
||||
if info.task.is_none() {
|
||||
if is_core_pool {
|
||||
// Core pool never closes, wait forever.
|
||||
info = self.task_is_some.wait(info).unwrap();
|
||||
info = self.task_is_some.wait(info);
|
||||
} else {
|
||||
let dur = Duration::from_secs(THREAD_IDLE_MAX_SEC);
|
||||
let result: WaitTimeoutResult;
|
||||
(info, result) = self.task_is_some.wait_timeout(info, dur).unwrap();
|
||||
(info, result) = self.task_is_some.wait_timeout(info, dur);
|
||||
if result.timed_out() {
|
||||
// Terminate thread after timeout
|
||||
info.idle_threads -= 1;
|
||||
@@ -72,10 +73,10 @@ impl ThreadPool {
|
||||
0
|
||||
}
|
||||
|
||||
let mut info = self.info.lock().unwrap();
|
||||
let mut info = self.info.lock();
|
||||
while info.task.is_some() {
|
||||
// Wait until task is none
|
||||
info = self.task_is_none.wait(info).unwrap();
|
||||
info = self.task_is_none.wait(info);
|
||||
}
|
||||
info.task = Some(Box::new(f));
|
||||
if info.idle_threads == 0 {
|
||||
|
||||
Reference in New Issue
Block a user