diff options
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | CHANGELOG.md | 16 | ||||
-rw-r--r-- | Cargo.lock | 237 | ||||
-rw-r--r-- | Cargo.toml | 46 | ||||
-rw-r--r-- | Cargo.toml.orig | 5 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | benches/pin.rs | 2 | ||||
-rw-r--r-- | build.rs | 15 | ||||
-rw-r--r-- | no_atomic.rs | 22 | ||||
-rw-r--r-- | src/atomic.rs | 67 | ||||
-rw-r--r-- | src/collector.rs | 30 | ||||
-rw-r--r-- | src/deferred.rs | 11 | ||||
-rw-r--r-- | src/internal.rs | 6 | ||||
-rw-r--r-- | src/sync/queue.rs | 7 |
15 files changed, 398 insertions, 87 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 1f53d5d..0a948d5 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,6 @@ { "git": { - "sha1": "6d4cdd4daf9a897deef6cde9569f2fbf12c29bc5" - } -} + "sha1": "2988f873f87d2263a7fd2b9465fb9c28f43a6490" + }, + "path_in_vcs": "crossbeam-epoch" +}
\ No newline at end of file @@ -44,7 +44,7 @@ rust_test { host_supported: true, crate_name: "crossbeam_epoch", cargo_env_compat: true, - cargo_pkg_version: "0.9.5", + cargo_pkg_version: "0.9.7", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -73,7 +73,7 @@ rust_library { host_supported: true, crate_name: "crossbeam_epoch", cargo_env_compat: true, - cargo_pkg_version: "0.9.5", + cargo_pkg_version: "0.9.7", srcs: ["src/lib.rs"], edition: "2018", features: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index c78fbf8..8c158f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,20 @@ +# Version 0.9.7 + +- Fix Miri error when `-Zmiri-check-number-validity` is enabled. (#779) + +# Version 0.9.6 + +- Add `Atomic::fetch_update`. (#706) + # Version 0.9.5 -- Fix UB in `Pointable` impl of `[MaybeUninit<T>]` (#694) -- Support targets that do not have atomic CAS on stable Rust (#698) -- Fix breakage with nightly feature due to rust-lang/rust#84510 (#692) +- Fix UB in `Pointable` impl of `[MaybeUninit<T>]`. (#694) +- Support targets that do not have atomic CAS on stable Rust. (#698) +- Fix breakage with nightly feature due to rust-lang/rust#84510. (#692) # Version 0.9.4 -- Fix UB in `<[MaybeUninit<T>] as Pointable>::init` when global allocator failed allocation (#690) +- Fix UB in `<[MaybeUninit<T>] as Pointable>::init` when global allocator failed allocation. (#690) - Bump `loom` dependency to version 0.5. (#686) # Version 0.9.3 @@ -3,6 +3,15 @@ version = 3 [[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -10,9 +19,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cfg-if" @@ -22,13 +31,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const_fn" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" [[package]] name = "crossbeam-epoch" -version = "0.9.5" +version = "0.9.7" dependencies = [ "cfg-if", "const_fn", @@ -42,9 +51,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6" dependencies = [ "cfg-if", "lazy_static", @@ -66,9 +75,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" dependencies = [ "cfg-if", "libc", @@ -83,9 +92,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" [[package]] name = "log" @@ -98,35 +107,76 @@ dependencies = [ [[package]] name = "loom" -version = "0.5.0" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aa5348dc45fa5f2419b6dd4ea20345e6b01b1fcc9d176a322eada1ac3f382ba" +checksum = "edc5c7d328e32cc4954e8e01193d7f0ef5ab257b5090b70a964e099a36034309" dependencies = [ "cfg-if", "generator", "scoped-tls", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", ] [[package]] name = "memoffset" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ "autocfg", ] [[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "pin-project-lite" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" + +[[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" +dependencies = [ + "proc-macro2", +] [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", @@ -136,9 +186,9 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", "rand_core", @@ -146,27 +196,51 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ "rand_core", ] [[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] name = "rustversion" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" +checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" [[package]] name = "scoped-tls" @@ -181,6 +255,115 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "syn" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d8d93354fe2a8e50d5953f5ae2e47a3fc2ef03292e7ea46e3cc38f549525fb9" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23" +dependencies = [ + "lazy_static", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa" +dependencies = [ + "ansi_term", + "lazy_static", + "matchers", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3,25 +3,33 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" +rust-version = "1.36" name = "crossbeam-epoch" -version = "0.9.5" -authors = ["The Crossbeam Project Developers"] +version = "0.9.7" description = "Epoch-based garbage collection" homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch" -documentation = "https://docs.rs/crossbeam-epoch" -keywords = ["lock-free", "rcu", "atomic", "garbage"] -categories = ["concurrency", "memory-management", "no-std"] +keywords = [ + "lock-free", + "rcu", + "atomic", + "garbage", +] +categories = [ + "concurrency", + "memory-management", + "no-std", +] license = "MIT OR Apache-2.0" repository = "https://github.com/crossbeam-rs/crossbeam" + [dependencies.cfg-if] version = "1" @@ -43,15 +51,27 @@ version = "0.6" [dependencies.scopeguard] version = "1.1.0" default-features = false + [dev-dependencies.rand] version = "0.8" [features] alloc = [] default = ["std"] -loom = ["loom-crate", "crossbeam-utils/loom"] -nightly = ["crossbeam-utils/nightly", "const_fn"] -std = ["alloc", "crossbeam-utils/std", "lazy_static"] +loom = [ + "loom-crate", + "crossbeam-utils/loom", +] +nightly = [ + "crossbeam-utils/nightly", + "const_fn", +] +std = [ + "alloc", + "crossbeam-utils/std", + "lazy_static", +] + [target."cfg(crossbeam_loom)".dependencies.loom-crate] version = "0.5" optional = true diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 939e346..bdb095a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -4,13 +4,12 @@ name = "crossbeam-epoch" # - Update CHANGELOG.md # - Update README.md # - Create "crossbeam-epoch-X.Y.Z" git tag -version = "0.9.5" -authors = ["The Crossbeam Project Developers"] +version = "0.9.7" edition = "2018" +rust-version = "1.36" license = "MIT OR Apache-2.0" repository = "https://github.com/crossbeam-rs/crossbeam" homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch" -documentation = "https://docs.rs/crossbeam-epoch" description = "Epoch-based garbage collection" keywords = ["lock-free", "rcu", "atomic", "garbage"] categories = ["concurrency", "memory-management", "no-std"] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/crossbeam-epoch/crossbeam-epoch-0.9.5.crate" + value: "https://static.crates.io/crates/crossbeam-epoch/crossbeam-epoch-0.9.7.crate" } - version: "0.9.5" + version: "0.9.7" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 6 - day: 21 + year: 2022 + month: 3 + day: 1 } } diff --git a/benches/pin.rs b/benches/pin.rs index 0dff4c5..8bf87e9 100644 --- a/benches/pin.rs +++ b/benches/pin.rs @@ -8,7 +8,7 @@ use test::Bencher; #[bench] fn single_pin(b: &mut Bencher) { - b.iter(|| epoch::pin()); + b.iter(epoch::pin); } #[bench] @@ -1,12 +1,21 @@ +// The rustc-cfg listed below are considered public API, but it is *unstable* +// and outside of the normal semver guarantees: +// +// - `crossbeam_no_atomic_cas` +// Assume the target does *not* support atomic CAS operations. +// This is usually detected automatically by the build script, but you may +// need to enable it manually when building for custom targets or using +// non-cargo build systems that don't run the build script. +// +// With the exceptions mentioned above, the rustc-cfg emitted by the build +// script are *not* public API. + #![warn(rust_2018_idioms)] use std::env; include!("no_atomic.rs"); -// The rustc-cfg strings below are *not* public API. Please let us know by -// opening a GitHub issue if your build environment requires some way to enable -// these cfgs other than by executing our build script. fn main() { let target = match env::var("TARGET") { Ok(target) => target, diff --git a/no_atomic.rs b/no_atomic.rs index 522b3b8..90ac60a 100644 --- a/no_atomic.rs +++ b/no_atomic.rs @@ -3,13 +3,16 @@ const NO_ATOMIC_CAS: &[&str] = &[ "avr-unknown-gnu-atmega328", + "bpfeb-unknown-none", + "bpfel-unknown-none", "msp430-none-elf", "riscv32i-unknown-none-elf", "riscv32imc-unknown-none-elf", "thumbv4t-none-eabi", "thumbv6m-none-eabi", ]; -#[allow(dead_code)] + +#[allow(dead_code)] // Only crossbeam-utils uses this. const NO_ATOMIC_64: &[&str] = &[ "arm-linux-androideabi", "armebv7r-none-eabi", @@ -18,18 +21,24 @@ const NO_ATOMIC_64: &[&str] = &[ "armv5te-unknown-linux-gnueabi", "armv5te-unknown-linux-musleabi", "armv5te-unknown-linux-uclibceabi", + "armv6k-nintendo-3ds", "armv7r-none-eabi", "armv7r-none-eabihf", + "avr-unknown-gnu-atmega328", "hexagon-unknown-linux-musl", + "m68k-unknown-linux-gnu", "mips-unknown-linux-gnu", "mips-unknown-linux-musl", "mips-unknown-linux-uclibc", + "mipsel-sony-psp", "mipsel-unknown-linux-gnu", "mipsel-unknown-linux-musl", "mipsel-unknown-linux-uclibc", "mipsel-unknown-none", "mipsisa32r6-unknown-linux-gnu", "mipsisa32r6el-unknown-linux-gnu", + "msp430-none-elf", + "powerpc-unknown-freebsd", "powerpc-unknown-linux-gnu", "powerpc-unknown-linux-gnuspe", "powerpc-unknown-linux-musl", @@ -39,18 +48,21 @@ const NO_ATOMIC_64: &[&str] = &[ "powerpc-wrs-vxworks-spe", "riscv32gc-unknown-linux-gnu", "riscv32gc-unknown-linux-musl", + "riscv32i-unknown-none-elf", "riscv32imac-unknown-none-elf", + "riscv32imc-esp-espidf", + "riscv32imc-unknown-none-elf", + "thumbv4t-none-eabi", + "thumbv6m-none-eabi", "thumbv7em-none-eabi", "thumbv7em-none-eabihf", "thumbv7m-none-eabi", "thumbv8m.base-none-eabi", "thumbv8m.main-none-eabi", "thumbv8m.main-none-eabihf", - "mipsel-sony-psp", - "thumbv4t-none-eabi", - "thumbv6m-none-eabi", ]; -#[allow(dead_code)] + +#[allow(dead_code)] // Only crossbeam-utils uses this. const NO_ATOMIC: &[&str] = &[ "avr-unknown-gnu-atmega328", "msp430-none-elf", diff --git a/src/atomic.rs b/src/atomic.rs index adb0afa..f727387 100644 --- a/src/atomic.rs +++ b/src/atomic.rs @@ -562,6 +562,65 @@ impl<T: ?Sized + Pointable> Atomic<T> { }) } + /// Fetches the pointer, and then applies a function to it that returns a new value. + /// Returns a `Result` of `Ok(previous_value)` if the function returned `Some`, else `Err(_)`. + /// + /// Note that the given function may be called multiple times if the value has been changed by + /// other threads in the meantime, as long as the function returns `Some(_)`, but the function + /// will have been applied only once to the stored value. + /// + /// `fetch_update` takes two [`Ordering`] arguments to describe the memory + /// ordering of this operation. The first describes the required ordering for + /// when the operation finally succeeds while the second describes the + /// required ordering for loads. These correspond to the success and failure + /// orderings of [`Atomic::compare_exchange`] respectively. + /// + /// Using [`Acquire`] as success ordering makes the store part of this + /// operation [`Relaxed`], and using [`Release`] makes the final successful + /// load [`Relaxed`]. The (failed) load ordering can only be [`SeqCst`], + /// [`Acquire`] or [`Relaxed`] and must be equivalent to or weaker than the + /// success ordering. + /// + /// [`Relaxed`]: Ordering::Relaxed + /// [`Acquire`]: Ordering::Acquire + /// [`Release`]: Ordering::Release + /// [`SeqCst`]: Ordering::SeqCst + /// + /// # Examples + /// + /// ``` + /// use crossbeam_epoch::{self as epoch, Atomic}; + /// use std::sync::atomic::Ordering::SeqCst; + /// + /// let a = Atomic::new(1234); + /// let guard = &epoch::pin(); + /// + /// let res1 = a.fetch_update(SeqCst, SeqCst, guard, |x| Some(x.with_tag(1))); + /// assert!(res1.is_ok()); + /// + /// let res2 = a.fetch_update(SeqCst, SeqCst, guard, |x| None); + /// assert!(res2.is_err()); + /// ``` + pub fn fetch_update<'g, F>( + &self, + set_order: Ordering, + fail_order: Ordering, + guard: &'g Guard, + mut func: F, + ) -> Result<Shared<'g, T>, Shared<'g, T>> + where + F: FnMut(Shared<'g, T>) -> Option<Shared<'g, T>>, + { + let mut prev = self.load(fail_order, guard); + while let Some(next) = func(prev) { + match self.compare_exchange_weak(prev, next, set_order, fail_order, guard) { + Ok(shared) => return Ok(shared), + Err(next_prev) => prev = next_prev.current, + } + } + Err(prev) + } + /// Stores the pointer `new` (either `Shared` or `Owned`) into the atomic pointer if the current /// value is the same as `current`. The tag is also taken into account, so two pointers to the /// same object, but with different tags, will not be considered equal. @@ -1225,7 +1284,6 @@ impl<'g, T> Shared<'g, T> { /// let p = a.load(SeqCst, guard); /// assert_eq!(p.as_raw(), raw); /// ``` - #[allow(clippy::trivially_copy_pass_by_ref)] pub fn as_raw(&self) -> *const T { let (raw, _) = decompose_tag::<T>(self.data); raw as *const _ @@ -1264,7 +1322,6 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> { /// a.store(Owned::new(1234), SeqCst); /// assert!(!a.load(SeqCst, guard).is_null()); /// ``` - #[allow(clippy::trivially_copy_pass_by_ref)] pub fn is_null(&self) -> bool { let (raw, _) = decompose_tag::<T>(self.data); raw == 0 @@ -1301,8 +1358,6 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> { /// assert_eq!(p.deref(), &1234); /// } /// ``` - #[allow(clippy::trivially_copy_pass_by_ref)] - #[allow(clippy::should_implement_trait)] pub unsafe fn deref(&self) -> &'g T { let (raw, _) = decompose_tag::<T>(self.data); T::deref(raw) @@ -1344,7 +1399,6 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> { /// assert_eq!(p.deref(), &vec![1, 2, 3, 4, 5]); /// } /// ``` - #[allow(clippy::should_implement_trait)] pub unsafe fn deref_mut(&mut self) -> &'g mut T { let (raw, _) = decompose_tag::<T>(self.data); T::deref_mut(raw) @@ -1381,7 +1435,6 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> { /// assert_eq!(p.as_ref(), Some(&1234)); /// } /// ``` - #[allow(clippy::trivially_copy_pass_by_ref)] pub unsafe fn as_ref(&self) -> Option<&'g T> { let (raw, _) = decompose_tag::<T>(self.data); if raw == 0 { @@ -1433,7 +1486,6 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> { /// let p = a.load(SeqCst, guard); /// assert_eq!(p.tag(), 2); /// ``` - #[allow(clippy::trivially_copy_pass_by_ref)] pub fn tag(&self) -> usize { let (_, tag) = decompose_tag::<T>(self.data); tag @@ -1457,7 +1509,6 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> { /// assert_eq!(p2.tag(), 2); /// assert_eq!(p1.as_raw(), p2.as_raw()); /// ``` - #[allow(clippy::trivially_copy_pass_by_ref)] pub fn with_tag(&self, tag: usize) -> Shared<'g, T> { unsafe { Self::from_usize(compose_tag::<T>(self.data, tag)) } } diff --git a/src/collector.rs b/src/collector.rs index 7cfb819..099a2ff 100644 --- a/src/collector.rs +++ b/src/collector.rs @@ -178,13 +178,18 @@ mod tests { #[test] fn pin_holds_advance() { + #[cfg(miri)] + const N: usize = 500; + #[cfg(not(miri))] + const N: usize = 500_000; + let collector = Collector::new(); thread::scope(|scope| { for _ in 0..NUM_THREADS { scope.spawn(|_| { let handle = collector.register(); - for _ in 0..500_000 { + for _ in 0..N { let guard = &handle.pin(); let before = collector.global.epoch.load(Ordering::Relaxed); @@ -202,6 +207,9 @@ mod tests { #[cfg(not(crossbeam_sanitize))] // TODO: assertions failed due to `cfg(crossbeam_sanitize)` reduce `internal::MAX_OBJECTS` #[test] fn incremental() { + #[cfg(miri)] + const COUNT: usize = 500; + #[cfg(not(miri))] const COUNT: usize = 100_000; static DESTROYS: AtomicUsize = AtomicUsize::new(0); @@ -230,12 +238,16 @@ mod tests { let guard = &handle.pin(); collector.global.collect(guard); } - assert!(DESTROYS.load(Ordering::Relaxed) == 100_000); + assert!(DESTROYS.load(Ordering::Relaxed) == COUNT); } #[test] fn buffering() { const COUNT: usize = 10; + #[cfg(miri)] + const N: usize = 500; + #[cfg(not(miri))] + const N: usize = 100_000; static DESTROYS: AtomicUsize = AtomicUsize::new(0); let collector = Collector::new(); @@ -252,7 +264,7 @@ mod tests { } } - for _ in 0..100_000 { + for _ in 0..N { collector.global.collect(&handle.pin()); } assert!(DESTROYS.load(Ordering::Relaxed) < COUNT); @@ -268,6 +280,9 @@ mod tests { #[test] fn count_drops() { + #[cfg(miri)] + const COUNT: usize = 500; + #[cfg(not(miri))] const COUNT: usize = 100_000; static DROPS: AtomicUsize = AtomicUsize::new(0); @@ -301,6 +316,9 @@ mod tests { #[test] fn count_destroy() { + #[cfg(miri)] + const COUNT: usize = 500; + #[cfg(not(miri))] const COUNT: usize = 100_000; static DESTROYS: AtomicUsize = AtomicUsize::new(0); @@ -367,6 +385,9 @@ mod tests { #[test] fn destroy_array() { + #[cfg(miri)] + const COUNT: usize = 500; + #[cfg(not(miri))] const COUNT: usize = 100_000; static DESTROYS: AtomicUsize = AtomicUsize::new(0); @@ -402,6 +423,9 @@ mod tests { #[test] fn stress() { const THREADS: usize = 8; + #[cfg(miri)] + const COUNT: usize = 500; + #[cfg(not(miri))] const COUNT: usize = 100_000; static DROPS: AtomicUsize = AtomicUsize::new(0); diff --git a/src/deferred.rs b/src/deferred.rs index d953c46..c33d515 100644 --- a/src/deferred.rs +++ b/src/deferred.rs @@ -18,7 +18,7 @@ type Data = [usize; DATA_WORDS]; /// This is a handy way of keeping an unsized `FnOnce()` within a sized structure. pub(crate) struct Deferred { call: unsafe fn(*mut u8), - data: Data, + data: MaybeUninit<Data>, _marker: PhantomData<*mut ()>, // !Send + !Sync } @@ -46,7 +46,7 @@ impl Deferred { Deferred { call: call::<F>, - data: data.assume_init(), + data, _marker: PhantomData, } } else { @@ -57,14 +57,13 @@ impl Deferred { unsafe fn call<F: FnOnce()>(raw: *mut u8) { // It's safe to cast `raw` from `*mut u8` to `*mut Box<F>`, because `raw` is // originally derived from `*mut Box<F>`. - #[allow(clippy::cast_ptr_alignment)] let b: Box<F> = ptr::read(raw as *mut Box<F>); (*b)(); } Deferred { call: call::<F>, - data: data.assume_init(), + data, _marker: PhantomData, } } @@ -75,12 +74,14 @@ impl Deferred { #[inline] pub(crate) fn call(mut self) { let call = self.call; - unsafe { call(&mut self.data as *mut Data as *mut u8) }; + unsafe { call(self.data.as_mut_ptr() as *mut u8) }; } } #[cfg(all(test, not(crossbeam_loom)))] mod tests { + #![allow(clippy::drop_copy)] + use super::Deferred; use std::cell::Cell; diff --git a/src/internal.rs b/src/internal.rs index 966bceb..de208b1 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -101,7 +101,7 @@ impl Bag { /// Seals the bag with the given epoch. fn seal(self, epoch: Epoch) -> SealedBag { - SealedBag { epoch, bag: self } + SealedBag { epoch, _bag: self } } } @@ -216,7 +216,7 @@ fn no_op_func() {} #[derive(Default, Debug)] struct SealedBag { epoch: Epoch, - bag: Bag, + _bag: Bag, } /// It is safe to share `SealedBag` because `is_expired` only inspects the epoch. @@ -311,7 +311,7 @@ impl Global { // TODO(stjepang): `Local`s are stored in a linked list because linked lists are fairly // easy to implement in a lock-free manner. However, traversal can be slow due to cache // misses and data dependencies. We should experiment with other data structures as well. - for local in self.locals.iter(&guard) { + for local in self.locals.iter(guard) { match local { Err(IterError::Stalled) => { // A concurrent thread stalled this iteration. That thread might also try to diff --git a/src/sync/queue.rs b/src/sync/queue.rs index 67c228d..9500438 100644 --- a/src/sync/queue.rs +++ b/src/sync/queue.rs @@ -259,6 +259,9 @@ mod test { } } + #[cfg(miri)] + const CONC_COUNT: i64 = 1000; + #[cfg(not(miri))] const CONC_COUNT: i64 = 1000000; #[test] @@ -422,8 +425,8 @@ mod test { let mut vl2 = vl.clone(); let mut vr2 = vr.clone(); - vl2.sort(); - vr2.sort(); + vl2.sort_unstable(); + vr2.sort_unstable(); assert_eq!(vl, vl2); assert_eq!(vr, vr2); |