➖ Sustituye parking_lot por std::sync
PageTop ya no lo necesita como dependencia directa: `std::sync` cubre los bloqueos del contexto, los temas y las trazas. No se detecta pérdida de rendimiento en ningún caso. Usa `unwrap()` en los bloqueos, también en las extensiones, porque sus secciones exclusivas no pueden provocar panic. Sólo pagetop-cron ignora el envenenamiento, porque calcula fechas con el bloqueo tomado.
This commit is contained in:
parent
a6d15ab211
commit
698b917fb1
11 changed files with 31 additions and 56 deletions
|
|
@ -11,10 +11,9 @@ use crate::response::read_flash_messages;
|
|||
use crate::web::HttpRequest;
|
||||
use crate::{CowStr, util};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use std::any::{Any, TypeId};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
|
||||
mod assets_op;
|
||||
pub use assets_op::AssetsOp;
|
||||
|
|
|
|||
|
|
@ -481,7 +481,7 @@ pub trait Contextual {
|
|||
segments
|
||||
};
|
||||
let count = {
|
||||
let mut map = self.context().id_counters.lock();
|
||||
let mut map = self.context().id_counters.lock().unwrap();
|
||||
let n = map.entry(TypeId::of::<C>()).or_insert(0);
|
||||
*n += 1;
|
||||
*n
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
use crate::core::theme::ThemeRef;
|
||||
use crate::{global, trace};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::{LazyLock, RwLock};
|
||||
|
||||
// **< TEMAS >**************************************************************************************
|
||||
|
||||
|
|
@ -11,7 +9,7 @@ static THEMES: LazyLock<RwLock<Vec<ThemeRef>>> = LazyLock::new(|| RwLock::new(Ve
|
|||
|
||||
// Registra el tema si no lo estaba ya, para evitar duplicados. Devuelve `true` si lo ha añadido.
|
||||
pub(crate) fn register_theme(theme: ThemeRef) -> bool {
|
||||
let mut themes = THEMES.write();
|
||||
let mut themes = THEMES.write().unwrap();
|
||||
if themes.iter().any(|t| t.type_id() == theme.type_id()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -21,7 +19,7 @@ pub(crate) fn register_theme(theme: ThemeRef) -> bool {
|
|||
|
||||
/// Devuelve los temas habilitados en la aplicación, en el orden en que se registraron.
|
||||
pub fn enabled_themes() -> Vec<ThemeRef> {
|
||||
THEMES.read().clone()
|
||||
THEMES.read().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Devuelve el tema identificado por su [`short_name()`](crate::core::AnyInfo::short_name).
|
||||
|
|
@ -30,6 +28,7 @@ pub fn enabled_themes() -> Vec<ThemeRef> {
|
|||
pub fn theme_by_short_name(short_name: &str) -> Option<ThemeRef> {
|
||||
THEMES
|
||||
.read()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.find(|t| t.short_name().eq_ignore_ascii_case(short_name))
|
||||
.copied()
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@ use crate::core::component::{Child, ChildOp, Children, Component};
|
|||
use crate::core::theme::{CoreRegions, RegionRef, ThemeRef};
|
||||
use crate::{AutoDefault, UniqueId, builder_impl};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, LazyLock};
|
||||
use std::sync::{Arc, LazyLock, RwLock};
|
||||
|
||||
// Lista de prototipos de componentes por nombre de región.
|
||||
//
|
||||
|
|
@ -90,7 +88,7 @@ impl ChildrenInRegions {
|
|||
let region_name = region.name();
|
||||
|
||||
// 1. Prototipos globales comunes.
|
||||
if let Some(global_protos) = COMMON_REGIONS.read().get(region_name) {
|
||||
if let Some(global_protos) = COMMON_REGIONS.read().unwrap().get(region_name) {
|
||||
result.add_many(
|
||||
global_protos
|
||||
.iter()
|
||||
|
|
@ -102,7 +100,7 @@ impl ChildrenInRegions {
|
|||
result.add_many(page_children);
|
||||
}
|
||||
// 3. Prototipos del tema activo.
|
||||
if let Some(theme_region) = THEME_REGIONS.read().get(&theme.type_id())
|
||||
if let Some(theme_region) = THEME_REGIONS.read().unwrap().get(&theme.type_id())
|
||||
&& let Some(theme_protos) = theme_region.get(region_name)
|
||||
{
|
||||
result.add_many(
|
||||
|
|
@ -190,6 +188,7 @@ impl InRegion {
|
|||
InRegion::ForTheme(theme, region) => {
|
||||
THEME_REGIONS
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(theme.type_id())
|
||||
.or_default()
|
||||
.push((*region).name(), proto);
|
||||
|
|
@ -200,6 +199,6 @@ impl InRegion {
|
|||
|
||||
#[inline]
|
||||
fn add_to_common(region: RegionRef, proto: Arc<dyn Component>) {
|
||||
COMMON_REGIONS.write().push(region.name(), proto);
|
||||
COMMON_REGIONS.write().unwrap().push(region.name(), proto);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ pub use tracing::{debug_span, error_span, info_span, trace_span, warn_span};
|
|||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Mutex, PoisonError};
|
||||
|
||||
// Avisos generados antes de iniciar las trazas. La configuración se lee antes, porque las trazas
|
||||
// dependen de la sección `[log]`, así que sus avisos se guardan aquí y se emiten al iniciarlas.
|
||||
|
|
@ -34,9 +34,7 @@ static DEFERRED_WARNINGS: Mutex<Option<Vec<String>>> = Mutex::new(Some(Vec::new(
|
|||
// basta para la configuración global, que `init()` lee antes de recoger los avisos. Usarla después
|
||||
// es un error de programación: se emite como `error!` con el aviso incluido, para que no se pierda.
|
||||
pub(crate) fn defer_warning(message: String) {
|
||||
let mut deferred = DEFERRED_WARNINGS
|
||||
.lock()
|
||||
.unwrap_or_else(PoisonError::into_inner);
|
||||
let mut deferred = DEFERRED_WARNINGS.lock().unwrap();
|
||||
match deferred.as_mut() {
|
||||
Some(warnings) => warnings.push(message),
|
||||
None => {
|
||||
|
|
@ -70,7 +68,7 @@ pub(crate) fn init() -> Option<WorkerGuard> {
|
|||
// Al leer `SETTINGS` en la línea anterior ya se han guardado los avisos de la configuración.
|
||||
let mut warnings = DEFERRED_WARNINGS
|
||||
.lock()
|
||||
.unwrap_or_else(PoisonError::into_inner)
|
||||
.unwrap()
|
||||
.take() // Deja `None`, desde ahora, `defer_warning()` trata cualquier aviso como mal uso.
|
||||
.unwrap_or_default();
|
||||
if !enabled {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue