diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 5381d3228cb..397d7fd36df 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -19,7 +19,7 @@ Examples: `Vec2, Pos2, Rect, lerp, remap` Example: `Shape::Circle { center, radius, fill, stroke }` -Depends on `emath`, [`ab_glyph`](https://crates.io/crates/ab_glyph), [`atomic_refcell`](https://crates.io/crates/atomic_refcell), [`ahash`](https://crates.io/crates/ahash). +Depends on `emath`. ### `egui_extras` This adds additional features on top of `egui`. diff --git a/CHANGELOG.md b/CHANGELOG.md index 3612db7098a..91875ac8dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,11 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w ### Fixed 🐛 * Fixed ComboBoxes always being rendered left-aligned ([#1304](https://github.com/emilk/egui/pull/1304)). -* Fixed ui code that could lead to a deadlock ([#1380](https://github.com/emilk/egui/pull/1380)) +* Fixed ui code that could lead to a deadlock ([#1380](https://github.com/emilk/egui/pull/1380)). + +### Removed 🔥 +* Removed the `single_threaded/multi_threaded` flags - egui is now always thread-safe ([#1390](https://github.com/emilk/egui/pull/1390)). + ## 0.17.0 - 2022-02-22 - Improved font selection and image handling diff --git a/Cargo.lock b/Cargo.lock index 30384431c02..7c1e66bf3aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -203,12 +203,6 @@ dependencies = [ "system-deps", ] -[[package]] -name = "atomic_refcell" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b5e5f48b927f04e952dedc932f31995a65a0bf65ec971c74436e51bf6e970d" - [[package]] name = "atty" version = "0.2.14" @@ -1206,7 +1200,6 @@ version = "0.17.0" dependencies = [ "ab_glyph", "ahash 0.7.6", - "atomic_refcell", "bytemuck", "cint", "criterion", diff --git a/README.md b/README.md index 2b058698fc3..f8c4ef3a578 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ On Fedora Rawhide you need to run: * Extensible: [easy to write your own widgets for egui](https://github.com/emilk/egui/blob/master/egui_demo_lib/src/apps/demo/toggle_switch.rs) * Modular: You should be able to use small parts of egui and combine them in new ways * Safe: there is no `unsafe` code in egui -* Minimal dependencies: [`ab_glyph`](https://crates.io/crates/ab_glyph) [`ahash`](https://crates.io/crates/ahash) [`atomic_refcell`](https://crates.io/crates/atomic_refcell), [`nohash-hasher`](https://crates.io/crates/nohash-hasher) +* Minimal dependencies: [`ab_glyph`](https://crates.io/crates/ab_glyph) [`ahash`](https://crates.io/crates/ahash) [`nohash-hasher`](https://crates.io/crates/nohash-hasher) [`parking_lot`](https://crates.io/crates/parking_lot) egui is *not* a framework. egui is a library you call into, not an environment you program for. diff --git a/egui-winit/Cargo.toml b/egui-winit/Cargo.toml index a7cde96f905..c27d9cca845 100644 --- a/egui-winit/Cargo.toml +++ b/egui-winit/Cargo.toml @@ -45,7 +45,6 @@ serialize = ["egui/serialize", "serde"] [dependencies] egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ - "single_threaded", "tracing", ] } instant = { version = "0.1", features = ["wasm-bindgen"] } diff --git a/egui/Cargo.toml b/egui/Cargo.toml index b99087a0b2f..b51c8e70028 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -20,7 +20,7 @@ all-features = true [features] -default = ["default_fonts", "single_threaded"] +default = ["default_fonts"] # add compatibility with https://crates.io/crates/cint cint = ["epaint/cint"] @@ -46,11 +46,6 @@ persistence = ["serde", "epaint/serialize", "ron"] # implement serde on most types. serialize = ["serde", "epaint/serialize"] -# multi_threaded is only needed if you plan to use the same egui::Context -# from multiple threads. It comes with a minor performance impact. -single_threaded = ["epaint/single_threaded"] -multi_threaded = ["epaint/multi_threaded"] - [dependencies] epaint = { version = "0.17.0", path = "../epaint", default-features = false } diff --git a/egui_extras/Cargo.toml b/egui_extras/Cargo.toml index 63c31f96576..09ea707f357 100644 --- a/egui_extras/Cargo.toml +++ b/egui_extras/Cargo.toml @@ -27,9 +27,7 @@ svg = ["resvg", "tiny-skia", "usvg"] [dependencies] -egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ - "single_threaded", -] } +egui = { version = "0.17.0", path = "../egui", default-features = false } parking_lot = "0.12" # Optional dependencies: @@ -37,7 +35,7 @@ parking_lot = "0.12" # Add support for loading images with the `image` crate. # You also need to ALSO opt-in to the image formats you want to support, like so: # image = { version = "0.24", features = ["jpeg", "png"] } -image = { version = "0.24", optional = true, default-features = false, features = [] } +image = { version = "0.24", optional = true, default-features = false } # svg feature resvg = { version = "0.22", optional = true } diff --git a/egui_glium/Cargo.toml b/egui_glium/Cargo.toml index b23a7a610d7..8ef557917d0 100644 --- a/egui_glium/Cargo.toml +++ b/egui_glium/Cargo.toml @@ -47,7 +47,6 @@ screen_reader = ["egui-winit/screen_reader"] [dependencies] egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ "convert_bytemuck", - "single_threaded", ] } egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false } diff --git a/egui_glow/Cargo.toml b/egui_glow/Cargo.toml index 90dfa48620b..fbf5202619d 100644 --- a/egui_glow/Cargo.toml +++ b/egui_glow/Cargo.toml @@ -57,7 +57,6 @@ winit = ["egui-winit", "glutin"] [dependencies] egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ "convert_bytemuck", - "single_threaded", ] } epi = { version = "0.17.0", path = "../epi", optional = true } diff --git a/egui_web/Cargo.toml b/egui_web/Cargo.toml index 5994f9d1a8b..7f9b09fc9f0 100644 --- a/egui_web/Cargo.toml +++ b/egui_web/Cargo.toml @@ -43,7 +43,6 @@ screen_reader = ["tts"] [dependencies] egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ "convert_bytemuck", - "single_threaded", "tracing", ] } egui_glow = { version = "0.17.0", path = "../egui_glow", default-features = false } diff --git a/epaint/CHANGELOG.md b/epaint/CHANGELOG.md index 9a3007048b1..ec709f69600 100644 --- a/epaint/CHANGELOG.md +++ b/epaint/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to the epaint crate will be documented in this file. ## Unreleased * Add `Shape::Callback` for backend-specific painting ([#1351](https://github.com/emilk/egui/pull/1351)). +* Removed the `single_threaded/multi_threaded` flags - epaint is now always thread-safe ([#1390](https://github.com/emilk/egui/pull/1390)). ## 0.17.0 - 2022-02-22 diff --git a/epaint/Cargo.toml b/epaint/Cargo.toml index 4c6ef6a219b..3b42c78825e 100644 --- a/epaint/Cargo.toml +++ b/epaint/Cargo.toml @@ -27,7 +27,7 @@ all-features = true [features] -default = ["default_fonts", "multi_threaded"] +default = ["default_fonts"] # implement bytemuck on most types. convert_bytemuck = ["bytemuck", "emath/bytemuck"] @@ -47,23 +47,16 @@ mint = ["emath/mint"] # implement serde on most types. serialize = ["serde", "ahash/serde", "emath/serde"] -single_threaded = ["atomic_refcell"] - -# Only needed if you plan to use the same fonts from multiple threads. -# It comes with a minor performance impact. -multi_threaded = ["parking_lot"] - [dependencies] emath = { version = "0.17.0", path = "../emath" } ab_glyph = "0.2.11" ahash = { version = "0.7", default-features = false, features = ["std"] } -atomic_refcell = { version = "0.1", optional = true } # Used instead of parking_lot when you are always using epaint in a single thread. About as fast as parking_lot. Panics on multi-threaded use. bytemuck = { version = "1.7.2", optional = true, features = ["derive"] } cint = { version = "^0.2.2", optional = true } 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" # Using parking_lot over std::sync::Mutex gives 50% speedups in some real-world scenarios. serde = { version = "1", optional = true, features = ["derive", "rc"] } [dev-dependencies] diff --git a/epaint/src/mutex.rs b/epaint/src/mutex.rs index fa0e939e108..1d73ff7d799 100644 --- a/epaint/src/mutex.rs +++ b/epaint/src/mutex.rs @@ -1,16 +1,10 @@ //! Helper module that wraps some Mutex types with different implementations. -//! -//! When the `single_threaded` feature is on the mutexes will panic when locked from different threads. - -#[cfg(not(any(feature = "single_threaded", feature = "multi_threaded")))] -compile_error!("Either feature \"single_threaded\" or \"multi_threaded\" must be enabled."); // ---------------------------------------------------------------------------- -#[cfg(feature = "multi_threaded")] #[cfg(not(debug_assertions))] mod mutex_impl { - /// Provides interior mutability. Only thread-safe if the `multi_threaded` feature is enabled. + /// Provides interior mutability. #[derive(Default)] pub struct Mutex(parking_lot::Mutex); @@ -30,10 +24,9 @@ mod mutex_impl { } } -#[cfg(feature = "multi_threaded")] #[cfg(debug_assertions)] mod mutex_impl { - /// Provides interior mutability. Only thread-safe if the `multi_threaded` feature is enabled. + /// Provides interior mutability. #[derive(Default)] pub struct Mutex(parking_lot::Mutex); @@ -111,7 +104,6 @@ mod mutex_impl { } } -#[cfg(feature = "multi_threaded")] mod rw_lock_impl { /// The lock you get from [`RwLock::read`]. pub use parking_lot::MappedRwLockReadGuard as RwLockReadGuard; @@ -119,7 +111,7 @@ mod rw_lock_impl { /// The lock you get from [`RwLock::write`]. pub use parking_lot::MappedRwLockWriteGuard as RwLockWriteGuard; - /// Provides interior mutability. Only thread-safe if the `multi_threaded` feature is enabled. + /// Provides interior mutability. #[derive(Default)] pub struct RwLock(parking_lot::RwLock); @@ -141,74 +133,7 @@ mod rw_lock_impl { } } -#[cfg(feature = "multi_threaded")] -mod arc_impl { - pub use std::sync::Arc; -} - -// ---------------------------------------------------------------------------- - -#[cfg(not(feature = "multi_threaded"))] -mod mutex_impl { - // `atomic_refcell` will panic if multiple threads try to access the same value - - /// Provides interior mutability. Only thread-safe if the `multi_threaded` feature is enabled. - #[derive(Default)] - pub struct Mutex(atomic_refcell::AtomicRefCell); - - /// The lock you get from [`Mutex`]. - pub use atomic_refcell::AtomicRefMut as MutexGuard; - - impl Mutex { - #[inline(always)] - pub fn new(val: T) -> Self { - Self(atomic_refcell::AtomicRefCell::new(val)) - } - - /// Panics if already locked. - #[inline(always)] - pub fn lock(&self) -> MutexGuard<'_, T> { - self.0.borrow_mut() - } - } -} - -#[cfg(not(feature = "multi_threaded"))] -mod rw_lock_impl { - // `atomic_refcell` will panic if multiple threads try to access the same value - - /// The lock you get from [`RwLock::read`]. - pub use atomic_refcell::AtomicRef as RwLockReadGuard; - - /// The lock you get from [`RwLock::write`]. - pub use atomic_refcell::AtomicRefMut as RwLockWriteGuard; - - /// Provides interior mutability. Only thread-safe if the `multi_threaded` feature is enabled. - #[derive(Default)] - pub struct RwLock(atomic_refcell::AtomicRefCell); - - impl RwLock { - #[inline(always)] - pub fn new(val: T) -> Self { - Self(atomic_refcell::AtomicRefCell::new(val)) - } - - #[inline(always)] - pub fn read(&self) -> RwLockReadGuard<'_, T> { - self.0.borrow() - } - - /// Panics if already locked. - #[inline(always)] - pub fn write(&self) -> RwLockWriteGuard<'_, T> { - self.0.borrow_mut() - } - } -} - -#[cfg(not(feature = "multi_threaded"))] mod arc_impl { - // pub use std::rc::Rc as Arc; // TODO(emilk): optimize single threaded code by using `Rc` instead of `Arc`. pub use std::sync::Arc; } diff --git a/epi/Cargo.toml b/epi/Cargo.toml index 4e894a62114..a62005eb0e4 100644 --- a/epi/Cargo.toml +++ b/epi/Cargo.toml @@ -28,9 +28,7 @@ persistence = ["ron", "serde", "egui/persistence"] [dependencies] -egui = { version = "0.17.0", path = "../egui", default-features = false, features = [ - "single_threaded", -] } +egui = { version = "0.17.0", path = "../egui", default-features = false } glow = "0.11" tracing = "0.1" diff --git a/sh/check.sh b/sh/check.sh index e2d8bd35b56..2a319cf417f 100755 --- a/sh/check.sh +++ b/sh/check.sh @@ -20,17 +20,15 @@ cargo doc -p egui_web --target wasm32-unknown-unknown --lib --no-deps --all-feat cargo doc --document-private-items --no-deps --all-features (cd emath && cargo check --no-default-features) -(cd epaint && cargo check --no-default-features --features "single_threaded") -(cd epaint && cargo check --no-default-features --features "multi_threaded") -(cd epaint && cargo check --no-default-features --features "single_threaded" --release) -(cd epaint && cargo check --no-default-features --features "multi_threaded" --release) -(cd egui && cargo check --no-default-features --features "multi_threaded,serialize") +(cd epaint && cargo check --no-default-features) +(cd epaint && cargo check --no-default-features --release) +(cd egui && cargo check --no-default-features --features "serialize") (cd eframe && cargo check --no-default-features) (cd epi && cargo check --no-default-features) (cd egui_demo_lib && cargo check --no-default-features) (cd egui_extras && cargo check --no-default-features) (cd egui_web && cargo check --no-default-features) -# (cd egui-winit && cargo check --no-default-features) # we don't pick singlethreaded or multithreaded +(cd egui-winit && cargo check --no-default-features) (cd egui_glium && cargo check --no-default-features) (cd egui_glow && cargo check --no-default-features)