aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-01 22:46:13 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-01 22:46:13 +0000
commite4d3376a3df60fe5f31dcf0611a8734618aac921 (patch)
tree02c7430dc5e4272fb43b84401cdb6d50e9ed8a4b
parent68da8abf9dd835bd0b38a0d93f2cea5ec3bd0186 (diff)
parent49ee284a3871459d277edba0e1ad361bd5936bd9 (diff)
downloadcrossbeam-epoch-main.tar.gz
Upgrade crossbeam-epoch to 0.9.18 am: 49ee284a38HEADmastermainemu-34-2-dev
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/crossbeam-epoch/+/2943530 Change-Id: I64c42941eb47a63d550e288362b4957c2db3d734 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp19
-rw-r--r--CHANGELOG.md21
-rw-r--r--Cargo.lock194
-rw-r--r--Cargo.toml26
-rw-r--r--Cargo.toml.orig21
-rw-r--r--METADATA25
-rw-r--r--README.md4
-rw-r--r--build-common.rs13
-rw-r--r--build.rs57
-rw-r--r--no_atomic.rs85
-rw-r--r--src/atomic.rs66
-rw-r--r--src/collector.rs11
-rw-r--r--src/default.rs2
-rw-r--r--src/deferred.rs7
-rw-r--r--src/epoch.rs3
-rw-r--r--src/guard.rs25
-rw-r--r--src/internal.rs31
-rw-r--r--src/lib.rs73
-rw-r--r--src/sync/once_lock.rs27
-rw-r--r--src/sync/queue.rs5
21 files changed, 260 insertions, 457 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index fdc8b14..d24fe6d 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "721382b00b5dadd81954ed66764d547e2f1bb7a3"
+ "sha1": "9c3182abebb36bdc9446d75d4644190fef70fa01"
},
"path_in_vcs": "crossbeam-epoch"
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index 4ca15d2..347d320 100644
--- a/Android.bp
+++ b/Android.bp
@@ -44,27 +44,23 @@ rust_test {
host_supported: true,
crate_name: "crossbeam_epoch",
cargo_env_compat: true,
- cargo_pkg_version: "0.9.14",
+ cargo_pkg_version: "0.9.18",
srcs: ["src/lib.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
test_options: {
unit_test: true,
},
- edition: "2018",
+ edition: "2021",
features: [
"alloc",
"default",
"std",
],
rustlibs: [
- "libcfg_if",
"libcrossbeam_utils",
- "libmemoffset",
"librand",
- "libscopeguard",
],
- proc_macros: ["librustversion"],
}
rust_library {
@@ -72,20 +68,15 @@ rust_library {
host_supported: true,
crate_name: "crossbeam_epoch",
cargo_env_compat: true,
- cargo_pkg_version: "0.9.14",
+ cargo_pkg_version: "0.9.18",
srcs: ["src/lib.rs"],
- edition: "2018",
+ edition: "2021",
features: [
"alloc",
"default",
"std",
],
- rustlibs: [
- "libcfg_if",
- "libcrossbeam_utils",
- "libmemoffset",
- "libscopeguard",
- ],
+ rustlibs: ["libcrossbeam_utils"],
apex_available: [
"//apex_available:platform",
"//apex_available:anyapex",
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f7508ae..d5ca3a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,24 @@
+# Version 0.9.18
+
+- Remove dependency on `cfg-if`. (#1072)
+- Remove dependency on `autocfg`. (#1071)
+
+# Version 0.9.17
+
+- Remove dependency on `memoffset`. (#1058)
+
+# Version 0.9.16
+
+- Bump the minimum supported Rust version to 1.61. (#1037)
+- Improve support for targets without atomic CAS. (#1037)
+- Remove build script. (#1037)
+- Remove dependency on `scopeguard`. (#1045)
+- Update `loom` dependency to 0.7.
+
+# Version 0.9.15
+
+- Update `memoffset` to 0.9. (#981)
+
# Version 0.9.14
- Update `memoffset` to 0.8. (#955)
diff --git a/Cargo.lock b/Cargo.lock
index dab6b89..3a2c624 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,16 +3,22 @@
version = 3
[[package]]
-name = "autocfg"
-version = "1.1.0"
+name = "aho-corasick"
+version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
+dependencies = [
+ "memchr",
+]
[[package]]
name = "cc"
-version = "1.0.79"
+version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
+checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
+dependencies = [
+ "libc",
+]
[[package]]
name = "cfg-if"
@@ -22,23 +28,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crossbeam-epoch"
-version = "0.9.14"
+version = "0.9.18"
dependencies = [
- "autocfg",
- "cfg-if",
"crossbeam-utils",
"loom",
- "memoffset",
"rand",
- "rustversion",
- "scopeguard",
]
[[package]]
name = "crossbeam-utils"
-version = "0.8.15"
+version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
+checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c"
dependencies = [
"cfg-if",
"loom",
@@ -46,9 +47,9 @@ dependencies = [
[[package]]
name = "generator"
-version = "0.7.3"
+version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "33a20a288a94683f5f4da0adecdbe095c94a77c295e514cc6484e9394dd8376e"
+checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e"
dependencies = [
"cc",
"libc",
@@ -59,9 +60,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.8"
+version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
+checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"libc",
@@ -76,24 +77,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.139"
+version = "0.2.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
+checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7"
[[package]]
name = "log"
-version = "0.4.17"
+version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
-dependencies = [
- "cfg-if",
-]
+checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "loom"
-version = "0.5.6"
+version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5"
+checksum = "7e045d70ddfbc984eacfa964ded019534e8f6cbf36f6410aee0ed5cefa5a9175"
dependencies = [
"cfg-if",
"generator",
@@ -108,17 +106,14 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
- "regex-automata",
+ "regex-automata 0.1.10",
]
[[package]]
-name = "memoffset"
-version = "0.8.0"
+name = "memchr"
+version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
-dependencies = [
- "autocfg",
-]
+checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "nu-ansi-term"
@@ -132,9 +127,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.17.1"
+version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "overload"
@@ -144,9 +139,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "pin-project-lite"
-version = "0.2.9"
+version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
+checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "ppv-lite86"
@@ -156,18 +151,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
-version = "1.0.51"
+version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
+checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.23"
+version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
+checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
@@ -204,11 +199,14 @@ dependencies = [
[[package]]
name = "regex"
-version = "1.7.1"
+version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
+checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
- "regex-syntax",
+ "aho-corasick",
+ "memchr",
+ "regex-automata 0.4.3",
+ "regex-syntax 0.8.2",
]
[[package]]
@@ -217,20 +215,37 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
- "regex-syntax",
+ "regex-syntax 0.6.29",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax 0.8.2",
]
[[package]]
name = "regex-syntax"
-version = "0.6.28"
+version = "0.6.29"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
+checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "rustversion"
-version = "1.0.11"
+version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
+checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "scoped-tls"
@@ -239,31 +254,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
[[package]]
-name = "scopeguard"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
-
-[[package]]
name = "sharded-slab"
-version = "0.1.4"
+version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
+checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "smallvec"
-version = "1.10.0"
+version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
+checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "syn"
-version = "1.0.109"
+version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
+checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
@@ -282,11 +291,10 @@ dependencies = [
[[package]]
name = "tracing"
-version = "0.1.37"
+version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
+checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
- "cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@@ -294,9 +302,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
-version = "0.1.23"
+version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
+checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
@@ -305,9 +313,9 @@ dependencies = [
[[package]]
name = "tracing-core"
-version = "0.1.30"
+version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
+checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
@@ -315,20 +323,20 @@ dependencies = [
[[package]]
name = "tracing-log"
-version = "0.1.3"
+version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922"
+checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
- "lazy_static",
"log",
+ "once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
-version = "0.3.16"
+version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
+checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"matchers",
"nu-ansi-term",
@@ -344,9 +352,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
-version = "1.0.6"
+version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "valuable"
@@ -384,18 +392,18 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
-version = "0.44.0"
+version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b"
+checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
+checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
@@ -408,42 +416,42 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
+checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
+checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
+checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
+checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
+checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
+checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
-version = "0.42.1"
+version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
+checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
diff --git a/Cargo.toml b/Cargo.toml
index 0ba7985..0a8fc81 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,10 +10,10 @@
# See Cargo.toml.orig for the original contents.
[package]
-edition = "2018"
-rust-version = "1.38"
+edition = "2021"
+rust-version = "1.61"
name = "crossbeam-epoch"
-version = "0.9.14"
+version = "0.9.18"
description = "Epoch-based garbage collection"
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch"
readme = "README.md"
@@ -31,29 +31,13 @@ categories = [
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
-[dependencies.cfg-if]
-version = "1"
-
[dependencies.crossbeam-utils]
-version = "0.8.5"
-default-features = false
-
-[dependencies.memoffset]
-version = "0.8"
-
-[dependencies.scopeguard]
-version = "1.1"
+version = "0.8.18"
default-features = false
[dev-dependencies.rand]
version = "0.8"
-[dev-dependencies.rustversion]
-version = "1"
-
-[build-dependencies.autocfg]
-version = "1"
-
[features]
alloc = []
default = ["std"]
@@ -68,6 +52,6 @@ std = [
]
[target."cfg(crossbeam_loom)".dependencies.loom-crate]
-version = "0.5"
+version = "0.7.1"
optional = true
package = "loom"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 45428bf..0f87aed 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -4,9 +4,9 @@ name = "crossbeam-epoch"
# - Update CHANGELOG.md
# - Update README.md
# - Create "crossbeam-epoch-X.Y.Z" git tag
-version = "0.9.14"
-edition = "2018"
-rust-version = "1.38"
+version = "0.9.18"
+edition = "2021"
+rust-version = "1.61"
license = "MIT OR Apache-2.0"
repository = "https://github.com/crossbeam-rs/crossbeam"
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch"
@@ -42,26 +42,15 @@ nightly = ["crossbeam-utils/nightly"]
# patch versions of crossbeam may make breaking changes to them at any time.
loom = ["loom-crate", "crossbeam-utils/loom"]
-[build-dependencies]
-autocfg = "1"
-
[dependencies]
-cfg-if = "1"
-memoffset = "0.8"
-scopeguard = { version = "1.1", default-features = false }
+crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false }
# Enable the use of loom for concurrency testing.
#
# NOTE: This feature is outside of the normal semver guarantees and minor or
# patch versions of crossbeam may make breaking changes to them at any time.
[target.'cfg(crossbeam_loom)'.dependencies]
-loom-crate = { package = "loom", version = "0.5", optional = true }
-
-[dependencies.crossbeam-utils]
-version = "0.8.5"
-path = "../crossbeam-utils"
-default-features = false
+loom-crate = { package = "loom", version = "0.7.1", optional = true }
[dev-dependencies]
rand = "0.8"
-rustversion = "1"
diff --git a/METADATA b/METADATA
index 07adda6..d09d0a6 100644
--- a/METADATA
+++ b/METADATA
@@ -1,23 +1,20 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update rust/crates/crossbeam-epoch
-# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+# Usage: tools/external_updater/updater.sh update external/rust/crates/crossbeam-epoch
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "crossbeam-epoch"
description: "Epoch-based garbage collection"
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/crossbeam-epoch"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/crossbeam-epoch/crossbeam-epoch-0.9.14.crate"
- }
- version: "0.9.14"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 3
- day: 6
+ year: 2024
+ month: 2
+ day: 1
+ }
+ homepage: "https://crates.io/crates/crossbeam-epoch"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/crossbeam-epoch/crossbeam-epoch-0.9.18.crate"
+ version: "0.9.18"
}
}
diff --git a/README.md b/README.md
index 2840ea7..ba74c7c 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch#license)
https://crates.io/crates/crossbeam-epoch)
[![Documentation](https://docs.rs/crossbeam-epoch/badge.svg)](
https://docs.rs/crossbeam-epoch)
-[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
+[![Rust 1.61+](https://img.shields.io/badge/rust-1.61+-lightgray.svg)](
https://www.rust-lang.org)
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)
@@ -35,7 +35,7 @@ crossbeam-epoch = "0.9"
Crossbeam Epoch supports stable Rust releases going back at least six months,
and every time the minimum supported Rust version is increased, a new minor
-version is released. Currently, the minimum supported Rust version is 1.38.
+version is released. Currently, the minimum supported Rust version is 1.61.
## License
diff --git a/build-common.rs b/build-common.rs
deleted file mode 100644
index e91bb4d..0000000
--- a/build-common.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-// The target triplets have the form of 'arch-vendor-system'.
-//
-// When building for Linux (e.g. the 'system' part is
-// 'linux-something'), replace the vendor with 'unknown'
-// so that mapping to rust standard targets happens correctly.
-fn convert_custom_linux_target(target: String) -> String {
- let mut parts: Vec<&str> = target.split('-').collect();
- let system = parts.get(2);
- if system == Some(&"linux") {
- parts[1] = "unknown";
- };
- parts.join("-")
-}
diff --git a/build.rs b/build.rs
deleted file mode 100644
index 978141a..0000000
--- a/build.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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");
-include!("build-common.rs");
-
-fn main() {
- let target = match env::var("TARGET") {
- Ok(target) => convert_custom_linux_target(target),
- Err(e) => {
- println!(
- "cargo:warning={}: unable to get TARGET environment variable: {}",
- env!("CARGO_PKG_NAME"),
- e
- );
- return;
- }
- };
-
- let cfg = match autocfg::AutoCfg::new() {
- Ok(cfg) => cfg,
- Err(e) => {
- println!(
- "cargo:warning={}: unable to determine rustc version: {}",
- env!("CARGO_PKG_NAME"),
- e
- );
- return;
- }
- };
-
- // Note that this is `no_`*, not `has_*`. This allows treating as the latest
- // stable rustc is used when the build script doesn't run. This is useful
- // for non-cargo build systems that don't run the build script.
- if NO_ATOMIC_CAS.contains(&&*target) {
- println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
- }
-
- if !cfg.probe_rustc_version(1, 61) {
- println!("cargo:rustc-cfg=crossbeam_no_const_fn_trait_bound");
- }
-
- println!("cargo:rerun-if-changed=no_atomic.rs");
-}
diff --git a/no_atomic.rs b/no_atomic.rs
deleted file mode 100644
index beb11b0..0000000
--- a/no_atomic.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-// This file is @generated by no_atomic.sh.
-// It is not intended for manual editing.
-
-const NO_ATOMIC_CAS: &[&str] = &[
- "armv4t-none-eabi",
- "armv5te-none-eabi",
- "avr-unknown-gnu-atmega328",
- "bpfeb-unknown-none",
- "bpfel-unknown-none",
- "msp430-none-elf",
- "riscv32i-unknown-none-elf",
- "riscv32im-unknown-none-elf",
- "riscv32imc-unknown-none-elf",
- "thumbv4t-none-eabi",
- "thumbv5te-none-eabi",
- "thumbv6m-none-eabi",
-];
-
-#[allow(dead_code)] // Only crossbeam-utils uses this.
-const NO_ATOMIC_64: &[&str] = &[
- "arm-linux-androideabi",
- "armebv7r-none-eabi",
- "armebv7r-none-eabihf",
- "armv4t-none-eabi",
- "armv4t-unknown-linux-gnueabi",
- "armv5te-none-eabi",
- "armv5te-unknown-linux-gnueabi",
- "armv5te-unknown-linux-musleabi",
- "armv5te-unknown-linux-uclibceabi",
- "armv6k-nintendo-3ds",
- "armv7-sony-vita-newlibeabihf",
- "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-sony-psx",
- "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",
- "powerpc-unknown-netbsd",
- "powerpc-unknown-openbsd",
- "powerpc-wrs-vxworks",
- "powerpc-wrs-vxworks-spe",
- "riscv32gc-unknown-linux-gnu",
- "riscv32gc-unknown-linux-musl",
- "riscv32i-unknown-none-elf",
- "riscv32im-unknown-none-elf",
- "riscv32imac-unknown-none-elf",
- "riscv32imac-unknown-xous-elf",
- "riscv32imc-unknown-none-elf",
- "thumbv4t-none-eabi",
- "thumbv5te-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",
-];
-
-#[allow(dead_code)] // Only crossbeam-utils uses this.
-const NO_ATOMIC: &[&str] = &[
- "avr-unknown-gnu-atmega328",
- "bpfeb-unknown-none",
- "bpfel-unknown-none",
- "mipsel-sony-psx",
- "msp430-none-elf",
- "riscv32i-unknown-none-elf",
- "riscv32im-unknown-none-elf",
- "riscv32imc-unknown-none-elf",
-];
diff --git a/src/atomic.rs b/src/atomic.rs
index 19bab47..41b4cd9 100644
--- a/src/atomic.rs
+++ b/src/atomic.rs
@@ -1,16 +1,16 @@
+use alloc::boxed::Box;
+use core::alloc::Layout;
use core::borrow::{Borrow, BorrowMut};
use core::cmp;
use core::fmt;
use core::marker::PhantomData;
use core::mem::{self, MaybeUninit};
use core::ops::{Deref, DerefMut};
+use core::ptr;
use core::slice;
-use core::sync::atomic::Ordering;
-use crate::alloc::alloc;
-use crate::alloc::boxed::Box;
use crate::guard::Guard;
-use crate::primitive::sync::atomic::AtomicUsize;
+use crate::primitive::sync::atomic::{AtomicUsize, Ordering};
use crossbeam_utils::atomic::AtomicConsume;
/// Given ordering for the success case in a compare-exchange operation, returns the strongest
@@ -233,9 +233,6 @@ impl<T> Pointable for T {
///
/// Elements are not present in the type, but they will be in the allocation.
/// ```
-///
-// TODO(@jeehoonkang): once we bump the minimum required Rust version to 1.44 or newer, use
-// [`alloc::alloc::Layout::extend`] instead.
#[repr(C)]
struct Array<T> {
/// The number of elements (not the number of bytes).
@@ -243,20 +240,28 @@ struct Array<T> {
elements: [MaybeUninit<T>; 0],
}
+impl<T> Array<T> {
+ fn layout(len: usize) -> Layout {
+ Layout::new::<Self>()
+ .extend(Layout::array::<MaybeUninit<T>>(len).unwrap())
+ .unwrap()
+ .0
+ .pad_to_align()
+ }
+}
+
impl<T> Pointable for [MaybeUninit<T>] {
const ALIGN: usize = mem::align_of::<Array<T>>();
type Init = usize;
unsafe fn init(len: Self::Init) -> usize {
- let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * len;
- let align = mem::align_of::<Array<T>>();
- let layout = alloc::Layout::from_size_align(size, align).unwrap();
- let ptr = alloc::alloc(layout).cast::<Array<T>>();
+ let layout = Array::<T>::layout(len);
+ let ptr = alloc::alloc::alloc(layout).cast::<Array<T>>();
if ptr.is_null() {
- alloc::handle_alloc_error(layout);
+ alloc::alloc::handle_alloc_error(layout);
}
- (*ptr).len = len;
+ ptr::addr_of_mut!((*ptr).len).write(len);
ptr as usize
}
@@ -271,11 +276,9 @@ impl<T> Pointable for [MaybeUninit<T>] {
}
unsafe fn drop(ptr: usize) {
- let array = &*(ptr as *mut Array<T>);
- let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * array.len;
- let align = mem::align_of::<Array<T>>();
- let layout = alloc::Layout::from_size_align(size, align).unwrap();
- alloc::dealloc(ptr as *mut u8, layout);
+ let len = (*(ptr as *mut Array<T>)).len;
+ let layout = Array::<T>::layout(len);
+ alloc::alloc::dealloc(ptr as *mut u8, layout);
}
}
@@ -344,16 +347,15 @@ impl<T: ?Sized + Pointable> Atomic<T> {
///
/// let a = Atomic::<i32>::null();
/// ```
- #[cfg(all(not(crossbeam_no_const_fn_trait_bound), not(crossbeam_loom)))]
+ #[cfg(not(crossbeam_loom))]
pub const fn null() -> Atomic<T> {
Self {
data: AtomicUsize::new(0),
_marker: PhantomData,
}
}
-
/// Returns a new null atomic pointer.
- #[cfg(not(all(not(crossbeam_no_const_fn_trait_bound), not(crossbeam_loom))))]
+ #[cfg(crossbeam_loom)]
pub fn null() -> Atomic<T> {
Self {
data: AtomicUsize::new(0),
@@ -879,17 +881,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
/// }
/// ```
pub unsafe fn into_owned(self) -> Owned<T> {
- #[cfg(crossbeam_loom)]
- {
- // FIXME: loom does not yet support into_inner, so we use unsync_load for now,
- // which should have the same synchronization properties:
- // https://github.com/tokio-rs/loom/issues/117
- Owned::from_usize(self.data.unsync_load())
- }
- #[cfg(not(crossbeam_loom))]
- {
- Owned::from_usize(self.data.into_inner())
- }
+ Owned::from_usize(self.data.into_inner())
}
/// Takes ownership of the pointee if it is non-null.
@@ -926,10 +918,6 @@ impl<T: ?Sized + Pointable> Atomic<T> {
/// }
/// ```
pub unsafe fn try_into_owned(self) -> Option<Owned<T>> {
- // FIXME: See self.into_owned()
- #[cfg(crossbeam_loom)]
- let data = self.data.unsync_load();
- #[cfg(not(crossbeam_loom))]
let data = self.data.into_inner();
if decompose_tag::<T>(data).0 == 0 {
None
@@ -1313,10 +1301,7 @@ pub struct Shared<'g, T: 'g + ?Sized + Pointable> {
impl<T: ?Sized + Pointable> Clone for Shared<'_, T> {
fn clone(&self) -> Self {
- Self {
- data: self.data,
- _marker: PhantomData,
- }
+ *self
}
}
@@ -1702,7 +1687,6 @@ mod tests {
Shared::<i64>::null().with_tag(7);
}
- #[rustversion::since(1.61)]
#[test]
fn const_atomic_null() {
use super::Atomic;
diff --git a/src/collector.rs b/src/collector.rs
index 5b08511..12655d6 100644
--- a/src/collector.rs
+++ b/src/collector.rs
@@ -286,7 +286,7 @@ mod tests {
const COUNT: usize = 100_000;
static DROPS: AtomicUsize = AtomicUsize::new(0);
- struct Elem(i32);
+ struct Elem(#[allow(dead_code)] i32);
impl Drop for Elem {
fn drop(&mut self) {
@@ -350,7 +350,7 @@ mod tests {
const COUNT: usize = 700;
static DROPS: AtomicUsize = AtomicUsize::new(0);
- struct Elem(i32);
+ struct Elem(#[allow(dead_code)] i32);
impl Drop for Elem {
fn drop(&mut self) {
@@ -403,9 +403,10 @@ mod tests {
}
let len = v.len();
- let ptr = ManuallyDrop::new(v).as_mut_ptr() as usize;
+ let cap = v.capacity();
+ let ptr = ManuallyDrop::new(v).as_mut_ptr();
guard.defer_unchecked(move || {
- drop(Vec::from_raw_parts(ptr as *const i32 as *mut i32, len, len));
+ drop(Vec::from_raw_parts(ptr, len, cap));
DESTROYS.fetch_add(len, Ordering::Relaxed);
});
guard.flush();
@@ -427,7 +428,7 @@ mod tests {
const COUNT: usize = 100_000;
static DROPS: AtomicUsize = AtomicUsize::new(0);
- struct Elem(i32);
+ struct Elem(#[allow(dead_code)] i32);
impl Drop for Elem {
fn drop(&mut self) {
diff --git a/src/default.rs b/src/default.rs
index b42c1c7..a9790a3 100644
--- a/src/default.rs
+++ b/src/default.rs
@@ -77,7 +77,7 @@ mod tests {
}
thread_local! {
- static FOO: Foo = Foo;
+ static FOO: Foo = const { Foo };
}
thread::scope(|scope| {
diff --git a/src/deferred.rs b/src/deferred.rs
index 2f3d79f..041955f 100644
--- a/src/deferred.rs
+++ b/src/deferred.rs
@@ -89,10 +89,9 @@ impl Deferred {
#[cfg(all(test, not(crossbeam_loom)))]
mod tests {
- #![allow(clippy::drop_copy)]
-
use super::Deferred;
use std::cell::Cell;
+ use std::convert::identity;
#[test]
fn on_stack() {
@@ -100,7 +99,7 @@ mod tests {
let a = [0usize; 1];
let d = Deferred::new(move || {
- drop(a);
+ let _ = identity(a);
fired.set(true);
});
@@ -115,7 +114,7 @@ mod tests {
let a = [0usize; 10];
let d = Deferred::new(move || {
- drop(a);
+ let _ = identity(a);
fired.set(true);
});
diff --git a/src/epoch.rs b/src/epoch.rs
index 663508b..18d7418 100644
--- a/src/epoch.rs
+++ b/src/epoch.rs
@@ -7,8 +7,7 @@
//! If an object became garbage in some epoch, then we can be sure that after two advancements no
//! participant will hold a reference to it. That is the crux of safe memory reclamation.
-use crate::primitive::sync::atomic::AtomicUsize;
-use core::sync::atomic::Ordering;
+use crate::primitive::sync::atomic::{AtomicUsize, Ordering};
/// An epoch that can be marked as pinned or unpinned.
///
diff --git a/src/guard.rs b/src/guard.rs
index ba7fe1b..5fe3380 100644
--- a/src/guard.rs
+++ b/src/guard.rs
@@ -1,8 +1,6 @@
use core::fmt;
use core::mem;
-use scopeguard::defer;
-
use crate::atomic::Shared;
use crate::collector::Collector;
use crate::deferred::Deferred;
@@ -366,6 +364,17 @@ impl Guard {
where
F: FnOnce() -> R,
{
+ // Ensure the Guard is re-pinned even if the function panics
+ struct ScopeGuard(*const Local);
+ impl Drop for ScopeGuard {
+ fn drop(&mut self) {
+ if let Some(local) = unsafe { self.0.as_ref() } {
+ mem::forget(local.pin());
+ local.release_handle();
+ }
+ }
+ }
+
if let Some(local) = unsafe { self.local.as_ref() } {
// We need to acquire a handle here to ensure the Local doesn't
// disappear from under us.
@@ -373,13 +382,7 @@ impl Guard {
local.unpin();
}
- // Ensure the Guard is re-pinned even if the function panics
- defer! {
- if let Some(local) = unsafe { self.local.as_ref() } {
- mem::forget(local.pin());
- local.release_handle();
- }
- }
+ let _guard = ScopeGuard(self.local);
f()
}
@@ -447,8 +450,8 @@ impl fmt::Debug for Guard {
/// // Load `a` without pinning the current thread.
/// a.load(Relaxed, epoch::unprotected());
///
-/// // It's possible to create more dummy guards by calling `clone()`.
-/// let dummy = &epoch::unprotected().clone();
+/// // It's possible to create more dummy guards.
+/// let dummy = epoch::unprotected();
///
/// dummy.defer(move || {
/// println!("This gets executed immediately.");
diff --git a/src/internal.rs b/src/internal.rs
index 00c66a4..b2e9e71 100644
--- a/src/internal.rs
+++ b/src/internal.rs
@@ -36,15 +36,13 @@
//! destroyed as soon as the data structure gets dropped.
use crate::primitive::cell::UnsafeCell;
-use crate::primitive::sync::atomic;
+use crate::primitive::sync::atomic::{self, Ordering};
use core::cell::Cell;
use core::mem::{self, ManuallyDrop};
use core::num::Wrapping;
-use core::sync::atomic::Ordering;
use core::{fmt, ptr};
use crossbeam_utils::CachePadded;
-use memoffset::offset_of;
use crate::atomic::{Owned, Shared};
use crate::collector::{Collector, LocalHandle};
@@ -269,13 +267,11 @@ impl Global {
}
/// Participant for garbage collection.
+#[repr(C)] // Note: `entry` must be the first field
pub(crate) struct Local {
/// A node in the intrusive linked list of `Local`s.
entry: Entry,
- /// The local epoch.
- epoch: AtomicEpoch,
-
/// A reference to the global data.
///
/// When all guards and handles get dropped, this reference is destroyed.
@@ -294,6 +290,9 @@ pub(crate) struct Local {
///
/// This is just an auxiliary counter that sometimes kicks off collection.
pin_count: Cell<Wrapping<usize>>,
+
+ /// The local epoch.
+ epoch: CachePadded<AtomicEpoch>,
}
// Make sure `Local` is less than or equal to 2048 bytes.
@@ -320,12 +319,12 @@ impl Local {
let local = Owned::new(Local {
entry: Entry::default(),
- epoch: AtomicEpoch::new(Epoch::starting()),
collector: UnsafeCell::new(ManuallyDrop::new(collector.clone())),
bag: UnsafeCell::new(Bag::new()),
guard_count: Cell::new(0),
handle_count: Cell::new(1),
pin_count: Cell::new(Wrapping(0)),
+ epoch: CachePadded::new(AtomicEpoch::new(Epoch::starting())),
})
.into_shared(unprotected());
collector.global.locals.insert(local, unprotected());
@@ -535,16 +534,18 @@ impl Local {
}
}
-impl IsElement<Local> for Local {
- fn entry_of(local: &Local) -> &Entry {
- let entry_ptr = (local as *const Local as usize + offset_of!(Local, entry)) as *const Entry;
- unsafe { &*entry_ptr }
+impl IsElement<Self> for Local {
+ fn entry_of(local: &Self) -> &Entry {
+ // SAFETY: `Local` is `repr(C)` and `entry` is the first field of it.
+ unsafe {
+ let entry_ptr = (local as *const Self).cast::<Entry>();
+ &*entry_ptr
+ }
}
- unsafe fn element_of(entry: &Entry) -> &Local {
- // offset_of! macro uses unsafe, but it's unnecessary in this context.
- #[allow(unused_unsafe)]
- let local_ptr = (entry as *const Entry as usize - offset_of!(Local, entry)) as *const Local;
+ unsafe fn element_of(entry: &Entry) -> &Self {
+ // SAFETY: `Local` is `repr(C)` and `entry` is the first field of it.
+ let local_ptr = (entry as *const Entry).cast::<Self>();
&*local_ptr
}
diff --git a/src/lib.rs b/src/lib.rs
index b432c1f..fd4d74b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -66,8 +66,6 @@
#[cfg(crossbeam_loom)]
extern crate loom_crate as loom;
-use cfg_if::cfg_if;
-
#[cfg(crossbeam_loom)]
#[allow(unused_imports, dead_code)]
mod primitive {
@@ -76,8 +74,7 @@ mod primitive {
}
pub(crate) mod sync {
pub(crate) mod atomic {
- use core::sync::atomic::Ordering;
- pub(crate) use loom::sync::atomic::{fence, AtomicUsize};
+ pub(crate) use loom::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};
// FIXME: loom does not support compiler_fence at the moment.
// https://github.com/tokio-rs/loom/issues/117
@@ -90,11 +87,10 @@ mod primitive {
}
pub(crate) use loom::thread_local;
}
-#[cfg(not(crossbeam_no_atomic_cas))]
+#[cfg(target_has_atomic = "ptr")]
#[cfg(not(crossbeam_loom))]
#[allow(unused_imports, dead_code)]
mod primitive {
- #[cfg(feature = "alloc")]
pub(crate) mod cell {
#[derive(Debug)]
#[repr(transparent)]
@@ -122,13 +118,13 @@ mod primitive {
}
}
}
- #[cfg(feature = "alloc")]
pub(crate) mod sync {
pub(crate) mod atomic {
- pub(crate) use core::sync::atomic::compiler_fence;
- pub(crate) use core::sync::atomic::fence;
- pub(crate) use core::sync::atomic::AtomicUsize;
+ pub(crate) use core::sync::atomic::{
+ compiler_fence, fence, AtomicPtr, AtomicUsize, Ordering,
+ };
}
+ #[cfg(feature = "alloc")]
pub(crate) use alloc::sync::Arc;
}
@@ -136,34 +132,35 @@ mod primitive {
pub(crate) use std::thread_local;
}
-#[cfg(not(crossbeam_no_atomic_cas))]
-cfg_if! {
- if #[cfg(feature = "alloc")] {
- extern crate alloc;
-
- mod atomic;
- mod collector;
- mod deferred;
- mod epoch;
- mod guard;
- mod internal;
- mod sync;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+extern crate alloc;
- pub use self::atomic::{
- Pointable, Atomic, CompareExchangeError,
- Owned, Pointer, Shared,
- };
- pub use self::collector::{Collector, LocalHandle};
- pub use self::guard::{unprotected, Guard};
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod atomic;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod collector;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod deferred;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod epoch;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod guard;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod internal;
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+mod sync;
- #[allow(deprecated)]
- pub use self::atomic::{CompareAndSetError, CompareAndSetOrdering};
- }
-}
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+#[allow(deprecated)]
+pub use crate::atomic::{CompareAndSetError, CompareAndSetOrdering};
+#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
+pub use crate::{
+ atomic::{Atomic, CompareExchangeError, Owned, Pointable, Pointer, Shared},
+ collector::{Collector, LocalHandle},
+ guard::{unprotected, Guard},
+};
-cfg_if! {
- if #[cfg(feature = "std")] {
- mod default;
- pub use self::default::{default_collector, is_pinned, pin};
- }
-}
+#[cfg(feature = "std")]
+mod default;
+#[cfg(feature = "std")]
+pub use crate::default::{default_collector, is_pinned, pin};
diff --git a/src/sync/once_lock.rs b/src/sync/once_lock.rs
index c1fefc9..e057aca 100644
--- a/src/sync/once_lock.rs
+++ b/src/sync/once_lock.rs
@@ -4,13 +4,10 @@
use core::cell::UnsafeCell;
use core::mem::MaybeUninit;
-use core::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;
pub(crate) struct OnceLock<T> {
once: Once,
- // Once::is_completed requires Rust 1.43, so use this to track of whether they have been initialized.
- is_initialized: AtomicBool,
value: UnsafeCell<MaybeUninit<T>>,
// Unlike std::sync::OnceLock, we don't need PhantomData here because
// we don't use #[may_dangle].
@@ -25,7 +22,6 @@ impl<T> OnceLock<T> {
pub(crate) const fn new() -> Self {
Self {
once: Once::new(),
- is_initialized: AtomicBool::new(false),
value: UnsafeCell::new(MaybeUninit::uninit()),
}
}
@@ -50,37 +46,26 @@ impl<T> OnceLock<T> {
F: FnOnce() -> T,
{
// Fast path check
- if self.is_initialized() {
+ if self.once.is_completed() {
// SAFETY: The inner value has been initialized
return unsafe { self.get_unchecked() };
}
self.initialize(f);
- debug_assert!(self.is_initialized());
-
// SAFETY: The inner value has been initialized
unsafe { self.get_unchecked() }
}
- #[inline]
- fn is_initialized(&self) -> bool {
- self.is_initialized.load(Ordering::Acquire)
- }
-
#[cold]
fn initialize<F>(&self, f: F)
where
F: FnOnce() -> T,
{
- let slot = self.value.get().cast::<T>();
- let is_initialized = &self.is_initialized;
+ let slot = self.value.get();
self.once.call_once(|| {
let value = f();
- unsafe {
- slot.write(value);
- }
- is_initialized.store(true, Ordering::Release);
+ unsafe { slot.write(MaybeUninit::new(value)) }
});
}
@@ -88,16 +73,16 @@ impl<T> OnceLock<T> {
///
/// The value must be initialized
unsafe fn get_unchecked(&self) -> &T {
- debug_assert!(self.is_initialized());
+ debug_assert!(self.once.is_completed());
&*self.value.get().cast::<T>()
}
}
impl<T> Drop for OnceLock<T> {
fn drop(&mut self) {
- if self.is_initialized() {
+ if self.once.is_completed() {
// SAFETY: The inner value has been initialized
- unsafe { self.value.get().cast::<T>().drop_in_place() };
+ unsafe { (*self.value.get()).assume_init_drop() };
}
}
}
diff --git a/src/sync/queue.rs b/src/sync/queue.rs
index 9500438..76c326b 100644
--- a/src/sync/queue.rs
+++ b/src/sync/queue.rs
@@ -132,8 +132,7 @@ impl<T> Queue<T> {
.compare_exchange(tail, next, Release, Relaxed, guard);
}
guard.defer_destroy(head);
- // TODO: Replace with MaybeUninit::read when api is stable
- Some(n.data.as_ptr().read())
+ Some(n.data.assume_init_read())
})
.map_err(|_| ())
},
@@ -165,7 +164,7 @@ impl<T> Queue<T> {
.compare_exchange(tail, next, Release, Relaxed, guard);
}
guard.defer_destroy(head);
- Some(n.data.as_ptr().read())
+ Some(n.data.assume_init_read())
})
.map_err(|_| ())
},