Remove dependency on parking_lot (#353)

This commit is contained in:
包布丁
2023-03-06 23:01:19 +08:00
committed by GitHub
parent 2e17847b48
commit c2baa31c2a
3 changed files with 12 additions and 16 deletions

View File

@@ -136,7 +136,6 @@ directories = "4.0"
async-ffi = "0.2"
libloading = "0.7"
async-recursion = "1.0"
parking_lot = "0.12"
# config-json
serde_json = { version = "1.0", features = ["raw_value"], optional = true }

View File

@@ -1,20 +1,17 @@
use std::io;
use std::io::Write;
use std::sync::Mutex;
use anyhow::{anyhow, Result};
use lazy_static::lazy_static;
use log4rs::append::file::FileAppender;
use log4rs::append::{console::ConsoleAppender, Append};
use log4rs::config::{Appender, Config, Root};
use log4rs::encode::{pattern::PatternEncoder, Encode};
use log4rs::Handle;
use parking_lot::Mutex;
use crate::config;
lazy_static! {
static ref HANDLE: Mutex<Option<Handle>> = Mutex::new(None);
}
static HANDLE: Mutex<Option<Handle>> = Mutex::new(None);
#[cfg(any(target_os = "ios", target_os = "android", target_os = "macos"))]
mod mobile {
@@ -29,7 +26,7 @@ mod mobile {
impl log4rs::append::Append for MobileConsoleAppender {
fn append(&self, record: &log::Record<'_>) -> Result<()> {
// No need flush with the current mobile console writer impl
self.encoder.encode(&mut *self.writer.lock(), record)
self.encoder.encode(&mut *self.writer.lock().unwrap(), record)
}
fn flush(&self) {}
@@ -140,7 +137,7 @@ pub fn setup_logger(config: &protobuf::MessageField<crate::config::Log>) -> Resu
}
}
let config = builder.build(root.build(loglevel)).unwrap();
let mut handle = HANDLE.lock();
let mut handle = HANDLE.lock().unwrap();
if let Some(handle) = handle.as_ref() {
handle.set_config(config);
} else {

View File

@@ -2,10 +2,10 @@ use std::collections::HashMap;
use std::io;
use std::sync::mpsc::sync_channel;
use std::sync::Arc;
use std::sync::Mutex;
use anyhow::anyhow;
use lazy_static::lazy_static;
use parking_lot::Mutex;
use thiserror::Error;
use tokio::sync::mpsc;
use tokio::sync::RwLock;
@@ -249,7 +249,7 @@ impl RuntimeManager {
// by an editor, in that case create a new watcher to watch
// the new file.
if let event::EventKind::Remove(event::RemoveKind::File) = ev.kind {
if let Some(m) = RUNTIME_MANAGER.lock().get(&rt_id) {
if let Some(m) = RUNTIME_MANAGER.lock().unwrap().get(&rt_id) {
let _ = m.new_watcher();
}
}
@@ -267,7 +267,7 @@ impl RuntimeManager {
)
.map_err(Error::Watcher)?;
log::info!("watching changes of file: {}", config_path);
self.watcher.lock().replace(watcher);
self.watcher.lock().unwrap().replace(watcher);
}
Ok(())
}
@@ -281,21 +281,21 @@ lazy_static! {
}
pub fn reload(key: RuntimeId) -> Result<(), Error> {
if let Some(m) = RUNTIME_MANAGER.lock().get(&key) {
if let Some(m) = RUNTIME_MANAGER.lock().unwrap().get(&key) {
return m.blocking_reload();
}
Err(Error::RuntimeManager)
}
pub fn shutdown(key: RuntimeId) -> bool {
if let Some(m) = RUNTIME_MANAGER.lock().get(&key) {
if let Some(m) = RUNTIME_MANAGER.lock().unwrap().get(&key) {
return m.blocking_shutdown();
}
false
}
pub fn is_running(key: RuntimeId) -> bool {
RUNTIME_MANAGER.lock().contains_key(&key)
RUNTIME_MANAGER.lock().unwrap().contains_key(&key)
}
pub fn test_config(config_path: &str) -> Result<(), Error> {
@@ -531,7 +531,7 @@ pub fn start(rt_id: RuntimeId, opts: StartOptions) -> Result<(), Error> {
let _ = tokio::signal::ctrl_c().await;
}));
RUNTIME_MANAGER.lock().insert(rt_id, runtime_manager);
RUNTIME_MANAGER.lock().unwrap().insert(rt_id, runtime_manager);
log::trace!("added runtime {}", &rt_id);
@@ -542,7 +542,7 @@ pub fn start(rt_id: RuntimeId, opts: StartOptions) -> Result<(), Error> {
drop(inbound_manager);
RUNTIME_MANAGER.lock().remove(&rt_id);
RUNTIME_MANAGER.lock().unwrap().remove(&rt_id);
rt.shutdown_background();