Use parking_lot for wrapping TextureManager
This commit is contained in:
parent
079490b30d
commit
6a3e7d17ac
5 changed files with 15 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1005,6 +1005,7 @@ dependencies = [
|
||||||
"ahash 0.7.6",
|
"ahash 0.7.6",
|
||||||
"epaint",
|
"epaint",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
|
"parking_lot 0.12.0",
|
||||||
"ron",
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
@ -57,6 +57,7 @@ epaint = { version = "0.17.0", path = "../epaint", default-features = false }
|
||||||
|
|
||||||
ahash = "0.7"
|
ahash = "0.7"
|
||||||
nohash-hasher = "0.2"
|
nohash-hasher = "0.2"
|
||||||
|
parking_lot = "0.12"
|
||||||
|
|
||||||
# Optional:
|
# Optional:
|
||||||
ron = { version = "0.7", optional = true }
|
ron = { version = "0.7", optional = true }
|
||||||
|
|
|
@ -11,8 +11,10 @@ use epaint::{mutex::*, stats::*, text::Fonts, TessellationOptions, *};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// NOTE: we always use `parking_lot` here so we can
|
||||||
|
// use `WrappedTextureManager` from any thread.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct WrappedTextureManager(Arc<RwLock<epaint::TextureManager>>);
|
struct WrappedTextureManager(Arc<parking_lot::RwLock<epaint::TextureManager>>);
|
||||||
|
|
||||||
impl Default for WrappedTextureManager {
|
impl Default for WrappedTextureManager {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
@ -25,7 +27,7 @@ impl Default for WrappedTextureManager {
|
||||||
);
|
);
|
||||||
assert_eq!(font_id, TextureId::default());
|
assert_eq!(font_id, TextureId::default());
|
||||||
|
|
||||||
Self(Arc::new(RwLock::new(tex_mngr)))
|
Self(Arc::new(parking_lot::RwLock::new(tex_mngr)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +165,9 @@ impl ContextImpl {
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
ctx: Arc<RwLock<ContextImpl>>,
|
ctx: Arc<RwLock<ContextImpl>>,
|
||||||
|
// These are not inside of `ContextImpl` because we want to have thread-safe access to them
|
||||||
|
// even without running with the multi_threaded feature flag.
|
||||||
|
// See https://github.com/emilk/egui/issues/1379.
|
||||||
repaint_info: Arc<RepaintInfo>,
|
repaint_info: Arc<RepaintInfo>,
|
||||||
tex_manager: WrappedTextureManager,
|
tex_manager: WrappedTextureManager,
|
||||||
}
|
}
|
||||||
|
@ -731,7 +736,7 @@ impl Context {
|
||||||
/// You can show stats about the allocated textures using [`Self::texture_ui`].
|
/// You can show stats about the allocated textures using [`Self::texture_ui`].
|
||||||
///
|
///
|
||||||
/// This is safe to call from any thread at any time.
|
/// This is safe to call from any thread at any time.
|
||||||
pub fn tex_manager(&self) -> Arc<RwLock<epaint::textures::TextureManager>> {
|
pub fn tex_manager(&self) -> Arc<parking_lot::RwLock<epaint::textures::TextureManager>> {
|
||||||
self.tex_manager.0.clone()
|
self.tex_manager.0.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ single_threaded = ["atomic_refcell"]
|
||||||
|
|
||||||
# Only needed if you plan to use the same fonts from multiple threads.
|
# Only needed if you plan to use the same fonts from multiple threads.
|
||||||
# It comes with a minor performance impact.
|
# It comes with a minor performance impact.
|
||||||
multi_threaded = ["parking_lot"]
|
multi_threaded = []
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -63,7 +63,7 @@ atomic_refcell = { version = "0.1", optional = true } # Used
|
||||||
bytemuck = { version = "1.7.2", optional = true, features = ["derive"] }
|
bytemuck = { version = "1.7.2", optional = true, features = ["derive"] }
|
||||||
cint = { version = "^0.2.2", optional = true }
|
cint = { version = "^0.2.2", optional = true }
|
||||||
nohash-hasher = "0.2"
|
nohash-hasher = "0.2"
|
||||||
parking_lot = { version = "0.12", optional = true } # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios.
|
parking_lot = "0.12"
|
||||||
serde = { version = "1", optional = true, features = ["derive", "rc"] }
|
serde = { version = "1", optional = true, features = ["derive", "rc"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::{
|
use crate::{emath::NumExt, mutex::Arc, ImageData, ImageDelta, TextureId, TextureManager};
|
||||||
emath::NumExt,
|
|
||||||
mutex::{Arc, RwLock},
|
use parking_lot::RwLock;
|
||||||
ImageData, ImageDelta, TextureId, TextureManager,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Used to paint images.
|
/// Used to paint images.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue