From 15a329f61b9c6900c5727275c6374b2e0fa156d8 Mon Sep 17 00:00:00 2001 From: imDema Date: Fri, 12 Apr 2024 12:02:52 +0200 Subject: [PATCH] Add count window test, update dependencies --- Cargo.lock | 148 ++++++++++++++--------------- Cargo.toml | 14 +-- src/operator/window/descr/count.rs | 46 +++++++++ src/profiler/mod.rs | 23 +++-- src/worker.rs | 2 +- 5 files changed, 142 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55424d8e..321c9589 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,9 +32,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -95,15 +95,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -137,9 +137,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "block-buffer" @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.15.4" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" @@ -164,9 +164,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cast" @@ -176,9 +176,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.90" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" [[package]] name = "cfg-if" @@ -215,9 +215,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -237,14 +237,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -474,9 +474,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "flume" @@ -546,7 +546,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -600,9 +600,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ "cfg-if", "js-sys", @@ -625,9 +625,9 @@ checksum = "f2e102e6eb644d3e0b186fc161e4460417880a0a0b87d235f2e5b8fb30f2e9e0" [[package]] name = "half" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eceaaeec696539ddaf7b333340f1af35a5aa87ae3e4f3ead0532f72affab2e" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" dependencies = [ "cfg-if", "crunchy", @@ -659,9 +659,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -707,9 +707,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" @@ -774,9 +774,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.15" +version = "1.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" +checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" dependencies = [ "cc", "libc", @@ -808,9 +808,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "micrometer" @@ -924,9 +924,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "openssl-sys" -version = "0.9.101" +version = "0.9.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" dependencies = [ "cc", "libc", @@ -990,9 +990,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -1051,9 +1051,9 @@ dependencies = [ [[package]] name = "quick_cache" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58c20af3800cee5134b79a3bd4a3d4b583c16ccfa5f53338f46400851a5b3819" +checksum = "347e1a588d1de074eeb3c00eadff93db4db65aeb62aee852b1efd0949fe65b6c" dependencies = [ "ahash", "equivalent", @@ -1063,9 +1063,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1102,9 +1102,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4963ed1bc86e4f3ee217022bd855b297cef07fb9eac5dfa1f788b220b49b3bd" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -1140,9 +1140,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -1163,9 +1163,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "renoir" @@ -1223,11 +1223,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -1272,14 +1272,14 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -1332,9 +1332,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -1375,9 +1375,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" @@ -1392,9 +1392,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.53" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -1430,7 +1430,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -1455,9 +1455,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.36.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -1478,14 +1478,14 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] name = "toml" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ "serde", "serde_spanned", @@ -1504,9 +1504,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.7" +version = "0.22.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" dependencies = [ "indexmap", "serde", @@ -1535,7 +1535,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] [[package]] @@ -1667,7 +1667,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", "wasm-bindgen-shared", ] @@ -1689,7 +1689,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1886,9 +1886,9 @@ checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" dependencies = [ "memchr", ] @@ -1919,5 +1919,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.53", + "syn 2.0.58", ] diff --git a/Cargo.toml b/Cargo.toml index e646ff69..b1bbfb67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,9 +35,9 @@ derivative = "2.2.0" # serialization serde = { version = "1.0.197", features = ["derive"] } -serde_json = "1.0.114" +serde_json = "1.0.115" bincode = "1.3.3" -toml = "0.8.11" +toml = "0.8.12" thiserror = "1.0.58" @@ -50,7 +50,7 @@ once_cell = "1.19.0" ssh2 = { version = "0.9.4", optional = true } whoami = { version = "1.5.1", optional = true } shell-escape = { version = "0.1.5", optional = true } -clap = { version = "4.5.2", features = ["derive"], optional = true } +clap = { version = "4.5.4", features = ["derive"], optional = true } sha2 = { version = "0.10.8", optional = true } base64 = { version = "0.22.0", optional = true } @@ -66,7 +66,7 @@ lazy-init = "0.5.1" # Faster monotonic clock using libc's CLOCK_MONOTONIC_COARSE coarsetime = "0.1.34" -tokio = { version = "1.36.0", features = ["rt"], default-features = false, optional = true } +tokio = { version = "1.37.0", features = ["rt"], default-features = false, optional = true } futures = { version = "0.3.30", optional = true } parking_lot = "0.12.1" @@ -74,9 +74,9 @@ parking_lot = "0.12.1" wyhash = "0.5.0" fxhash = "0.2.1" glidesort = "0.1.2" -indexmap = "2.2.5" +indexmap = "2.2.6" tracing = { version = "0.1.40", features = ["log"] } -quick_cache = "0.4.1" +quick_cache = "0.5.1" dashmap = "5.5.3" [dev-dependencies] @@ -93,7 +93,7 @@ itertools = "0.12.1" micrometer = { version = "0.2.7", features = ["enable"]} # for the examples -regex = "1.10.3" +regex = "1.10.4" kstring = { version = "2.0.0", features = ["serde"] } nexmark = { version = "0.2.0", features = ["serde"] } diff --git a/src/operator/window/descr/count.rs b/src/operator/window/descr/count.rs index 10c35514..f40b80d0 100644 --- a/src/operator/window/descr/count.rs +++ b/src/operator/window/descr/count.rs @@ -193,6 +193,52 @@ mod tests { } } + #[test] + fn exact_window() { + let window = CountWindow::new(4, 1, true); + + let fold: Fold, _> = Fold::new(Vec::new(), |v, el| v.push(el)); + let mut manager = window.build(fold); + + let mut res = Vec::new(); + for i in 1..6 { + res.extend( + manager + .process(StreamElement::Item(i)) + .map(WindowResult::unwrap_item), + ); + } + manager.process(StreamElement::Terminate); + + eprintln!("{res:?}"); + assert_eq!(vec![vec![1, 2, 3, 4], vec![2, 3, 4, 5],], res) + } + + #[test] + fn nonexact_window() { + let window = CountWindow::new(4, 1, false); + + let fold: Fold, _> = Fold::new(Vec::new(), |v, el| v.push(el)); + let mut manager = window.build(fold); + + let mut res = Vec::new(); + for i in 1..6 { + res.extend( + manager + .process(StreamElement::Item(i)) + .map(WindowResult::unwrap_item), + ); + } + res.extend( + manager + .process(StreamElement::Terminate) + .map(WindowResult::unwrap_item), + ); + + eprintln!("{res:?}"); + assert_eq!(vec![vec![1, 2, 3, 4], vec![2, 3, 4, 5], vec![3, 4, 5]], res) + } + #[test] #[cfg(feature = "timestamp")] fn count_window_timestamped() { diff --git a/src/profiler/mod.rs b/src/profiler/mod.rs index e367a32f..dccff877 100644 --- a/src/profiler/mod.rs +++ b/src/profiler/mod.rs @@ -30,20 +30,21 @@ pub trait Profiler { /// The implementation of the profiler when the `profiler` feature is enabled. #[cfg(feature = "profiler")] mod with_profiler { + use once_cell::sync::Lazy; use std::cell::UnsafeCell; use std::sync::Mutex; use std::time::Instant; - use crate::channel::{UnboundedReceiver, UnboundedSender}; use crate::profiler::backend::ProfilerBackend; use crate::profiler::metrics::ProfilerResult; + use flume::{Receiver, Sender}; /// The sender and receiver pair of the current profilers. /// /// These are options since they can be consumed. static CHANNEL: Lazy, Option)>> = Lazy::new(|| { - let (sender, receiver) = ProfilerReceiver::new(); + let (sender, receiver) = flume::unbounded(); Mutex::new((Some(sender), Some(receiver))) }); @@ -58,9 +59,9 @@ mod with_profiler { } /// The type of the channel sender with the `ProfilerResult`s. - type ProfilerSender = UnboundedChannelSender; + type ProfilerSender = Sender; /// The type of the channel receiver with the `ProfilerResult`s. - type ProfilerReceiver = UnboundedChannelReceiver; + type ProfilerReceiver = Receiver; /// Get the sender for sending the profiler results. pub(crate) fn get_sender() -> ProfilerSender { @@ -87,7 +88,7 @@ mod with_profiler { results.push(profiler_res); } - let (sender, receiver) = ProfilerReceiver::new(); + let (sender, receiver) = flume::unbounded(); channels.0 = Some(sender); channels.1 = Some(receiver); @@ -98,11 +99,13 @@ mod with_profiler { /// The implementation of the profiler when the `profiler` feature is disabled. #[cfg(not(feature = "profiler"))] mod without_profiler { + use std::cell::UnsafeCell; + use crate::network::Coord; use crate::profiler::*; /// The fake profiler for when the `profiler` feature is disabled. - static mut PROFILER: NoOpProfiler = NoOpProfiler; + // static PROFILER: UnsafeCell = UnsafeCell::new(NoOpProfiler); /// Fake profiler. This is used when the `profiler` feature is not enabled. /// @@ -111,6 +114,10 @@ mod without_profiler { #[derive(Debug, Clone, Copy, Default)] pub struct NoOpProfiler; + thread_local! { + static PROFILER: UnsafeCell = const { UnsafeCell::new(NoOpProfiler) }; + } + impl Profiler for NoOpProfiler { #[inline(always)] fn items_in(&mut self, _from: Coord, _to: Coord, _amount: usize) {} @@ -126,9 +133,7 @@ mod without_profiler { /// Get a fake profiler that does nothing. pub fn get_profiler() -> &'static mut NoOpProfiler { - // SAFETY: the profiler does nothing, so, even though this is a mutable borrow, no data is - // shared. - unsafe { &mut PROFILER } + PROFILER.with(|t| unsafe { &mut *t.get() }) } /// Do nothing, since there is nothing to wait for. diff --git a/src/worker.rs b/src/worker.rs index 0192235d..425a0811 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -10,7 +10,7 @@ thread_local! { /// Coordinates of the replica the current worker thread is working on. /// /// Access to this by calling `replica_coord()`. - static COORD: RefCell> = RefCell::new(None); + static COORD: RefCell> = const { RefCell::new(None) }; } /// Get the coord of the replica the current thread is working on.