1 diff --git a/Cargo.lock b/Cargo.lock |
|
2 --- a/Cargo.lock |
|
3 +++ b/Cargo.lock |
|
4 @@ -972,13 +972,13 @@ |
|
5 "cfg-if 1.0.0", |
|
6 ] |
|
7 |
|
8 [[package]] |
|
9 name = "crossbeam-channel" |
|
10 -version = "0.5.2" |
|
11 -source = "registry+https://github.com/rust-lang/crates.io-index" |
|
12 -checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa" |
|
13 +version = "0.5.4" |
|
14 +source = "registry+https://github.com/rust-lang/crates.io-index" |
|
15 +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" |
|
16 dependencies = [ |
|
17 "cfg-if 1.0.0", |
|
18 "crossbeam-utils 0.8.6", |
|
19 ] |
|
20 |
|
21 diff --git a/third_party/rust/crossbeam-channel/.cargo-checksum.json b/third_party/rust/crossbeam-channel/.cargo-checksum.json |
|
22 --- a/third_party/rust/crossbeam-channel/.cargo-checksum.json |
|
23 +++ b/third_party/rust/crossbeam-channel/.cargo-checksum.json |
|
24 @@ -1 +1 @@ |
|
25 -{"files":{"CHANGELOG.md":"e70d1a5fa6697a8b24e193e3934975317df12279c167b90fcb9616291792197c","Cargo.lock":"0f4e59f28bdd52c4781d102fc7d1f16d1ea417aaec0a4846432444a4019b2537","Cargo.toml":"c8334f658b699a1a0e25d997d752a9493a627f9ddcb7aab739c7319ea583882f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5734ed989dfca1f625b40281ee9f4530f91b2411ec01cb748223e7eb87e201ab","LICENSE-THIRD-PARTY":"b16db96b93b1d7cf7bea533f572091ec6bca3234fbe0a83038be772ff391a44c","README.md":"415a71d4978cfd338a6ae1f1b41284652eccd277a815542c304647dc437a8274","benches/crossbeam.rs":"96cb1abd23cac3ef8a7174a802e94609926b555bb02c9658c78723d433f1dd92","examples/fibonacci.rs":"4e88fa40048cdc31e9c7bb60347d46f92543d7ddf39cab3b52bfe44affdb6a02","examples/matching.rs":"63c250e164607a7a9f643d46f107bb5da846d49e89cf9069909562d20e530f71","examples/stopwatch.rs":"d02121258f08d56f1eb7997e19bcb9bacb6836cfa0abbba90a9e59d8a50ae5cf","src/channel.rs":"a9baaad2f414c38cd324a60ac9375ca58462ce6662217683648e9b66cec43a8c","src/context.rs":"ff4d39639ddf16aaab582d4a5f3d10ef2c71afe1abbf4e60f3d9d2ddbd72c230","src/counter.rs":"c49a9f44587888850edeb62f7c8ecd1acecb39c836834254ff3ac934c478440a","src/err.rs":"fdbde7279a1e74973e5c7d3e835a97836229a357fe465c0ba1a37f2a012d1bef","src/flavors/array.rs":"853c2ad068f912cfb49877bcd41e241f34b25026b709bf0629523f19952e3adc","src/flavors/at.rs":"65bf870b3ddb14738256706b0276f2656ad1fe9cd8eb91737489868edd088e92","src/flavors/list.rs":"50dbe59616c39b5aa184470023ce0cfb1cb0dbd92e1577375d299446981527c0","src/flavors/mod.rs":"3d9d43bc38b0adb18c96c995c2bd3421d8e33ab6c30b20c3c467d21d48e485dc","src/flavors/never.rs":"0e7921922d00c711552fb063c63c78192fa6ddc0762fb81c1713b847495ec39a","src/flavors/tick.rs":"38a479b9f4a72a5ccb9c407a1e7b44d36b6ad0f4e214e39266b12b9564c803dc","src/flavors/zero.rs":"012a53f56b86df22ce49866da95e5f457fb99a18a098f0f64779c6d1cdd7092f","src/lib.rs":"3a65706d4124844ffc4c8cb1f8cc779631ec94f449f85cbb68364ad3619404f1","src/select.rs":"66eb10a6cbdf8dd0869f2a7cac9992fdaee36c9e2a01d708d39d7c794572935b","src/select_macro.rs":"96bc9acb9a22588a4e733b0ab0761ad2be9a6b3e03744e8fc9c6de9ae433b696","src/utils.rs":"746fe315d6cfc832e3dda35e5055c0fd5c99907f1303b2ea7eacc4e37c8527e1","src/waker.rs":"591ee70bf62ccad5aa2fac7b92d444183b02790a79c024f016c78de2396d08a3","tests/after.rs":"0154a8e152880db17a20514ecdd49dabc361d3629858d119b9746b5e932c780c","tests/array.rs":"e5f25e8991863a9a86d61a66be646d04feae527f35b1697fd215b97af4383736","tests/golang.rs":"dc85669c9c4e902b1bb263d00f5cb6f9ecb6d42b19fe53425b55ce97c887da49","tests/iter.rs":"25dc02135bbae9d47a30f9047661648e66bdc134e40ba78bc2fbacbb8b3819bc","tests/list.rs":"de865ef097f3bcb35c1c814554e6108fed43b3dbb1533c8bbcf8688cceb6b6ab","tests/mpsc.rs":"401aa3c6923815058881ddce98070df68ebab283913c89c007436bb8af7ca0ea","tests/never.rs":"ee40c4fc4dd5af4983fae8de6927f52b81174d222c162f745b26c4a6c7108e4f","tests/ready.rs":"d349702f123925a0781b48d677e6dcf64fc5d1fc788a7bf1e151a3d57e81871c","tests/same_channel.rs":"2bab761443671e841e1b2476bd8082d75533a2f6be7946f5dbcee67cdc82dccb","tests/select.rs":"d20259a45f387cbce80c2c876ae81ea3883f36ea01c5151c159d58c362f6ba07","tests/select_macro.rs":"d3af2dc98e0dd03dc4ffab464b8ccb2f8b7504e8bb830948a04c015b92f0b296","tests/thread_locals.rs":"a1ce59e2aff69161621c0cb215eb6ea238088c06a31a8507a74cf179fd5a4299","tests/tick.rs":"5f697bd14c48505d932e82065b5302ef668e1cc19cac18e8ac22e0c83c221c1d","tests/zero.rs":"afbd838001d4196daddf17133e60ccea31529cc48ee01e245ac0d6366d1e30b9"},"package":"e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"} |
|
26 \ No newline at end of file |
|
27 +{"files":{"CHANGELOG.md":"0f549e63930d1e576f117ee9249c84276eadbe6fb95818680c042c6c0af8a807","Cargo.lock":"834da9468c17c8e1b7fe457764257f4dfdaa24bc98cbdfedf3af4f3d4f5c1e6a","Cargo.toml":"1296a016c4c23d38a35b3d737ee8285fcaaf7d23b7bbb5a3484cefe56b7ca32a","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5734ed989dfca1f625b40281ee9f4530f91b2411ec01cb748223e7eb87e201ab","LICENSE-THIRD-PARTY":"b16db96b93b1d7cf7bea533f572091ec6bca3234fbe0a83038be772ff391a44c","README.md":"415a71d4978cfd338a6ae1f1b41284652eccd277a815542c304647dc437a8274","benches/crossbeam.rs":"96cb1abd23cac3ef8a7174a802e94609926b555bb02c9658c78723d433f1dd92","examples/fibonacci.rs":"4e88fa40048cdc31e9c7bb60347d46f92543d7ddf39cab3b52bfe44affdb6a02","examples/matching.rs":"63c250e164607a7a9f643d46f107bb5da846d49e89cf9069909562d20e530f71","examples/stopwatch.rs":"d02121258f08d56f1eb7997e19bcb9bacb6836cfa0abbba90a9e59d8a50ae5cf","src/channel.rs":"3bbf69df6c3f0071a44bab0139a749447604f5ffa5e45acc2998803dee066522","src/context.rs":"ff4d39639ddf16aaab582d4a5f3d10ef2c71afe1abbf4e60f3d9d2ddbd72c230","src/counter.rs":"c49a9f44587888850edeb62f7c8ecd1acecb39c836834254ff3ac934c478440a","src/err.rs":"44cb2024ee6b0cd6fd24996430e53720769f64b4ac35016bc3e05cb9db48681d","src/flavors/array.rs":"0743fb71a8adc8d95143b1cdae996823dddb7ab7fb7139eb6e0cdf733ff231ee","src/flavors/at.rs":"1db64919593b7c14f838c16a22732515f1e716d2d5f6cc639f42631380e545cd","src/flavors/list.rs":"017b66a84ada393d11d1730297426338244b115944a4d631573447641a66bed6","src/flavors/mod.rs":"3d9d43bc38b0adb18c96c995c2bd3421d8e33ab6c30b20c3c467d21d48e485dc","src/flavors/never.rs":"747da857aa1a7601641f23f4930e6ad00ebaf50456d9be5c7aa270e2ecc24dcb","src/flavors/tick.rs":"69b2dfe0186bc8b9fd7a73e32da59d2656d8150da1e00fba92a412e0907568a3","src/flavors/zero.rs":"1edd8e5114daa5b82ec9f4a715c0389a9de02cce64de0f71b4225868dad99a99","src/lib.rs":"3a65706d4124844ffc4c8cb1f8cc779631ec94f449f85cbb68364ad3619404f1","src/select.rs":"63dbfde7098dac1424f1cc884f6b8364f3bf3e06527691dde628ff6c416a7f35","src/select_macro.rs":"582a033cc0a51917fd5197dfb66677e9d7982c013414e75ae78b4a740189a56d","src/utils.rs":"b4d38e39a7d7774729458b1b39253377a55657d377c483d30b32e42a0a0092e3","src/waker.rs":"2114bd84f35b2c654d1914127e0380e17a5c20d8ec1e20449af3d653cad27c64","tests/after.rs":"0154a8e152880db17a20514ecdd49dabc361d3629858d119b9746b5e932c780c","tests/array.rs":"e0f3814328c79727a85df3aee0409701849dabfeaaa2f70721e14396fbaba1cd","tests/golang.rs":"dc85669c9c4e902b1bb263d00f5cb6f9ecb6d42b19fe53425b55ce97c887da49","tests/iter.rs":"25dc02135bbae9d47a30f9047661648e66bdc134e40ba78bc2fbacbb8b3819bc","tests/list.rs":"de865ef097f3bcb35c1c814554e6108fed43b3dbb1533c8bbcf8688cceb6b6ab","tests/mpsc.rs":"401aa3c6923815058881ddce98070df68ebab283913c89c007436bb8af7ca0ea","tests/never.rs":"ee40c4fc4dd5af4983fae8de6927f52b81174d222c162f745b26c4a6c7108e4f","tests/ready.rs":"d349702f123925a0781b48d677e6dcf64fc5d1fc788a7bf1e151a3d57e81871c","tests/same_channel.rs":"2bab761443671e841e1b2476bd8082d75533a2f6be7946f5dbcee67cdc82dccb","tests/select.rs":"d20259a45f387cbce80c2c876ae81ea3883f36ea01c5151c159d58c362f6ba07","tests/select_macro.rs":"948eb21f72a9317c0de98a9bd21f6f8ff2b09b73b45c171c45b04c051a2fd0c4","tests/thread_locals.rs":"a1ce59e2aff69161621c0cb215eb6ea238088c06a31a8507a74cf179fd5a4299","tests/tick.rs":"5f697bd14c48505d932e82065b5302ef668e1cc19cac18e8ac22e0c83c221c1d","tests/zero.rs":"afbd838001d4196daddf17133e60ccea31529cc48ee01e245ac0d6366d1e30b9"},"package":"5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"} |
|
28 \ No newline at end of file |
|
29 diff --git a/third_party/rust/crossbeam-channel/CHANGELOG.md b/third_party/rust/crossbeam-channel/CHANGELOG.md |
|
30 --- a/third_party/rust/crossbeam-channel/CHANGELOG.md |
|
31 +++ b/third_party/rust/crossbeam-channel/CHANGELOG.md |
|
32 @@ -1,8 +1,16 @@ |
|
33 +# Version 0.5.4 |
|
34 + |
|
35 +- Workaround a bug in upstream related to TLS access on AArch64 Linux. (#802) |
|
36 + |
|
37 +# Version 0.5.3 |
|
38 + |
|
39 +- Fix panic on very large timeout. (#798) |
|
40 + |
|
41 # Version 0.5.2 |
|
42 |
|
43 -- Fix stacked borrows violations. (#763, #764) |
|
44 +- Fix stacked borrows violations when `-Zmiri-tag-raw-pointers` is enabled. (#763, #764) |
|
45 |
|
46 # Version 0.5.1 |
|
47 |
|
48 - Fix memory leak in unbounded channel. (#669) |
|
49 |
|
50 @@ -19,10 +27,12 @@ |
|
51 |
|
52 - Fix bug in release (yanking 0.4.3) |
|
53 - Fix UB and breaking change introduced in 0.4.3 |
|
54 |
|
55 # Version 0.4.3 |
|
56 + |
|
57 +**Note**: This release has been yanked. See [CVE-2020-15254](https://github.com/crossbeam-rs/crossbeam/security/advisories/GHSA-v5m7-53cv-f3hx) for details. |
|
58 |
|
59 - Change license to "MIT OR Apache-2.0". |
|
60 |
|
61 # Version 0.4.2 |
|
62 |
|
63 diff --git a/third_party/rust/crossbeam-channel/Cargo.lock b/third_party/rust/crossbeam-channel/Cargo.lock |
|
64 --- a/third_party/rust/crossbeam-channel/Cargo.lock |
|
65 +++ b/third_party/rust/crossbeam-channel/Cargo.lock |
|
66 @@ -8,34 +8,34 @@ |
|
67 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
68 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" |
|
69 |
|
70 [[package]] |
|
71 name = "crossbeam-channel" |
|
72 -version = "0.5.2" |
|
73 +version = "0.5.4" |
|
74 dependencies = [ |
|
75 "cfg-if", |
|
76 "crossbeam-utils", |
|
77 "num_cpus", |
|
78 "rand", |
|
79 "signal-hook", |
|
80 ] |
|
81 |
|
82 [[package]] |
|
83 name = "crossbeam-utils" |
|
84 -version = "0.8.6" |
|
85 +version = "0.8.8" |
|
86 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
87 -checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" |
|
88 +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" |
|
89 dependencies = [ |
|
90 "cfg-if", |
|
91 "lazy_static", |
|
92 ] |
|
93 |
|
94 [[package]] |
|
95 name = "getrandom" |
|
96 -version = "0.2.3" |
|
97 +version = "0.2.5" |
|
98 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
99 -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" |
|
100 +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" |
|
101 dependencies = [ |
|
102 "cfg-if", |
|
103 "libc", |
|
104 "wasi", |
|
105 ] |
|
106 @@ -55,13 +55,13 @@ |
|
107 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
108 checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" |
|
109 |
|
110 [[package]] |
|
111 name = "libc" |
|
112 -version = "0.2.112" |
|
113 +version = "0.2.120" |
|
114 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
115 -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" |
|
116 +checksum = "ad5c14e80759d0939d013e6ca49930e59fc53dd8e5009132f76240c179380c09" |
|
117 |
|
118 [[package]] |
|
119 name = "num_cpus" |
|
120 version = "1.13.1" |
|
121 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
122 @@ -77,18 +77,17 @@ |
|
123 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
124 checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" |
|
125 |
|
126 [[package]] |
|
127 name = "rand" |
|
128 -version = "0.8.4" |
|
129 +version = "0.8.5" |
|
130 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
131 -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" |
|
132 +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" |
|
133 dependencies = [ |
|
134 "libc", |
|
135 "rand_chacha", |
|
136 "rand_core", |
|
137 - "rand_hc", |
|
138 ] |
|
139 |
|
140 [[package]] |
|
141 name = "rand_chacha" |
|
142 version = "0.3.1" |
|
143 @@ -104,19 +103,10 @@ |
|
144 version = "0.6.3" |
|
145 source = "registry+https://github.com/rust-lang/crates.io-index" |
|
146 checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" |
|
147 dependencies = [ |
|
148 "getrandom", |
|
149 -] |
|
150 - |
|
151 -[[package]] |
|
152 -name = "rand_hc" |
|
153 -version = "0.3.1" |
|
154 -source = "registry+https://github.com/rust-lang/crates.io-index" |
|
155 -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" |
|
156 -dependencies = [ |
|
157 - "rand_core", |
|
158 ] |
|
159 |
|
160 [[package]] |
|
161 name = "signal-hook" |
|
162 version = "0.3.13" |
|
163 diff --git a/third_party/rust/crossbeam-channel/Cargo.toml b/third_party/rust/crossbeam-channel/Cargo.toml |
|
164 --- a/third_party/rust/crossbeam-channel/Cargo.toml |
|
165 +++ b/third_party/rust/crossbeam-channel/Cargo.toml |
|
166 @@ -11,24 +11,36 @@ |
|
167 |
|
168 [package] |
|
169 edition = "2018" |
|
170 rust-version = "1.36" |
|
171 name = "crossbeam-channel" |
|
172 -version = "0.5.2" |
|
173 +version = "0.5.4" |
|
174 description = "Multi-producer multi-consumer channels for message passing" |
|
175 homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel" |
|
176 -keywords = ["channel", "mpmc", "select", "golang", "message"] |
|
177 -categories = ["algorithms", "concurrency", "data-structures"] |
|
178 +keywords = [ |
|
179 + "channel", |
|
180 + "mpmc", |
|
181 + "select", |
|
182 + "golang", |
|
183 + "message", |
|
184 +] |
|
185 +categories = [ |
|
186 + "algorithms", |
|
187 + "concurrency", |
|
188 + "data-structures", |
|
189 +] |
|
190 license = "MIT OR Apache-2.0" |
|
191 repository = "https://github.com/crossbeam-rs/crossbeam" |
|
192 + |
|
193 [dependencies.cfg-if] |
|
194 version = "1" |
|
195 |
|
196 [dependencies.crossbeam-utils] |
|
197 version = "0.8" |
|
198 optional = true |
|
199 default-features = false |
|
200 + |
|
201 [dev-dependencies.num_cpus] |
|
202 version = "1.13.0" |
|
203 |
|
204 [dev-dependencies.rand] |
|
205 version = "0.8" |
|
206 diff --git a/third_party/rust/crossbeam-channel/src/channel.rs b/third_party/rust/crossbeam-channel/src/channel.rs |
|
207 --- a/third_party/rust/crossbeam-channel/src/channel.rs |
|
208 +++ b/third_party/rust/crossbeam-channel/src/channel.rs |
|
209 @@ -12,10 +12,11 @@ |
|
210 use crate::err::{ |
|
211 RecvError, RecvTimeoutError, SendError, SendTimeoutError, TryRecvError, TrySendError, |
|
212 }; |
|
213 use crate::flavors; |
|
214 use crate::select::{Operation, SelectHandle, Token}; |
|
215 +use crate::utils; |
|
216 |
|
217 /// Creates a channel of unbounded capacity. |
|
218 /// |
|
219 /// This channel has a growable buffer that can hold any number of messages at a time. |
|
220 /// |
|
221 @@ -469,11 +470,11 @@ |
|
222 /// s.send_timeout(3, Duration::from_millis(500)), |
|
223 /// Err(SendTimeoutError::Disconnected(3)), |
|
224 /// ); |
|
225 /// ``` |
|
226 pub fn send_timeout(&self, msg: T, timeout: Duration) -> Result<(), SendTimeoutError<T>> { |
|
227 - self.send_deadline(msg, Instant::now() + timeout) |
|
228 + self.send_deadline(msg, utils::convert_timeout_to_deadline(timeout)) |
|
229 } |
|
230 |
|
231 /// Waits for a message to be sent into the channel, but only until a given deadline. |
|
232 /// |
|
233 /// If the channel is full and not disconnected, this call will block until the send operation |
|
234 @@ -859,11 +860,11 @@ |
|
235 /// r.recv_timeout(Duration::from_secs(1)), |
|
236 /// Err(RecvTimeoutError::Disconnected), |
|
237 /// ); |
|
238 /// ``` |
|
239 pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError> { |
|
240 - self.recv_deadline(Instant::now() + timeout) |
|
241 + self.recv_deadline(utils::convert_timeout_to_deadline(timeout)) |
|
242 } |
|
243 |
|
244 /// Waits for a message to be received from the channel, but only before a given deadline. |
|
245 /// |
|
246 /// If the channel is empty and not disconnected, this call will block until the receive |
|
247 diff --git a/third_party/rust/crossbeam-channel/src/err.rs b/third_party/rust/crossbeam-channel/src/err.rs |
|
248 --- a/third_party/rust/crossbeam-channel/src/err.rs |
|
249 +++ b/third_party/rust/crossbeam-channel/src/err.rs |
|
250 @@ -306,20 +306,18 @@ |
|
251 } |
|
252 } |
|
253 |
|
254 impl TryRecvError { |
|
255 /// Returns `true` if the receive operation failed because the channel is empty. |
|
256 - #[allow(clippy::trivially_copy_pass_by_ref)] |
|
257 pub fn is_empty(&self) -> bool { |
|
258 match self { |
|
259 TryRecvError::Empty => true, |
|
260 _ => false, |
|
261 } |
|
262 } |
|
263 |
|
264 /// Returns `true` if the receive operation failed because the channel is disconnected. |
|
265 - #[allow(clippy::trivially_copy_pass_by_ref)] |
|
266 pub fn is_disconnected(&self) -> bool { |
|
267 match self { |
|
268 TryRecvError::Disconnected => true, |
|
269 _ => false, |
|
270 } |
|
271 @@ -345,20 +343,18 @@ |
|
272 } |
|
273 } |
|
274 |
|
275 impl RecvTimeoutError { |
|
276 /// Returns `true` if the receive operation timed out. |
|
277 - #[allow(clippy::trivially_copy_pass_by_ref)] |
|
278 pub fn is_timeout(&self) -> bool { |
|
279 match self { |
|
280 RecvTimeoutError::Timeout => true, |
|
281 _ => false, |
|
282 } |
|
283 } |
|
284 |
|
285 /// Returns `true` if the receive operation failed because the channel is disconnected. |
|
286 - #[allow(clippy::trivially_copy_pass_by_ref)] |
|
287 pub fn is_disconnected(&self) -> bool { |
|
288 match self { |
|
289 RecvTimeoutError::Disconnected => true, |
|
290 _ => false, |
|
291 } |
|
292 diff --git a/third_party/rust/crossbeam-channel/src/flavors/array.rs b/third_party/rust/crossbeam-channel/src/flavors/array.rs |
|
293 --- a/third_party/rust/crossbeam-channel/src/flavors/array.rs |
|
294 +++ b/third_party/rust/crossbeam-channel/src/flavors/array.rs |
|
295 @@ -7,11 +7,10 @@ |
|
296 //! Source: |
|
297 //! - <http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue> |
|
298 //! - <https://docs.google.com/document/d/1yIAYmbvL3JxOKOjuCyon7JhW4cSv1wy5hC0ApeGMV9s/pub> |
|
299 |
|
300 use std::cell::UnsafeCell; |
|
301 -use std::marker::PhantomData; |
|
302 use std::mem::MaybeUninit; |
|
303 use std::ptr; |
|
304 use std::sync::atomic::{self, AtomicUsize, Ordering}; |
|
305 use std::time::Instant; |
|
306 |
|
307 @@ -31,11 +30,11 @@ |
|
308 msg: UnsafeCell<MaybeUninit<T>>, |
|
309 } |
|
310 |
|
311 /// The token type for the array flavor. |
|
312 #[derive(Debug)] |
|
313 -pub struct ArrayToken { |
|
314 +pub(crate) struct ArrayToken { |
|
315 /// Slot to read from or write to. |
|
316 slot: *const u8, |
|
317 |
|
318 /// Stamp to store into the slot after reading or writing. |
|
319 stamp: usize, |
|
320 @@ -70,11 +69,11 @@ |
|
321 /// |
|
322 /// Messages are pushed into the tail of the channel. |
|
323 tail: CachePadded<AtomicUsize>, |
|
324 |
|
325 /// The buffer holding slots. |
|
326 - buffer: *mut Slot<T>, |
|
327 + buffer: Box<[Slot<T>]>, |
|
328 |
|
329 /// The channel capacity. |
|
330 cap: usize, |
|
331 |
|
332 /// A stamp with the value of `{ lap: 1, mark: 0, index: 0 }`. |
|
333 @@ -86,13 +85,10 @@ |
|
334 /// Senders waiting while the channel is full. |
|
335 senders: SyncWaker, |
|
336 |
|
337 /// Receivers waiting while the channel is empty and not disconnected. |
|
338 receivers: SyncWaker, |
|
339 - |
|
340 - /// Indicates that dropping a `Channel<T>` may drop values of type `T`. |
|
341 - _marker: PhantomData<T>, |
|
342 } |
|
343 |
|
344 impl<T> Channel<T> { |
|
345 /// Creates a bounded channel of capacity `cap`. |
|
346 pub(crate) fn with_capacity(cap: usize) -> Self { |
|
347 @@ -107,33 +103,29 @@ |
|
348 // Tail is initialized to `{ lap: 0, mark: 0, index: 0 }`. |
|
349 let tail = 0; |
|
350 |
|
351 // Allocate a buffer of `cap` slots initialized |
|
352 // with stamps. |
|
353 - let buffer = { |
|
354 - let boxed: Box<[Slot<T>]> = (0..cap) |
|
355 - .map(|i| { |
|
356 - // Set the stamp to `{ lap: 0, mark: 0, index: i }`. |
|
357 - Slot { |
|
358 - stamp: AtomicUsize::new(i), |
|
359 - msg: UnsafeCell::new(MaybeUninit::uninit()), |
|
360 - } |
|
361 - }) |
|
362 - .collect(); |
|
363 - Box::into_raw(boxed) as *mut Slot<T> |
|
364 - }; |
|
365 + let buffer: Box<[Slot<T>]> = (0..cap) |
|
366 + .map(|i| { |
|
367 + // Set the stamp to `{ lap: 0, mark: 0, index: i }`. |
|
368 + Slot { |
|
369 + stamp: AtomicUsize::new(i), |
|
370 + msg: UnsafeCell::new(MaybeUninit::uninit()), |
|
371 + } |
|
372 + }) |
|
373 + .collect(); |
|
374 |
|
375 Channel { |
|
376 buffer, |
|
377 cap, |
|
378 one_lap, |
|
379 mark_bit, |
|
380 head: CachePadded::new(AtomicUsize::new(head)), |
|
381 tail: CachePadded::new(AtomicUsize::new(tail)), |
|
382 senders: SyncWaker::new(), |
|
383 receivers: SyncWaker::new(), |
|
384 - _marker: PhantomData, |
|
385 } |
|
386 } |
|
387 |
|
388 /// Returns a receiver handle to the channel. |
|
389 pub(crate) fn receiver(&self) -> Receiver<'_, T> { |
|
390 @@ -161,11 +153,12 @@ |
|
391 // Deconstruct the tail. |
|
392 let index = tail & (self.mark_bit - 1); |
|
393 let lap = tail & !(self.one_lap - 1); |
|
394 |
|
395 // Inspect the corresponding slot. |
|
396 - let slot = unsafe { &*self.buffer.add(index) }; |
|
397 + debug_assert!(index < self.buffer.len()); |
|
398 + let slot = unsafe { self.buffer.get_unchecked(index) }; |
|
399 let stamp = slot.stamp.load(Ordering::Acquire); |
|
400 |
|
401 // If the tail and the stamp match, we may attempt to push. |
|
402 if tail == stamp { |
|
403 let new_tail = if index + 1 < self.cap { |
|
404 @@ -243,11 +236,12 @@ |
|
405 // Deconstruct the head. |
|
406 let index = head & (self.mark_bit - 1); |
|
407 let lap = head & !(self.one_lap - 1); |
|
408 |
|
409 // Inspect the corresponding slot. |
|
410 - let slot = unsafe { &*self.buffer.add(index) }; |
|
411 + debug_assert!(index < self.buffer.len()); |
|
412 + let slot = unsafe { self.buffer.get_unchecked(index) }; |
|
413 let stamp = slot.stamp.load(Ordering::Acquire); |
|
414 |
|
415 // If the the stamp is ahead of the head by 1, we may attempt to pop. |
|
416 if head + 1 == stamp { |
|
417 let new = if index + 1 < self.cap { |
|
418 @@ -473,11 +467,10 @@ |
|
419 } |
|
420 } |
|
421 } |
|
422 |
|
423 /// Returns the capacity of the channel. |
|
424 - #[allow(clippy::unnecessary_wraps)] // This is intentional. |
|
425 pub(crate) fn capacity(&self) -> Option<usize> { |
|
426 Some(self.cap) |
|
427 } |
|
428 |
|
429 /// Disconnects the channel and wakes up all blocked senders and receivers. |
|
430 @@ -538,26 +531,15 @@ |
|
431 } else { |
|
432 hix + i - self.cap |
|
433 }; |
|
434 |
|
435 unsafe { |
|
436 - let p = { |
|
437 - let slot = &mut *self.buffer.add(index); |
|
438 - let msg = &mut *slot.msg.get(); |
|
439 - msg.as_mut_ptr() |
|
440 - }; |
|
441 - p.drop_in_place(); |
|
442 - } |
|
443 - } |
|
444 - |
|
445 - // Finally, deallocate the buffer, but don't run any destructors. |
|
446 - unsafe { |
|
447 - // Create a slice from the buffer to make |
|
448 - // a fat pointer. Then, use Box::from_raw |
|
449 - // to deallocate it. |
|
450 - let ptr = std::slice::from_raw_parts_mut(self.buffer, self.cap) as *mut [Slot<T>]; |
|
451 - Box::from_raw(ptr); |
|
452 + debug_assert!(index < self.buffer.len()); |
|
453 + let slot = self.buffer.get_unchecked_mut(index); |
|
454 + let msg = &mut *slot.msg.get(); |
|
455 + msg.as_mut_ptr().drop_in_place(); |
|
456 + } |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 /// Receiver handle to a channel. |
|
462 diff --git a/third_party/rust/crossbeam-channel/src/flavors/at.rs b/third_party/rust/crossbeam-channel/src/flavors/at.rs |
|
463 --- a/third_party/rust/crossbeam-channel/src/flavors/at.rs |
|
464 +++ b/third_party/rust/crossbeam-channel/src/flavors/at.rs |
|
465 @@ -33,11 +33,11 @@ |
|
466 } |
|
467 } |
|
468 /// Creates a channel that delivers a message after a certain duration of time. |
|
469 #[inline] |
|
470 pub(crate) fn new_timeout(dur: Duration) -> Self { |
|
471 - Self::new_deadline(Instant::now() + dur) |
|
472 + Self::new_deadline(utils::convert_timeout_to_deadline(dur)) |
|
473 } |
|
474 |
|
475 /// Attempts to receive a message without blocking. |
|
476 #[inline] |
|
477 pub(crate) fn try_recv(&self) -> Result<Instant, TryRecvError> { |
|
478 @@ -140,11 +140,10 @@ |
|
479 1 |
|
480 } |
|
481 } |
|
482 |
|
483 /// Returns the capacity of the channel. |
|
484 - #[allow(clippy::unnecessary_wraps)] // This is intentional. |
|
485 #[inline] |
|
486 pub(crate) fn capacity(&self) -> Option<usize> { |
|
487 Some(1) |
|
488 } |
|
489 } |
|
490 diff --git a/third_party/rust/crossbeam-channel/src/flavors/list.rs b/third_party/rust/crossbeam-channel/src/flavors/list.rs |
|
491 --- a/third_party/rust/crossbeam-channel/src/flavors/list.rs |
|
492 +++ b/third_party/rust/crossbeam-channel/src/flavors/list.rs |
|
493 @@ -124,11 +124,11 @@ |
|
494 block: AtomicPtr<Block<T>>, |
|
495 } |
|
496 |
|
497 /// The token type for the list flavor. |
|
498 #[derive(Debug)] |
|
499 -pub struct ListToken { |
|
500 +pub(crate) struct ListToken { |
|
501 /// The block of slots. |
|
502 block: *const u8, |
|
503 |
|
504 /// The offset into the block. |
|
505 offset: usize, |
|
506 diff --git a/third_party/rust/crossbeam-channel/src/flavors/never.rs b/third_party/rust/crossbeam-channel/src/flavors/never.rs |
|
507 --- a/third_party/rust/crossbeam-channel/src/flavors/never.rs |
|
508 +++ b/third_party/rust/crossbeam-channel/src/flavors/never.rs |
|
509 @@ -63,11 +63,10 @@ |
|
510 pub(crate) fn len(&self) -> usize { |
|
511 0 |
|
512 } |
|
513 |
|
514 /// Returns the capacity of the channel. |
|
515 - #[allow(clippy::unnecessary_wraps)] // This is intentional. |
|
516 #[inline] |
|
517 pub(crate) fn capacity(&self) -> Option<usize> { |
|
518 Some(0) |
|
519 } |
|
520 } |
|
521 diff --git a/third_party/rust/crossbeam-channel/src/flavors/tick.rs b/third_party/rust/crossbeam-channel/src/flavors/tick.rs |
|
522 --- a/third_party/rust/crossbeam-channel/src/flavors/tick.rs |
|
523 +++ b/third_party/rust/crossbeam-channel/src/flavors/tick.rs |
|
524 @@ -8,10 +8,11 @@ |
|
525 use crossbeam_utils::atomic::AtomicCell; |
|
526 |
|
527 use crate::context::Context; |
|
528 use crate::err::{RecvTimeoutError, TryRecvError}; |
|
529 use crate::select::{Operation, SelectHandle, Token}; |
|
530 +use crate::utils; |
|
531 |
|
532 /// Result of a receive operation. |
|
533 pub(crate) type TickToken = Option<Instant>; |
|
534 |
|
535 /// Channel that delivers messages periodically. |
|
536 @@ -26,11 +27,11 @@ |
|
537 impl Channel { |
|
538 /// Creates a channel that delivers messages periodically. |
|
539 #[inline] |
|
540 pub(crate) fn new(dur: Duration) -> Self { |
|
541 Channel { |
|
542 - delivery_time: AtomicCell::new(Instant::now() + dur), |
|
543 + delivery_time: AtomicCell::new(utils::convert_timeout_to_deadline(dur)), |
|
544 duration: dur, |
|
545 } |
|
546 } |
|
547 |
|
548 /// Attempts to receive a message without blocking. |
|
549 @@ -110,11 +111,10 @@ |
|
550 1 |
|
551 } |
|
552 } |
|
553 |
|
554 /// Returns the capacity of the channel. |
|
555 - #[allow(clippy::unnecessary_wraps)] // This is intentional. |
|
556 #[inline] |
|
557 pub(crate) fn capacity(&self) -> Option<usize> { |
|
558 Some(1) |
|
559 } |
|
560 } |
|
561 diff --git a/third_party/rust/crossbeam-channel/src/flavors/zero.rs b/third_party/rust/crossbeam-channel/src/flavors/zero.rs |
|
562 --- a/third_party/rust/crossbeam-channel/src/flavors/zero.rs |
|
563 +++ b/third_party/rust/crossbeam-channel/src/flavors/zero.rs |
|
564 @@ -15,11 +15,11 @@ |
|
565 use crate::select::{Operation, SelectHandle, Selected, Token}; |
|
566 use crate::utils::Spinlock; |
|
567 use crate::waker::Waker; |
|
568 |
|
569 /// A pointer to a packet. |
|
570 -pub struct ZeroToken(*mut ()); |
|
571 +pub(crate) struct ZeroToken(*mut ()); |
|
572 |
|
573 impl Default for ZeroToken { |
|
574 fn default() -> Self { |
|
575 Self(ptr::null_mut()) |
|
576 } |
|
577 @@ -361,11 +361,10 @@ |
|
578 pub(crate) fn len(&self) -> usize { |
|
579 0 |
|
580 } |
|
581 |
|
582 /// Returns the capacity of the channel. |
|
583 - #[allow(clippy::unnecessary_wraps)] // This is intentional. |
|
584 pub(crate) fn capacity(&self) -> Option<usize> { |
|
585 Some(0) |
|
586 } |
|
587 |
|
588 /// Returns `true` if the channel is empty. |
|
589 diff --git a/third_party/rust/crossbeam-channel/src/select.rs b/third_party/rust/crossbeam-channel/src/select.rs |
|
590 --- a/third_party/rust/crossbeam-channel/src/select.rs |
|
591 +++ b/third_party/rust/crossbeam-channel/src/select.rs |
|
592 @@ -20,16 +20,17 @@ |
|
593 /// |
|
594 /// Each field contains data associated with a specific channel flavor. |
|
595 // This is a private API that is used by the select macro. |
|
596 #[derive(Debug, Default)] |
|
597 pub struct Token { |
|
598 - pub at: flavors::at::AtToken, |
|
599 - pub array: flavors::array::ArrayToken, |
|
600 - pub list: flavors::list::ListToken, |
|
601 - pub never: flavors::never::NeverToken, |
|
602 - pub tick: flavors::tick::TickToken, |
|
603 - pub zero: flavors::zero::ZeroToken, |
|
604 + pub(crate) at: flavors::at::AtToken, |
|
605 + pub(crate) array: flavors::array::ArrayToken, |
|
606 + pub(crate) list: flavors::list::ListToken, |
|
607 + #[allow(dead_code)] |
|
608 + pub(crate) never: flavors::never::NeverToken, |
|
609 + pub(crate) tick: flavors::tick::TickToken, |
|
610 + pub(crate) zero: flavors::zero::ZeroToken, |
|
611 } |
|
612 |
|
613 /// Identifier associated with an operation by a specific thread on a specific channel. |
|
614 #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
|
615 pub struct Operation(usize); |
|
616 @@ -484,11 +485,11 @@ |
|
617 #[inline] |
|
618 pub fn select_timeout<'a>( |
|
619 handles: &mut [(&'a dyn SelectHandle, usize, *const u8)], |
|
620 timeout: Duration, |
|
621 ) -> Result<SelectedOperation<'a>, SelectTimeoutError> { |
|
622 - select_deadline(handles, Instant::now() + timeout) |
|
623 + select_deadline(handles, utils::convert_timeout_to_deadline(timeout)) |
|
624 } |
|
625 |
|
626 /// Blocks until a given deadline, or until one of the operations becomes ready and selects it. |
|
627 #[inline] |
|
628 pub(crate) fn select_deadline<'a>( |
|
629 @@ -1040,11 +1041,11 @@ |
|
630 /// Ok(i) if i == oper2 => assert_eq!(r2.try_recv(), Ok(20)), |
|
631 /// Ok(_) => unreachable!(), |
|
632 /// } |
|
633 /// ``` |
|
634 pub fn ready_timeout(&mut self, timeout: Duration) -> Result<usize, ReadyTimeoutError> { |
|
635 - self.ready_deadline(Instant::now() + timeout) |
|
636 + self.ready_deadline(utils::convert_timeout_to_deadline(timeout)) |
|
637 } |
|
638 |
|
639 /// Blocks until a given deadline, or until one of the operations becomes ready. |
|
640 /// |
|
641 /// If an operation becomes ready, its index is returned. If multiple operations are ready at |
|
642 diff --git a/third_party/rust/crossbeam-channel/src/select_macro.rs b/third_party/rust/crossbeam-channel/src/select_macro.rs |
|
643 --- a/third_party/rust/crossbeam-channel/src/select_macro.rs |
|
644 +++ b/third_party/rust/crossbeam-channel/src/select_macro.rs |
|
645 @@ -119,22 +119,11 @@ |
|
646 ($($head)* $case ($($args)*) $(-> $res)* => { $body },) |
|
647 ) |
|
648 }; |
|
649 // Only one case remains. |
|
650 (@list |
|
651 - ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:expr) |
|
652 - ($($head:tt)*) |
|
653 - ) => { |
|
654 - $crate::crossbeam_channel_internal!( |
|
655 - @list |
|
656 - () |
|
657 - ($($head)* $case ($($args)*) $(-> $res)* => { $body },) |
|
658 - ) |
|
659 - }; |
|
660 - // Accept a trailing comma at the end of the list. |
|
661 - (@list |
|
662 - ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:expr,) |
|
663 + ($case:ident ($($args:tt)*) $(-> $res:pat)* => $body:expr $(,)?) |
|
664 ($($head:tt)*) |
|
665 ) => { |
|
666 $crate::crossbeam_channel_internal!( |
|
667 @list |
|
668 () |
|
669 @@ -371,34 +360,21 @@ |
|
670 ) |
|
671 }; |
|
672 |
|
673 // Check the format of a recv case. |
|
674 (@case |
|
675 - (recv($r:expr) -> $res:pat => $body:tt, $($tail:tt)*) |
|
676 + (recv($r:expr $(,)?) -> $res:pat => $body:tt, $($tail:tt)*) |
|
677 ($($cases:tt)*) |
|
678 $default:tt |
|
679 ) => { |
|
680 $crate::crossbeam_channel_internal!( |
|
681 @case |
|
682 ($($tail)*) |
|
683 ($($cases)* recv($r) -> $res => $body,) |
|
684 $default |
|
685 ) |
|
686 }; |
|
687 - // Allow trailing comma... |
|
688 - (@case |
|
689 - (recv($r:expr,) -> $res:pat => $body:tt, $($tail:tt)*) |
|
690 - ($($cases:tt)*) |
|
691 - $default:tt |
|
692 - ) => { |
|
693 - $crate::crossbeam_channel_internal!( |
|
694 - @case |
|
695 - ($($tail)*) |
|
696 - ($($cases)* recv($r) -> $res => $body,) |
|
697 - $default |
|
698 - ) |
|
699 - }; |
|
700 // Print an error if the argument list is invalid. |
|
701 (@case |
|
702 (recv($($args:tt)*) -> $res:pat => $body:tt, $($tail:tt)*) |
|
703 ($($cases:tt)*) |
|
704 $default:tt |
|
705 @@ -426,34 +402,21 @@ |
|
706 ) |
|
707 }; |
|
708 |
|
709 // Check the format of a send case. |
|
710 (@case |
|
711 - (send($s:expr, $m:expr) -> $res:pat => $body:tt, $($tail:tt)*) |
|
712 + (send($s:expr, $m:expr $(,)?) -> $res:pat => $body:tt, $($tail:tt)*) |
|
713 ($($cases:tt)*) |
|
714 $default:tt |
|
715 ) => { |
|
716 $crate::crossbeam_channel_internal!( |
|
717 @case |
|
718 ($($tail)*) |
|
719 ($($cases)* send($s, $m) -> $res => $body,) |
|
720 $default |
|
721 ) |
|
722 }; |
|
723 - // Allow trailing comma... |
|
724 - (@case |
|
725 - (send($s:expr, $m:expr,) -> $res:pat => $body:tt, $($tail:tt)*) |
|
726 - ($($cases:tt)*) |
|
727 - $default:tt |
|
728 - ) => { |
|
729 - $crate::crossbeam_channel_internal!( |
|
730 - @case |
|
731 - ($($tail)*) |
|
732 - ($($cases)* send($s, $m) -> $res => $body,) |
|
733 - $default |
|
734 - ) |
|
735 - }; |
|
736 // Print an error if the argument list is invalid. |
|
737 (@case |
|
738 (send($($args:tt)*) -> $res:pat => $body:tt, $($tail:tt)*) |
|
739 ($($cases:tt)*) |
|
740 $default:tt |
|
741 @@ -494,24 +457,11 @@ |
|
742 (default() => $body,) |
|
743 ) |
|
744 }; |
|
745 // Check the format of a default case with timeout. |
|
746 (@case |
|
747 - (default($timeout:expr) => $body:tt, $($tail:tt)*) |
|
748 - $cases:tt |
|
749 - () |
|
750 - ) => { |
|
751 - $crate::crossbeam_channel_internal!( |
|
752 - @case |
|
753 - ($($tail)*) |
|
754 - $cases |
|
755 - (default($timeout) => $body,) |
|
756 - ) |
|
757 - }; |
|
758 - // Allow trailing comma... |
|
759 - (@case |
|
760 - (default($timeout:expr,) => $body:tt, $($tail:tt)*) |
|
761 + (default($timeout:expr $(,)?) => $body:tt, $($tail:tt)*) |
|
762 $cases:tt |
|
763 () |
|
764 ) => { |
|
765 $crate::crossbeam_channel_internal!( |
|
766 @case |
|
767 diff --git a/third_party/rust/crossbeam-channel/src/utils.rs b/third_party/rust/crossbeam-channel/src/utils.rs |
|
768 --- a/third_party/rust/crossbeam-channel/src/utils.rs |
|
769 +++ b/third_party/rust/crossbeam-channel/src/utils.rs |
|
770 @@ -59,10 +59,18 @@ |
|
771 } |
|
772 } |
|
773 } |
|
774 } |
|
775 |
|
776 +// https://github.com/crossbeam-rs/crossbeam/issues/795 |
|
777 +pub(crate) fn convert_timeout_to_deadline(timeout: Duration) -> Instant { |
|
778 + match Instant::now().checked_add(timeout) { |
|
779 + Some(deadline) => deadline, |
|
780 + None => Instant::now() + Duration::from_secs(86400 * 365 * 30), |
|
781 + } |
|
782 +} |
|
783 + |
|
784 /// A simple spinlock. |
|
785 pub(crate) struct Spinlock<T> { |
|
786 flag: AtomicBool, |
|
787 value: UnsafeCell<T>, |
|
788 } |
|
789 diff --git a/third_party/rust/crossbeam-channel/src/waker.rs b/third_party/rust/crossbeam-channel/src/waker.rs |
|
790 --- a/third_party/rust/crossbeam-channel/src/waker.rs |
|
791 +++ b/third_party/rust/crossbeam-channel/src/waker.rs |
|
792 @@ -75,30 +75,36 @@ |
|
793 } |
|
794 |
|
795 /// Attempts to find another thread's entry, select the operation, and wake it up. |
|
796 #[inline] |
|
797 pub(crate) fn try_select(&mut self) -> Option<Entry> { |
|
798 - self.selectors |
|
799 - .iter() |
|
800 - .position(|selector| { |
|
801 - // Does the entry belong to a different thread? |
|
802 - selector.cx.thread_id() != current_thread_id() |
|
803 - && selector // Try selecting this operation. |
|
804 - .cx |
|
805 - .try_select(Selected::Operation(selector.oper)) |
|
806 - .is_ok() |
|
807 - && { |
|
808 - // Provide the packet. |
|
809 - selector.cx.store_packet(selector.packet); |
|
810 - // Wake the thread up. |
|
811 - selector.cx.unpark(); |
|
812 - true |
|
813 - } |
|
814 - }) |
|
815 - // Remove the entry from the queue to keep it clean and improve |
|
816 - // performance. |
|
817 - .map(|pos| self.selectors.remove(pos)) |
|
818 + if self.selectors.is_empty() { |
|
819 + None |
|
820 + } else { |
|
821 + let thread_id = current_thread_id(); |
|
822 + |
|
823 + self.selectors |
|
824 + .iter() |
|
825 + .position(|selector| { |
|
826 + // Does the entry belong to a different thread? |
|
827 + selector.cx.thread_id() != thread_id |
|
828 + && selector // Try selecting this operation. |
|
829 + .cx |
|
830 + .try_select(Selected::Operation(selector.oper)) |
|
831 + .is_ok() |
|
832 + && { |
|
833 + // Provide the packet. |
|
834 + selector.cx.store_packet(selector.packet); |
|
835 + // Wake the thread up. |
|
836 + selector.cx.unpark(); |
|
837 + true |
|
838 + } |
|
839 + }) |
|
840 + // Remove the entry from the queue to keep it clean and improve |
|
841 + // performance. |
|
842 + .map(|pos| self.selectors.remove(pos)) |
|
843 + } |
|
844 } |
|
845 |
|
846 /// Returns `true` if there is an entry which can be selected by the current thread. |
|
847 #[inline] |
|
848 pub(crate) fn can_select(&self) -> bool { |
|
849 diff --git a/third_party/rust/crossbeam-channel/tests/array.rs b/third_party/rust/crossbeam-channel/tests/array.rs |
|
850 --- a/third_party/rust/crossbeam-channel/tests/array.rs |
|
851 +++ b/third_party/rust/crossbeam-channel/tests/array.rs |
|
852 @@ -1,8 +1,6 @@ |
|
853 //! Tests for the array channel flavor. |
|
854 - |
|
855 -#![cfg(not(miri))] // TODO: many assertions failed due to Miri is slow |
|
856 |
|
857 use std::any::Any; |
|
858 use std::sync::atomic::AtomicUsize; |
|
859 use std::sync::atomic::Ordering; |
|
860 use std::thread; |
|
861 @@ -252,11 +250,17 @@ |
|
862 assert_eq!(r.recv(), Err(RecvError)); |
|
863 } |
|
864 |
|
865 #[test] |
|
866 fn len() { |
|
867 + #[cfg(miri)] |
|
868 + const COUNT: usize = 250; |
|
869 + #[cfg(not(miri))] |
|
870 const COUNT: usize = 25_000; |
|
871 + #[cfg(miri)] |
|
872 + const CAP: usize = 100; |
|
873 + #[cfg(not(miri))] |
|
874 const CAP: usize = 1000; |
|
875 |
|
876 let (s, r) = bounded(CAP); |
|
877 |
|
878 assert_eq!(s.len(), 0); |
|
879 @@ -345,10 +349,13 @@ |
|
880 .unwrap(); |
|
881 } |
|
882 |
|
883 #[test] |
|
884 fn spsc() { |
|
885 + #[cfg(miri)] |
|
886 + const COUNT: usize = 100; |
|
887 + #[cfg(not(miri))] |
|
888 const COUNT: usize = 100_000; |
|
889 |
|
890 let (s, r) = bounded(3); |
|
891 |
|
892 scope(|scope| { |
|
893 @@ -367,10 +374,13 @@ |
|
894 .unwrap(); |
|
895 } |
|
896 |
|
897 #[test] |
|
898 fn mpmc() { |
|
899 + #[cfg(miri)] |
|
900 + const COUNT: usize = 100; |
|
901 + #[cfg(not(miri))] |
|
902 const COUNT: usize = 25_000; |
|
903 const THREADS: usize = 4; |
|
904 |
|
905 let (s, r) = bounded::<usize>(3); |
|
906 let v = (0..COUNT).map(|_| AtomicUsize::new(0)).collect::<Vec<_>>(); |
|
907 @@ -399,10 +409,13 @@ |
|
908 } |
|
909 } |
|
910 |
|
911 #[test] |
|
912 fn stress_oneshot() { |
|
913 + #[cfg(miri)] |
|
914 + const COUNT: usize = 100; |
|
915 + #[cfg(not(miri))] |
|
916 const COUNT: usize = 10_000; |
|
917 |
|
918 for _ in 0..COUNT { |
|
919 let (s, r) = bounded(1); |
|
920 |
|
921 @@ -414,10 +427,13 @@ |
|
922 } |
|
923 } |
|
924 |
|
925 #[test] |
|
926 fn stress_iter() { |
|
927 + #[cfg(miri)] |
|
928 + const COUNT: usize = 100; |
|
929 + #[cfg(not(miri))] |
|
930 const COUNT: usize = 100_000; |
|
931 |
|
932 let (request_s, request_r) = bounded(1); |
|
933 let (response_s, response_r) = bounded(1); |
|
934 |
|
935 @@ -479,10 +495,11 @@ |
|
936 }); |
|
937 }) |
|
938 .unwrap(); |
|
939 } |
|
940 |
|
941 +#[cfg_attr(miri, ignore)] // Miri is too slow |
|
942 #[test] |
|
943 fn drops() { |
|
944 const RUNS: usize = 100; |
|
945 |
|
946 static DROPS: AtomicUsize = AtomicUsize::new(0); |
|
947 @@ -531,10 +548,13 @@ |
|
948 } |
|
949 } |
|
950 |
|
951 #[test] |
|
952 fn linearizable() { |
|
953 + #[cfg(miri)] |
|
954 + const COUNT: usize = 100; |
|
955 + #[cfg(not(miri))] |
|
956 const COUNT: usize = 25_000; |
|
957 const THREADS: usize = 4; |
|
958 |
|
959 let (s, r) = bounded(THREADS); |
|
960 |
|
961 @@ -551,10 +571,13 @@ |
|
962 .unwrap(); |
|
963 } |
|
964 |
|
965 #[test] |
|
966 fn fairness() { |
|
967 + #[cfg(miri)] |
|
968 + const COUNT: usize = 100; |
|
969 + #[cfg(not(miri))] |
|
970 const COUNT: usize = 10_000; |
|
971 |
|
972 let (s1, r1) = bounded::<()>(COUNT); |
|
973 let (s2, r2) = bounded::<()>(COUNT); |
|
974 |
|
975 @@ -573,10 +596,13 @@ |
|
976 assert!(hits.iter().all(|x| *x >= COUNT / hits.len() / 2)); |
|
977 } |
|
978 |
|
979 #[test] |
|
980 fn fairness_duplicates() { |
|
981 + #[cfg(miri)] |
|
982 + const COUNT: usize = 100; |
|
983 + #[cfg(not(miri))] |
|
984 const COUNT: usize = 10_000; |
|
985 |
|
986 let (s, r) = bounded::<()>(COUNT); |
|
987 |
|
988 for _ in 0..COUNT { |
|
989 @@ -617,10 +643,13 @@ |
|
990 } |
|
991 } |
|
992 |
|
993 #[test] |
|
994 fn channel_through_channel() { |
|
995 + #[cfg(miri)] |
|
996 + const COUNT: usize = 100; |
|
997 + #[cfg(not(miri))] |
|
998 const COUNT: usize = 1000; |
|
999 |
|
1000 type T = Box<dyn Any + Send>; |
|
1001 |
|
1002 let (s, r) = bounded::<T>(1); |
|
1003 @@ -652,5 +681,58 @@ |
|
1004 } |
|
1005 }); |
|
1006 }) |
|
1007 .unwrap(); |
|
1008 } |
|
1009 + |
|
1010 +#[test] |
|
1011 +fn panic_on_drop() { |
|
1012 + struct Msg1<'a>(&'a mut bool); |
|
1013 + impl Drop for Msg1<'_> { |
|
1014 + fn drop(&mut self) { |
|
1015 + if *self.0 && !std::thread::panicking() { |
|
1016 + panic!("double drop"); |
|
1017 + } else { |
|
1018 + *self.0 = true; |
|
1019 + } |
|
1020 + } |
|
1021 + } |
|
1022 + |
|
1023 + struct Msg2<'a>(&'a mut bool); |
|
1024 + impl Drop for Msg2<'_> { |
|
1025 + fn drop(&mut self) { |
|
1026 + if *self.0 { |
|
1027 + panic!("double drop"); |
|
1028 + } else { |
|
1029 + *self.0 = true; |
|
1030 + panic!("first drop"); |
|
1031 + } |
|
1032 + } |
|
1033 + } |
|
1034 + |
|
1035 + // normal |
|
1036 + let (s, r) = bounded(2); |
|
1037 + let (mut a, mut b) = (false, false); |
|
1038 + s.send(Msg1(&mut a)).unwrap(); |
|
1039 + s.send(Msg1(&mut b)).unwrap(); |
|
1040 + drop(s); |
|
1041 + drop(r); |
|
1042 + assert!(a); |
|
1043 + assert!(b); |
|
1044 + |
|
1045 + // panic on drop |
|
1046 + let (s, r) = bounded(2); |
|
1047 + let (mut a, mut b) = (false, false); |
|
1048 + s.send(Msg2(&mut a)).unwrap(); |
|
1049 + s.send(Msg2(&mut b)).unwrap(); |
|
1050 + drop(s); |
|
1051 + let res = std::panic::catch_unwind(move || { |
|
1052 + drop(r); |
|
1053 + }); |
|
1054 + assert_eq!( |
|
1055 + *res.unwrap_err().downcast_ref::<&str>().unwrap(), |
|
1056 + "first drop" |
|
1057 + ); |
|
1058 + assert!(a); |
|
1059 + // Elements after the panicked element will leak. |
|
1060 + assert!(!b); |
|
1061 +} |
|
1062 diff --git a/third_party/rust/crossbeam-channel/tests/select_macro.rs b/third_party/rust/crossbeam-channel/tests/select_macro.rs |
|
1063 --- a/third_party/rust/crossbeam-channel/tests/select_macro.rs |
|
1064 +++ b/third_party/rust/crossbeam-channel/tests/select_macro.rs |
|
1065 @@ -1466,5 +1466,16 @@ |
|
1066 drop(s); |
|
1067 }); |
|
1068 }) |
|
1069 .unwrap(); |
|
1070 } |
|
1071 + |
|
1072 +#[test] |
|
1073 +fn trailing_comma() { |
|
1074 + let (s, r) = unbounded::<usize>(); |
|
1075 + |
|
1076 + select! { |
|
1077 + send(s, 1,) -> _ => {}, |
|
1078 + recv(r,) -> _ => {}, |
|
1079 + default(ms(1000),) => {}, |
|
1080 + } |
|
1081 +} |
|
1082 |
|