Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
This commit is contained in:
1
vendor/crossbeam-deque/.cargo-checksum.json
vendored
Normal file
1
vendor/crossbeam-deque/.cargo-checksum.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"files":{"CHANGELOG.md":"23c4df815148a8d0cd366661313c629c115a022b3609d899665a1a079939ca46","Cargo.toml":"6f08856d95a287f5852ea0b333c2b44c0bfdd20a1430cae8632aaf6164a661a5","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5734ed989dfca1f625b40281ee9f4530f91b2411ec01cb748223e7eb87e201ab","README.md":"86445da156ad68ea1d1f2dc49a3cef942ccc377ff56316aefe89732ded763aba","src/deque.rs":"34c093fdd7df55d7838f023d00e4fff7d8cffb9c04b6bbe167c7bc7b8fee57a0","src/lib.rs":"9f0581481691bc698176f369410726adf597d470b9d14e226a65f490d6aff8c6","tests/fifo.rs":"3d98e0d4ca7cfddf10708b71642cf1ff05543d067ad837e48401d63cc31c0a18","tests/injector.rs":"fb054ef9fcac5f12e08b7b3451f370b96ab7589d32ef5c02e25958a473c45519","tests/lifo.rs":"57abdb3fc5920a422f785ba308b658bdc5400947532eeffb799f2395a2061549","tests/steal.rs":"cdf588cc13eeb275ef1231eb18e3245faca7a2d054fa6527bfdba2a34bc8f7bf"},"package":"fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751"}
|
133
vendor/crossbeam-deque/CHANGELOG.md
vendored
Normal file
133
vendor/crossbeam-deque/CHANGELOG.md
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
# Version 0.8.4
|
||||
|
||||
- Bump the minimum supported Rust version to 1.61. (#1037)
|
||||
|
||||
# Version 0.8.3
|
||||
|
||||
- Add `Stealer::{steal_batch_with_limit, steal_batch_with_limit_and_pop}` methods. (#903)
|
||||
- Add `Injector::{steal_batch_with_limit, steal_batch_with_limit_and_pop}` methods. (#903)
|
||||
|
||||
# Version 0.8.2
|
||||
|
||||
- Bump the minimum supported Rust version to 1.38. (#877)
|
||||
|
||||
# Version 0.8.1
|
||||
|
||||
- Fix deque steal race condition. (#726)
|
||||
- Add `Stealer::len` method. (#708)
|
||||
|
||||
# Version 0.8.0
|
||||
|
||||
**Note:** This release has been yanked. See [GHSA-pqqp-xmhj-wgcw](https://github.com/crossbeam-rs/crossbeam/security/advisories/GHSA-pqqp-xmhj-wgcw) for details.
|
||||
|
||||
- Bump the minimum supported Rust version to 1.36.
|
||||
- Add `Worker::len()` and `Injector::len()` methods.
|
||||
- Add `std` (enabled by default) feature for forward compatibility.
|
||||
|
||||
# Version 0.7.4
|
||||
|
||||
- Fix deque steal race condition.
|
||||
|
||||
# Version 0.7.3
|
||||
|
||||
**Note:** This release has been yanked. See [GHSA-pqqp-xmhj-wgcw](https://github.com/crossbeam-rs/crossbeam/security/advisories/GHSA-pqqp-xmhj-wgcw) for details.
|
||||
|
||||
- Stop stealing from the same deque. (#448)
|
||||
- Fix unsoundness issues by adopting `MaybeUninit`. (#458)
|
||||
|
||||
# Version 0.7.2
|
||||
|
||||
**Note:** This release has been yanked. See [GHSA-pqqp-xmhj-wgcw](https://github.com/crossbeam-rs/crossbeam/security/advisories/GHSA-pqqp-xmhj-wgcw) for details.
|
||||
|
||||
- Bump `crossbeam-epoch` to `0.8`.
|
||||
- Bump `crossbeam-utils` to `0.7`.
|
||||
|
||||
# Version 0.7.1
|
||||
|
||||
**Note:** This release has been yanked. See [GHSA-pqqp-xmhj-wgcw](https://github.com/crossbeam-rs/crossbeam/security/advisories/GHSA-pqqp-xmhj-wgcw) for details.
|
||||
|
||||
- Bump the minimum required version of `crossbeam-utils`.
|
||||
|
||||
# Version 0.7.0
|
||||
|
||||
**Note:** This release has been yanked. See [GHSA-pqqp-xmhj-wgcw](https://github.com/crossbeam-rs/crossbeam/security/advisories/GHSA-pqqp-xmhj-wgcw) for details.
|
||||
|
||||
- Make `Worker::pop()` faster in the FIFO case.
|
||||
- Replace `fifo()` nad `lifo()` with `Worker::new_fifo()` and `Worker::new_lifo()`.
|
||||
- Add more batched steal methods.
|
||||
- Introduce `Injector<T>`, a MPMC queue.
|
||||
- Rename `Steal::Data` to `Steal::Success`.
|
||||
- Add `Steal::or_else()` and implement `FromIterator` for `Steal`.
|
||||
- Add `#[must_use]` to `Steal`.
|
||||
|
||||
# Version 0.6.3
|
||||
|
||||
- Bump `crossbeam-epoch` to `0.7`.
|
||||
|
||||
# Version 0.6.2
|
||||
|
||||
- Update `crosbeam-utils` to `0.6`.
|
||||
|
||||
# Version 0.6.1
|
||||
|
||||
- Change a few `Relaxed` orderings to `Release` in order to fix false positives by tsan.
|
||||
|
||||
# Version 0.6.0
|
||||
|
||||
- Add `Stealer::steal_many` for batched stealing.
|
||||
- Change the return type of `pop` to `Pop<T>` so that spinning can be handled manually.
|
||||
|
||||
# Version 0.5.2
|
||||
|
||||
- Update `crossbeam-utils` to `0.5.0`.
|
||||
|
||||
# Version 0.5.1
|
||||
|
||||
- Minor optimizations.
|
||||
|
||||
# Version 0.5.0
|
||||
|
||||
- Add two deque constructors : `fifo()` and `lifo()`.
|
||||
- Update `rand` to `0.5.3`.
|
||||
- Rename `Deque` to `Worker`.
|
||||
- Return `Option<T>` from `Stealer::steal`.
|
||||
- Remove methods `Deque::len` and `Stealer::len`.
|
||||
- Remove method `Deque::stealer`.
|
||||
- Remove method `Deque::steal`.
|
||||
|
||||
# Version 0.4.1
|
||||
|
||||
- Update `crossbeam-epoch` to `0.5.0`.
|
||||
|
||||
# Version 0.4.0
|
||||
|
||||
- Update `crossbeam-epoch` to `0.4.2`.
|
||||
- Update `crossbeam-utils` to `0.4.0`.
|
||||
- Require minimum Rust version 1.25.
|
||||
|
||||
# Version 0.3.1
|
||||
|
||||
- Add `Deque::capacity`.
|
||||
- Add `Deque::min_capacity`.
|
||||
- Add `Deque::shrink_to_fit`.
|
||||
- Update `crossbeam-epoch` to `0.3.0`.
|
||||
- Support Rust 1.20.
|
||||
- Shrink the buffer in `Deque::push` if necessary.
|
||||
|
||||
# Version 0.3.0
|
||||
|
||||
- Update `crossbeam-epoch` to `0.4.0`.
|
||||
- Drop support for Rust 1.13.
|
||||
|
||||
# Version 0.2.0
|
||||
|
||||
- Update `crossbeam-epoch` to `0.3.0`.
|
||||
- Support Rust 1.13.
|
||||
|
||||
# Version 0.1.1
|
||||
|
||||
- Update `crossbeam-epoch` to `0.2.0`.
|
||||
|
||||
# Version 0.1.0
|
||||
|
||||
- First implementation of the Chase-Lev deque.
|
55
vendor/crossbeam-deque/Cargo.toml
vendored
Normal file
55
vendor/crossbeam-deque/Cargo.toml
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
rust-version = "1.61"
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.4"
|
||||
description = "Concurrent work-stealing deque"
|
||||
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-deque"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"chase-lev",
|
||||
"lock-free",
|
||||
"scheduler",
|
||||
"scheduling",
|
||||
]
|
||||
categories = [
|
||||
"algorithms",
|
||||
"concurrency",
|
||||
"data-structures",
|
||||
]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/crossbeam-rs/crossbeam"
|
||||
|
||||
[dependencies.cfg-if]
|
||||
version = "1"
|
||||
|
||||
[dependencies.crossbeam-epoch]
|
||||
version = "0.9.16"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.crossbeam-utils]
|
||||
version = "0.8.17"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.rand]
|
||||
version = "0.8"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"crossbeam-epoch/std",
|
||||
"crossbeam-utils/std",
|
||||
]
|
201
vendor/crossbeam-deque/LICENSE-APACHE
vendored
Normal file
201
vendor/crossbeam-deque/LICENSE-APACHE
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
27
vendor/crossbeam-deque/LICENSE-MIT
vendored
Normal file
27
vendor/crossbeam-deque/LICENSE-MIT
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 The Crossbeam Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
46
vendor/crossbeam-deque/README.md
vendored
Normal file
46
vendor/crossbeam-deque/README.md
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
# Crossbeam Deque
|
||||
|
||||
[](
|
||||
https://github.com/crossbeam-rs/crossbeam/actions)
|
||||
[](
|
||||
https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-deque#license)
|
||||
[](
|
||||
https://crates.io/crates/crossbeam-deque)
|
||||
[](
|
||||
https://docs.rs/crossbeam-deque)
|
||||
[](
|
||||
https://www.rust-lang.org)
|
||||
[](https://discord.com/invite/JXYwgWZ)
|
||||
|
||||
This crate provides work-stealing deques, which are primarily intended for
|
||||
building task schedulers.
|
||||
|
||||
## Usage
|
||||
|
||||
Add this to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
crossbeam-deque = "0.8"
|
||||
```
|
||||
|
||||
## Compatibility
|
||||
|
||||
Crossbeam Deque 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.61.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
#### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
|
||||
dual licensed as above, without any additional terms or conditions.
|
2195
vendor/crossbeam-deque/src/deque.rs
vendored
Normal file
2195
vendor/crossbeam-deque/src/deque.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
110
vendor/crossbeam-deque/src/lib.rs
vendored
Normal file
110
vendor/crossbeam-deque/src/lib.rs
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
//! Concurrent work-stealing deques.
|
||||
//!
|
||||
//! These data structures are most commonly used in work-stealing schedulers. The typical setup
|
||||
//! involves a number of threads, each having its own FIFO or LIFO queue (*worker*). There is also
|
||||
//! one global FIFO queue (*injector*) and a list of references to *worker* queues that are able to
|
||||
//! steal tasks (*stealers*).
|
||||
//!
|
||||
//! We spawn a new task onto the scheduler by pushing it into the *injector* queue. Each worker
|
||||
//! thread waits in a loop until it finds the next task to run and then runs it. To find a task, it
|
||||
//! first looks into its local *worker* queue, and then into the *injector* and *stealers*.
|
||||
//!
|
||||
//! # Queues
|
||||
//!
|
||||
//! [`Injector`] is a FIFO queue, where tasks are pushed and stolen from opposite ends. It is
|
||||
//! shared among threads and is usually the entry point for new tasks.
|
||||
//!
|
||||
//! [`Worker`] has two constructors:
|
||||
//!
|
||||
//! * [`new_fifo()`] - Creates a FIFO queue, in which tasks are pushed and popped from opposite
|
||||
//! ends.
|
||||
//! * [`new_lifo()`] - Creates a LIFO queue, in which tasks are pushed and popped from the same
|
||||
//! end.
|
||||
//!
|
||||
//! Each [`Worker`] is owned by a single thread and supports only push and pop operations.
|
||||
//!
|
||||
//! Method [`stealer()`] creates a [`Stealer`] that may be shared among threads and can only steal
|
||||
//! tasks from its [`Worker`]. Tasks are stolen from the end opposite to where they get pushed.
|
||||
//!
|
||||
//! # Stealing
|
||||
//!
|
||||
//! Steal operations come in three flavors:
|
||||
//!
|
||||
//! 1. [`steal()`] - Steals one task.
|
||||
//! 2. [`steal_batch()`] - Steals a batch of tasks and moves them into another worker.
|
||||
//! 3. [`steal_batch_and_pop()`] - Steals a batch of tasks, moves them into another queue, and pops
|
||||
//! one task from that worker.
|
||||
//!
|
||||
//! In contrast to push and pop operations, stealing can spuriously fail with [`Steal::Retry`], in
|
||||
//! which case the steal operation needs to be retried.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! Suppose a thread in a work-stealing scheduler is idle and looking for the next task to run. To
|
||||
//! find an available task, it might do the following:
|
||||
//!
|
||||
//! 1. Try popping one task from the local worker queue.
|
||||
//! 2. Try stealing a batch of tasks from the global injector queue.
|
||||
//! 3. Try stealing one task from another thread using the stealer list.
|
||||
//!
|
||||
//! An implementation of this work-stealing strategy:
|
||||
//!
|
||||
//! ```
|
||||
//! use crossbeam_deque::{Injector, Stealer, Worker};
|
||||
//! use std::iter;
|
||||
//!
|
||||
//! fn find_task<T>(
|
||||
//! local: &Worker<T>,
|
||||
//! global: &Injector<T>,
|
||||
//! stealers: &[Stealer<T>],
|
||||
//! ) -> Option<T> {
|
||||
//! // Pop a task from the local queue, if not empty.
|
||||
//! local.pop().or_else(|| {
|
||||
//! // Otherwise, we need to look for a task elsewhere.
|
||||
//! iter::repeat_with(|| {
|
||||
//! // Try stealing a batch of tasks from the global queue.
|
||||
//! global.steal_batch_and_pop(local)
|
||||
//! // Or try stealing a task from one of the other threads.
|
||||
//! .or_else(|| stealers.iter().map(|s| s.steal()).collect())
|
||||
//! })
|
||||
//! // Loop while no task was stolen and any steal operation needs to be retried.
|
||||
//! .find(|s| !s.is_retry())
|
||||
//! // Extract the stolen task, if there is one.
|
||||
//! .and_then(|s| s.success())
|
||||
//! })
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! [`new_fifo()`]: Worker::new_fifo
|
||||
//! [`new_lifo()`]: Worker::new_lifo
|
||||
//! [`stealer()`]: Worker::stealer
|
||||
//! [`steal()`]: Stealer::steal
|
||||
//! [`steal_batch()`]: Stealer::steal_batch
|
||||
//! [`steal_batch_and_pop()`]: Stealer::steal_batch_and_pop
|
||||
|
||||
#![doc(test(
|
||||
no_crate_inject,
|
||||
attr(
|
||||
deny(warnings, rust_2018_idioms),
|
||||
allow(dead_code, unused_assignments, unused_variables)
|
||||
)
|
||||
))]
|
||||
#![warn(
|
||||
missing_docs,
|
||||
missing_debug_implementations,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "std")] {
|
||||
use crossbeam_epoch as epoch;
|
||||
use crossbeam_utils as utils;
|
||||
|
||||
mod deque;
|
||||
pub use crate::deque::{Injector, Steal, Stealer, Worker};
|
||||
}
|
||||
}
|
357
vendor/crossbeam-deque/tests/fifo.rs
vendored
Normal file
357
vendor/crossbeam-deque/tests/fifo.rs
vendored
Normal file
@ -0,0 +1,357 @@
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crossbeam_deque::Steal::{Empty, Success};
|
||||
use crossbeam_deque::Worker;
|
||||
use crossbeam_utils::thread::scope;
|
||||
use rand::Rng;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
let w = Worker::new_fifo();
|
||||
let s = w.stealer();
|
||||
assert_eq!(w.pop(), None);
|
||||
assert_eq!(s.steal(), Empty);
|
||||
|
||||
w.push(1);
|
||||
assert_eq!(w.pop(), Some(1));
|
||||
assert_eq!(w.pop(), None);
|
||||
assert_eq!(s.steal(), Empty);
|
||||
|
||||
w.push(2);
|
||||
assert_eq!(s.steal(), Success(2));
|
||||
assert_eq!(s.steal(), Empty);
|
||||
assert_eq!(w.pop(), None);
|
||||
|
||||
w.push(3);
|
||||
w.push(4);
|
||||
w.push(5);
|
||||
assert_eq!(s.steal(), Success(3));
|
||||
assert_eq!(s.steal(), Success(4));
|
||||
assert_eq!(s.steal(), Success(5));
|
||||
assert_eq!(s.steal(), Empty);
|
||||
|
||||
w.push(6);
|
||||
w.push(7);
|
||||
w.push(8);
|
||||
w.push(9);
|
||||
assert_eq!(w.pop(), Some(6));
|
||||
assert_eq!(s.steal(), Success(7));
|
||||
assert_eq!(w.pop(), Some(8));
|
||||
assert_eq!(w.pop(), Some(9));
|
||||
assert_eq!(w.pop(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_empty() {
|
||||
let w = Worker::new_fifo();
|
||||
let s = w.stealer();
|
||||
|
||||
assert!(w.is_empty());
|
||||
w.push(1);
|
||||
assert!(!w.is_empty());
|
||||
w.push(2);
|
||||
assert!(!w.is_empty());
|
||||
let _ = w.pop();
|
||||
assert!(!w.is_empty());
|
||||
let _ = w.pop();
|
||||
assert!(w.is_empty());
|
||||
|
||||
assert!(s.is_empty());
|
||||
w.push(1);
|
||||
assert!(!s.is_empty());
|
||||
w.push(2);
|
||||
assert!(!s.is_empty());
|
||||
let _ = s.steal();
|
||||
assert!(!s.is_empty());
|
||||
let _ = s.steal();
|
||||
assert!(s.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spsc() {
|
||||
#[cfg(miri)]
|
||||
const STEPS: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const STEPS: usize = 50_000;
|
||||
|
||||
let w = Worker::new_fifo();
|
||||
let s = w.stealer();
|
||||
|
||||
scope(|scope| {
|
||||
scope.spawn(|_| {
|
||||
for i in 0..STEPS {
|
||||
loop {
|
||||
if let Success(v) = s.steal() {
|
||||
assert_eq!(i, v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(s.steal(), Empty);
|
||||
});
|
||||
|
||||
for i in 0..STEPS {
|
||||
w.push(i);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stampede() {
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let w = Worker::new_fifo();
|
||||
|
||||
for i in 0..COUNT {
|
||||
w.push(Box::new(i + 1));
|
||||
}
|
||||
let remaining = Arc::new(AtomicUsize::new(COUNT));
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let s = w.stealer();
|
||||
let remaining = remaining.clone();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let mut last = 0;
|
||||
while remaining.load(SeqCst) > 0 {
|
||||
if let Success(x) = s.steal() {
|
||||
assert!(last < *x);
|
||||
last = *x;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut last = 0;
|
||||
while remaining.load(SeqCst) > 0 {
|
||||
if let Some(x) = w.pop() {
|
||||
assert!(last < *x);
|
||||
last = *x;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stress() {
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let w = Worker::new_fifo();
|
||||
let done = Arc::new(AtomicBool::new(false));
|
||||
let hits = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let s = w.stealer();
|
||||
let done = done.clone();
|
||||
let hits = hits.clone();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
while !done.load(SeqCst) {
|
||||
if let Success(_) = s.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = s.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = s.steal_batch_and_pop(&w2) {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut expected = 0;
|
||||
while expected < COUNT {
|
||||
if rng.gen_range(0..3) == 0 {
|
||||
while w.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
} else {
|
||||
w.push(expected);
|
||||
expected += 1;
|
||||
}
|
||||
}
|
||||
|
||||
while hits.load(SeqCst) < COUNT {
|
||||
while w.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
done.store(true, SeqCst);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg_attr(miri, ignore)] // Miri is too slow
|
||||
#[test]
|
||||
fn no_starvation() {
|
||||
const THREADS: usize = 8;
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let w = Worker::new_fifo();
|
||||
let done = Arc::new(AtomicBool::new(false));
|
||||
let mut all_hits = Vec::new();
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let s = w.stealer();
|
||||
let done = done.clone();
|
||||
let hits = Arc::new(AtomicUsize::new(0));
|
||||
all_hits.push(hits.clone());
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
while !done.load(SeqCst) {
|
||||
if let Success(_) = s.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = s.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = s.steal_batch_and_pop(&w2) {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut my_hits = 0;
|
||||
loop {
|
||||
for i in 0..rng.gen_range(0..COUNT) {
|
||||
if rng.gen_range(0..3) == 0 && my_hits == 0 {
|
||||
while w.pop().is_some() {
|
||||
my_hits += 1;
|
||||
}
|
||||
} else {
|
||||
w.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if my_hits > 0 && all_hits.iter().all(|h| h.load(SeqCst) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
done.store(true, SeqCst);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destructors() {
|
||||
#[cfg(miri)]
|
||||
const THREADS: usize = 2;
|
||||
#[cfg(not(miri))]
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
#[cfg(miri)]
|
||||
const STEPS: usize = 100;
|
||||
#[cfg(not(miri))]
|
||||
const STEPS: usize = 1000;
|
||||
|
||||
struct Elem(usize, Arc<Mutex<Vec<usize>>>);
|
||||
|
||||
impl Drop for Elem {
|
||||
fn drop(&mut self) {
|
||||
self.1.lock().unwrap().push(self.0);
|
||||
}
|
||||
}
|
||||
|
||||
let w = Worker::new_fifo();
|
||||
let dropped = Arc::new(Mutex::new(Vec::new()));
|
||||
let remaining = Arc::new(AtomicUsize::new(COUNT));
|
||||
|
||||
for i in 0..COUNT {
|
||||
w.push(Elem(i, dropped.clone()));
|
||||
}
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let remaining = remaining.clone();
|
||||
let s = w.stealer();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_fifo();
|
||||
let mut cnt = 0;
|
||||
|
||||
while cnt < STEPS {
|
||||
if let Success(_) = s.steal() {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = s.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = s.steal_batch_and_pop(&w2) {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for _ in 0..STEPS {
|
||||
if w.pop().is_some() {
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let rem = remaining.load(SeqCst);
|
||||
assert!(rem > 0);
|
||||
|
||||
{
|
||||
let mut v = dropped.lock().unwrap();
|
||||
assert_eq!(v.len(), COUNT - rem);
|
||||
v.clear();
|
||||
}
|
||||
|
||||
drop(w);
|
||||
|
||||
{
|
||||
let mut v = dropped.lock().unwrap();
|
||||
assert_eq!(v.len(), rem);
|
||||
v.sort_unstable();
|
||||
for pair in v.windows(2) {
|
||||
assert_eq!(pair[0] + 1, pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
375
vendor/crossbeam-deque/tests/injector.rs
vendored
Normal file
375
vendor/crossbeam-deque/tests/injector.rs
vendored
Normal file
@ -0,0 +1,375 @@
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crossbeam_deque::Steal::{Empty, Success};
|
||||
use crossbeam_deque::{Injector, Worker};
|
||||
use crossbeam_utils::thread::scope;
|
||||
use rand::Rng;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
let q = Injector::new();
|
||||
assert_eq!(q.steal(), Empty);
|
||||
|
||||
q.push(1);
|
||||
q.push(2);
|
||||
assert_eq!(q.steal(), Success(1));
|
||||
assert_eq!(q.steal(), Success(2));
|
||||
assert_eq!(q.steal(), Empty);
|
||||
|
||||
q.push(3);
|
||||
assert_eq!(q.steal(), Success(3));
|
||||
assert_eq!(q.steal(), Empty);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_empty() {
|
||||
let q = Injector::new();
|
||||
assert!(q.is_empty());
|
||||
|
||||
q.push(1);
|
||||
assert!(!q.is_empty());
|
||||
q.push(2);
|
||||
assert!(!q.is_empty());
|
||||
|
||||
let _ = q.steal();
|
||||
assert!(!q.is_empty());
|
||||
let _ = q.steal();
|
||||
assert!(q.is_empty());
|
||||
|
||||
q.push(3);
|
||||
assert!(!q.is_empty());
|
||||
let _ = q.steal();
|
||||
assert!(q.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spsc() {
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 100_000;
|
||||
|
||||
let q = Injector::new();
|
||||
|
||||
scope(|scope| {
|
||||
scope.spawn(|_| {
|
||||
for i in 0..COUNT {
|
||||
loop {
|
||||
if let Success(v) = q.steal() {
|
||||
assert_eq!(i, v);
|
||||
break;
|
||||
}
|
||||
#[cfg(miri)]
|
||||
std::hint::spin_loop();
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(q.steal(), Empty);
|
||||
});
|
||||
|
||||
for i in 0..COUNT {
|
||||
q.push(i);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mpmc() {
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 25_000;
|
||||
const THREADS: usize = 4;
|
||||
|
||||
let q = Injector::new();
|
||||
let v = (0..COUNT).map(|_| AtomicUsize::new(0)).collect::<Vec<_>>();
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
scope.spawn(|_| {
|
||||
for i in 0..COUNT {
|
||||
q.push(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for _ in 0..THREADS {
|
||||
scope.spawn(|_| {
|
||||
for _ in 0..COUNT {
|
||||
loop {
|
||||
if let Success(n) = q.steal() {
|
||||
v[n].fetch_add(1, SeqCst);
|
||||
break;
|
||||
}
|
||||
#[cfg(miri)]
|
||||
std::hint::spin_loop();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
for c in v {
|
||||
assert_eq!(c.load(SeqCst), THREADS);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stampede() {
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let q = Injector::new();
|
||||
|
||||
for i in 0..COUNT {
|
||||
q.push(Box::new(i + 1));
|
||||
}
|
||||
let remaining = Arc::new(AtomicUsize::new(COUNT));
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let remaining = remaining.clone();
|
||||
let q = &q;
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let mut last = 0;
|
||||
while remaining.load(SeqCst) > 0 {
|
||||
if let Success(x) = q.steal() {
|
||||
assert!(last < *x);
|
||||
last = *x;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut last = 0;
|
||||
while remaining.load(SeqCst) > 0 {
|
||||
if let Success(x) = q.steal() {
|
||||
assert!(last < *x);
|
||||
last = *x;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stress() {
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let q = Injector::new();
|
||||
let done = Arc::new(AtomicBool::new(false));
|
||||
let hits = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let done = done.clone();
|
||||
let hits = hits.clone();
|
||||
let q = &q;
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
while !done.load(SeqCst) {
|
||||
if let Success(_) = q.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = q.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = q.steal_batch_and_pop(&w2) {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut expected = 0;
|
||||
while expected < COUNT {
|
||||
if rng.gen_range(0..3) == 0 {
|
||||
while let Success(_) = q.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
} else {
|
||||
q.push(expected);
|
||||
expected += 1;
|
||||
}
|
||||
}
|
||||
|
||||
while hits.load(SeqCst) < COUNT {
|
||||
while let Success(_) = q.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
done.store(true, SeqCst);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg_attr(miri, ignore)] // Miri is too slow
|
||||
#[test]
|
||||
fn no_starvation() {
|
||||
const THREADS: usize = 8;
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let q = Injector::new();
|
||||
let done = Arc::new(AtomicBool::new(false));
|
||||
let mut all_hits = Vec::new();
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let done = done.clone();
|
||||
let hits = Arc::new(AtomicUsize::new(0));
|
||||
all_hits.push(hits.clone());
|
||||
let q = &q;
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
while !done.load(SeqCst) {
|
||||
if let Success(_) = q.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = q.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = q.steal_batch_and_pop(&w2) {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut my_hits = 0;
|
||||
loop {
|
||||
for i in 0..rng.gen_range(0..COUNT) {
|
||||
if rng.gen_range(0..3) == 0 && my_hits == 0 {
|
||||
while let Success(_) = q.steal() {
|
||||
my_hits += 1;
|
||||
}
|
||||
} else {
|
||||
q.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if my_hits > 0 && all_hits.iter().all(|h| h.load(SeqCst) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
done.store(true, SeqCst);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destructors() {
|
||||
#[cfg(miri)]
|
||||
const THREADS: usize = 2;
|
||||
#[cfg(not(miri))]
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
#[cfg(miri)]
|
||||
const STEPS: usize = 100;
|
||||
#[cfg(not(miri))]
|
||||
const STEPS: usize = 1000;
|
||||
|
||||
struct Elem(usize, Arc<Mutex<Vec<usize>>>);
|
||||
|
||||
impl Drop for Elem {
|
||||
fn drop(&mut self) {
|
||||
self.1.lock().unwrap().push(self.0);
|
||||
}
|
||||
}
|
||||
|
||||
let q = Injector::new();
|
||||
let dropped = Arc::new(Mutex::new(Vec::new()));
|
||||
let remaining = Arc::new(AtomicUsize::new(COUNT));
|
||||
|
||||
for i in 0..COUNT {
|
||||
q.push(Elem(i, dropped.clone()));
|
||||
}
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let remaining = remaining.clone();
|
||||
let q = &q;
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_fifo();
|
||||
let mut cnt = 0;
|
||||
|
||||
while cnt < STEPS {
|
||||
if let Success(_) = q.steal() {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = q.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = q.steal_batch_and_pop(&w2) {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for _ in 0..STEPS {
|
||||
if let Success(_) = q.steal() {
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let rem = remaining.load(SeqCst);
|
||||
assert!(rem > 0);
|
||||
|
||||
{
|
||||
let mut v = dropped.lock().unwrap();
|
||||
assert_eq!(v.len(), COUNT - rem);
|
||||
v.clear();
|
||||
}
|
||||
|
||||
drop(q);
|
||||
|
||||
{
|
||||
let mut v = dropped.lock().unwrap();
|
||||
assert_eq!(v.len(), rem);
|
||||
v.sort_unstable();
|
||||
for pair in v.windows(2) {
|
||||
assert_eq!(pair[0] + 1, pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
359
vendor/crossbeam-deque/tests/lifo.rs
vendored
Normal file
359
vendor/crossbeam-deque/tests/lifo.rs
vendored
Normal file
@ -0,0 +1,359 @@
|
||||
use std::sync::atomic::Ordering::SeqCst;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crossbeam_deque::Steal::{Empty, Success};
|
||||
use crossbeam_deque::Worker;
|
||||
use crossbeam_utils::thread::scope;
|
||||
use rand::Rng;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
let w = Worker::new_lifo();
|
||||
let s = w.stealer();
|
||||
assert_eq!(w.pop(), None);
|
||||
assert_eq!(s.steal(), Empty);
|
||||
|
||||
w.push(1);
|
||||
assert_eq!(w.pop(), Some(1));
|
||||
assert_eq!(w.pop(), None);
|
||||
assert_eq!(s.steal(), Empty);
|
||||
|
||||
w.push(2);
|
||||
assert_eq!(s.steal(), Success(2));
|
||||
assert_eq!(s.steal(), Empty);
|
||||
assert_eq!(w.pop(), None);
|
||||
|
||||
w.push(3);
|
||||
w.push(4);
|
||||
w.push(5);
|
||||
assert_eq!(s.steal(), Success(3));
|
||||
assert_eq!(s.steal(), Success(4));
|
||||
assert_eq!(s.steal(), Success(5));
|
||||
assert_eq!(s.steal(), Empty);
|
||||
|
||||
w.push(6);
|
||||
w.push(7);
|
||||
w.push(8);
|
||||
w.push(9);
|
||||
assert_eq!(w.pop(), Some(9));
|
||||
assert_eq!(s.steal(), Success(6));
|
||||
assert_eq!(w.pop(), Some(8));
|
||||
assert_eq!(w.pop(), Some(7));
|
||||
assert_eq!(w.pop(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_empty() {
|
||||
let w = Worker::new_lifo();
|
||||
let s = w.stealer();
|
||||
|
||||
assert!(w.is_empty());
|
||||
w.push(1);
|
||||
assert!(!w.is_empty());
|
||||
w.push(2);
|
||||
assert!(!w.is_empty());
|
||||
let _ = w.pop();
|
||||
assert!(!w.is_empty());
|
||||
let _ = w.pop();
|
||||
assert!(w.is_empty());
|
||||
|
||||
assert!(s.is_empty());
|
||||
w.push(1);
|
||||
assert!(!s.is_empty());
|
||||
w.push(2);
|
||||
assert!(!s.is_empty());
|
||||
let _ = s.steal();
|
||||
assert!(!s.is_empty());
|
||||
let _ = s.steal();
|
||||
assert!(s.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spsc() {
|
||||
#[cfg(miri)]
|
||||
const STEPS: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const STEPS: usize = 50_000;
|
||||
|
||||
let w = Worker::new_lifo();
|
||||
let s = w.stealer();
|
||||
|
||||
scope(|scope| {
|
||||
scope.spawn(|_| {
|
||||
for i in 0..STEPS {
|
||||
loop {
|
||||
if let Success(v) = s.steal() {
|
||||
assert_eq!(i, v);
|
||||
break;
|
||||
}
|
||||
#[cfg(miri)]
|
||||
std::hint::spin_loop();
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(s.steal(), Empty);
|
||||
});
|
||||
|
||||
for i in 0..STEPS {
|
||||
w.push(i);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stampede() {
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let w = Worker::new_lifo();
|
||||
|
||||
for i in 0..COUNT {
|
||||
w.push(Box::new(i + 1));
|
||||
}
|
||||
let remaining = Arc::new(AtomicUsize::new(COUNT));
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let s = w.stealer();
|
||||
let remaining = remaining.clone();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let mut last = 0;
|
||||
while remaining.load(SeqCst) > 0 {
|
||||
if let Success(x) = s.steal() {
|
||||
assert!(last < *x);
|
||||
last = *x;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut last = COUNT + 1;
|
||||
while remaining.load(SeqCst) > 0 {
|
||||
if let Some(x) = w.pop() {
|
||||
assert!(last > *x);
|
||||
last = *x;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stress() {
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let w = Worker::new_lifo();
|
||||
let done = Arc::new(AtomicBool::new(false));
|
||||
let hits = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let s = w.stealer();
|
||||
let done = done.clone();
|
||||
let hits = hits.clone();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_lifo();
|
||||
|
||||
while !done.load(SeqCst) {
|
||||
if let Success(_) = s.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = s.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = s.steal_batch_and_pop(&w2) {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut expected = 0;
|
||||
while expected < COUNT {
|
||||
if rng.gen_range(0..3) == 0 {
|
||||
while w.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
} else {
|
||||
w.push(expected);
|
||||
expected += 1;
|
||||
}
|
||||
}
|
||||
|
||||
while hits.load(SeqCst) < COUNT {
|
||||
while w.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
done.store(true, SeqCst);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg_attr(miri, ignore)] // Miri is too slow
|
||||
#[test]
|
||||
fn no_starvation() {
|
||||
const THREADS: usize = 8;
|
||||
const COUNT: usize = 50_000;
|
||||
|
||||
let w = Worker::new_lifo();
|
||||
let done = Arc::new(AtomicBool::new(false));
|
||||
let mut all_hits = Vec::new();
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let s = w.stealer();
|
||||
let done = done.clone();
|
||||
let hits = Arc::new(AtomicUsize::new(0));
|
||||
all_hits.push(hits.clone());
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_lifo();
|
||||
|
||||
while !done.load(SeqCst) {
|
||||
if let Success(_) = s.steal() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = s.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = s.steal_batch_and_pop(&w2) {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
hits.fetch_add(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut my_hits = 0;
|
||||
loop {
|
||||
for i in 0..rng.gen_range(0..COUNT) {
|
||||
if rng.gen_range(0..3) == 0 && my_hits == 0 {
|
||||
while w.pop().is_some() {
|
||||
my_hits += 1;
|
||||
}
|
||||
} else {
|
||||
w.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if my_hits > 0 && all_hits.iter().all(|h| h.load(SeqCst) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
done.store(true, SeqCst);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn destructors() {
|
||||
#[cfg(miri)]
|
||||
const THREADS: usize = 2;
|
||||
#[cfg(not(miri))]
|
||||
const THREADS: usize = 8;
|
||||
#[cfg(miri)]
|
||||
const COUNT: usize = 500;
|
||||
#[cfg(not(miri))]
|
||||
const COUNT: usize = 50_000;
|
||||
#[cfg(miri)]
|
||||
const STEPS: usize = 100;
|
||||
#[cfg(not(miri))]
|
||||
const STEPS: usize = 1000;
|
||||
|
||||
struct Elem(usize, Arc<Mutex<Vec<usize>>>);
|
||||
|
||||
impl Drop for Elem {
|
||||
fn drop(&mut self) {
|
||||
self.1.lock().unwrap().push(self.0);
|
||||
}
|
||||
}
|
||||
|
||||
let w = Worker::new_lifo();
|
||||
let dropped = Arc::new(Mutex::new(Vec::new()));
|
||||
let remaining = Arc::new(AtomicUsize::new(COUNT));
|
||||
|
||||
for i in 0..COUNT {
|
||||
w.push(Elem(i, dropped.clone()));
|
||||
}
|
||||
|
||||
scope(|scope| {
|
||||
for _ in 0..THREADS {
|
||||
let remaining = remaining.clone();
|
||||
let s = w.stealer();
|
||||
|
||||
scope.spawn(move |_| {
|
||||
let w2 = Worker::new_lifo();
|
||||
let mut cnt = 0;
|
||||
|
||||
while cnt < STEPS {
|
||||
if let Success(_) = s.steal() {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
|
||||
let _ = s.steal_batch(&w2);
|
||||
|
||||
if let Success(_) = s.steal_batch_and_pop(&w2) {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
|
||||
while w2.pop().is_some() {
|
||||
cnt += 1;
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for _ in 0..STEPS {
|
||||
if w.pop().is_some() {
|
||||
remaining.fetch_sub(1, SeqCst);
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let rem = remaining.load(SeqCst);
|
||||
assert!(rem > 0);
|
||||
|
||||
{
|
||||
let mut v = dropped.lock().unwrap();
|
||||
assert_eq!(v.len(), COUNT - rem);
|
||||
v.clear();
|
||||
}
|
||||
|
||||
drop(w);
|
||||
|
||||
{
|
||||
let mut v = dropped.lock().unwrap();
|
||||
assert_eq!(v.len(), rem);
|
||||
v.sort_unstable();
|
||||
for pair in v.windows(2) {
|
||||
assert_eq!(pair[0] + 1, pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
212
vendor/crossbeam-deque/tests/steal.rs
vendored
Normal file
212
vendor/crossbeam-deque/tests/steal.rs
vendored
Normal file
@ -0,0 +1,212 @@
|
||||
use crossbeam_deque::Steal::Success;
|
||||
use crossbeam_deque::{Injector, Worker};
|
||||
|
||||
#[test]
|
||||
fn steal_fifo() {
|
||||
let w = Worker::new_fifo();
|
||||
for i in 1..=3 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
assert_eq!(s.steal(), Success(1));
|
||||
assert_eq!(s.steal(), Success(2));
|
||||
assert_eq!(s.steal(), Success(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_lifo() {
|
||||
let w = Worker::new_lifo();
|
||||
for i in 1..=3 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
assert_eq!(s.steal(), Success(1));
|
||||
assert_eq!(s.steal(), Success(2));
|
||||
assert_eq!(s.steal(), Success(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_injector() {
|
||||
let q = Injector::new();
|
||||
for i in 1..=3 {
|
||||
q.push(i);
|
||||
}
|
||||
|
||||
assert_eq!(q.steal(), Success(1));
|
||||
assert_eq!(q.steal(), Success(2));
|
||||
assert_eq!(q.steal(), Success(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_fifo_fifo() {
|
||||
let w = Worker::new_fifo();
|
||||
for i in 1..=4 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
assert_eq!(s.steal_batch(&w2), Success(()));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_lifo_lifo() {
|
||||
let w = Worker::new_lifo();
|
||||
for i in 1..=4 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_lifo();
|
||||
|
||||
assert_eq!(s.steal_batch(&w2), Success(()));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_fifo_lifo() {
|
||||
let w = Worker::new_fifo();
|
||||
for i in 1..=4 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_lifo();
|
||||
|
||||
assert_eq!(s.steal_batch(&w2), Success(()));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_lifo_fifo() {
|
||||
let w = Worker::new_lifo();
|
||||
for i in 1..=4 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
assert_eq!(s.steal_batch(&w2), Success(()));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_injector_fifo() {
|
||||
let q = Injector::new();
|
||||
for i in 1..=4 {
|
||||
q.push(i);
|
||||
}
|
||||
|
||||
let w2 = Worker::new_fifo();
|
||||
assert_eq!(q.steal_batch(&w2), Success(()));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_injector_lifo() {
|
||||
let q = Injector::new();
|
||||
for i in 1..=4 {
|
||||
q.push(i);
|
||||
}
|
||||
|
||||
let w2 = Worker::new_lifo();
|
||||
assert_eq!(q.steal_batch(&w2), Success(()));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_and_pop_fifo_fifo() {
|
||||
let w = Worker::new_fifo();
|
||||
for i in 1..=6 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
assert_eq!(s.steal_batch_and_pop(&w2), Success(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_and_pop_lifo_lifo() {
|
||||
let w = Worker::new_lifo();
|
||||
for i in 1..=6 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_lifo();
|
||||
|
||||
assert_eq!(s.steal_batch_and_pop(&w2), Success(3));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_and_pop_fifo_lifo() {
|
||||
let w = Worker::new_fifo();
|
||||
for i in 1..=6 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_lifo();
|
||||
|
||||
assert_eq!(s.steal_batch_and_pop(&w2), Success(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_and_pop_lifo_fifo() {
|
||||
let w = Worker::new_lifo();
|
||||
for i in 1..=6 {
|
||||
w.push(i);
|
||||
}
|
||||
|
||||
let s = w.stealer();
|
||||
let w2 = Worker::new_fifo();
|
||||
|
||||
assert_eq!(s.steal_batch_and_pop(&w2), Success(3));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_and_pop_injector_fifo() {
|
||||
let q = Injector::new();
|
||||
for i in 1..=6 {
|
||||
q.push(i);
|
||||
}
|
||||
|
||||
let w2 = Worker::new_fifo();
|
||||
assert_eq!(q.steal_batch_and_pop(&w2), Success(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn steal_batch_and_pop_injector_lifo() {
|
||||
let q = Injector::new();
|
||||
for i in 1..=6 {
|
||||
q.push(i);
|
||||
}
|
||||
|
||||
let w2 = Worker::new_lifo();
|
||||
assert_eq!(q.steal_batch_and_pop(&w2), Success(1));
|
||||
assert_eq!(w2.pop(), Some(2));
|
||||
assert_eq!(w2.pop(), Some(3));
|
||||
}
|
Reference in New Issue
Block a user