Skip to content

Commit 5c81162

Browse files
authored
support OrderedWorkStealQueue (#336)
2 parents 07e692e + 4fa48ea commit 5c81162

File tree

8 files changed

+486
-22
lines changed

8 files changed

+486
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ time = "0.3"
3838
corosensei = "0.2"
3939
core_affinity = "0.8"
4040
crossbeam-utils = "0.8"
41+
crossbeam-skiplist = "0.1"
4142
nix = "0.29"
4243
io-uring = "0.7"
4344
windows-sys = "0.59"

core/Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ license.workspace = true
1111
readme.workspace = true
1212

1313
[dependencies]
14-
cfg-if.workspace = true
15-
once_cell.workspace = true
16-
dashmap.workspace = true
17-
num_cpus.workspace = true
18-
rand.workspace = true
19-
st3.workspace = true
20-
crossbeam-deque.workspace = true
2114
tracing = { workspace = true, default-features = false, optional = true }
2215
tracing-subscriber = { workspace = true, features = [
2316
"fmt",
@@ -32,6 +25,14 @@ uuid = { workspace = true, features = [
3225
educe = { workspace = true, optional = true }
3326
core_affinity = { workspace = true, optional = true }
3427
crossbeam-utils = { workspace = true, optional = true }
28+
cfg-if.workspace = true
29+
once_cell.workspace = true
30+
dashmap.workspace = true
31+
num_cpus.workspace = true
32+
rand.workspace = true
33+
st3.workspace = true
34+
crossbeam-deque.workspace = true
35+
crossbeam-skiplist.workspace = true
3536
psm.workspace = true
3637

3738
[target.'cfg(unix)'.dependencies]

core/src/common/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,48 @@ pub mod timer;
5656
///
5757
pub mod work_steal;
5858

59+
/// Suppose a thread in a work-stealing scheduler is idle and looking for the next task to run. To
60+
/// find an available task, it might do the following:
61+
///
62+
/// 1. Try popping one task from the local worker queue.
63+
/// 2. Try popping and stealing tasks from another local worker queue.
64+
/// 3. Try popping and stealing a batch of tasks from the global injector queue.
65+
///
66+
/// A queue implementation of work-stealing strategy:
67+
///
68+
/// # Examples
69+
///
70+
/// ```
71+
/// use open_coroutine_core::common::ordered_work_steal::OrderedWorkStealQueue;
72+
///
73+
/// let queue = OrderedWorkStealQueue::new(2, 64);
74+
/// for i in 6..8 {
75+
/// queue.push_with_priority(i, i);
76+
/// }
77+
/// let local0 = queue.local_queue();
78+
/// for i in 2..6 {
79+
/// local0.push_with_priority(i, i);
80+
/// }
81+
/// let local1 = queue.local_queue();
82+
/// for i in 0..2 {
83+
/// local1.push_with_priority(i, i);
84+
/// }
85+
/// for i in 0..2 {
86+
/// assert_eq!(local1.pop_front(), Some(i));
87+
/// }
88+
/// for i in (2..6).rev() {
89+
/// assert_eq!(local1.pop_front(), Some(i));
90+
/// }
91+
/// for i in 6..8 {
92+
/// assert_eq!(local1.pop_front(), Some(i));
93+
/// }
94+
/// assert_eq!(local0.pop_front(), None);
95+
/// assert_eq!(local1.pop_front(), None);
96+
/// assert_eq!(queue.pop(), None);
97+
/// ```
98+
///
99+
pub mod ordered_work_steal;
100+
59101
#[cfg(target_os = "linux")]
60102
extern "C" {
61103
fn linux_version_code() -> c_int;

0 commit comments

Comments
 (0)