@@ -13,13 +13,13 @@ use cast::{transmute, transmute_mut_region, transmute_mut_unsafe};
13
13
use clone:: Clone ;
14
14
use unstable:: raw;
15
15
use super :: sleeper_list:: SleeperList ;
16
- use super :: work_queue:: WorkQueue ;
17
16
use super :: stack:: { StackPool } ;
18
17
use super :: rtio:: EventLoop ;
19
18
use super :: context:: Context ;
20
19
use super :: task:: { Task , AnySched , Sched } ;
21
20
use super :: message_queue:: MessageQueue ;
22
21
use rt:: kill:: BlockedTask ;
22
+ use rt:: deque;
23
23
use rt:: local_ptr;
24
24
use rt:: local:: Local ;
25
25
use rt:: rtio:: { RemoteCallback , PausibleIdleCallback , Callback } ;
@@ -39,14 +39,14 @@ use vec::{OwnedVector};
39
39
/// in too much allocation and too many events.
40
40
pub struct Scheduler {
41
41
/// There are N work queues, one per scheduler.
42
- priv work_queue : WorkQueue < ~Task > ,
42
+ work_queue : deque :: Worker < ~Task > ,
43
43
/// Work queues for the other schedulers. These are created by
44
44
/// cloning the core work queues.
45
- work_queues : ~[ WorkQueue < ~Task > ] ,
45
+ work_queues : ~[ deque :: Stealer < ~Task > ] ,
46
46
/// The queue of incoming messages from other schedulers.
47
47
/// These are enqueued by SchedHandles after which a remote callback
48
48
/// is triggered to handle the message.
49
- priv message_queue : MessageQueue < SchedMessage > ,
49
+ message_queue : MessageQueue < SchedMessage > ,
50
50
/// A shared list of sleeping schedulers. We'll use this to wake
51
51
/// up schedulers when pushing work onto the work queue.
52
52
sleeper_list : SleeperList ,
@@ -56,33 +56,33 @@ pub struct Scheduler {
56
56
/// not active since there are multiple event sources that may
57
57
/// wake the scheduler. It just prevents the scheduler from pushing
58
58
/// multiple handles onto the sleeper list.
59
- priv sleepy : bool ,
59
+ sleepy : bool ,
60
60
/// A flag to indicate we've received the shutdown message and should
61
61
/// no longer try to go to sleep, but exit instead.
62
62
no_sleep : bool ,
63
63
stack_pool : StackPool ,
64
64
/// The scheduler runs on a special task. When it is not running
65
65
/// it is stored here instead of the work queue.
66
- priv sched_task : Option < ~Task > ,
66
+ sched_task : Option < ~Task > ,
67
67
/// An action performed after a context switch on behalf of the
68
68
/// code running before the context switch
69
- priv cleanup_job : Option < CleanupJob > ,
69
+ cleanup_job : Option < CleanupJob > ,
70
70
/// Should this scheduler run any task, or only pinned tasks?
71
71
run_anything : bool ,
72
72
/// If the scheduler shouldn't run some tasks, a friend to send
73
73
/// them to.
74
- priv friend_handle : Option < SchedHandle > ,
74
+ friend_handle : Option < SchedHandle > ,
75
75
/// A fast XorShift rng for scheduler use
76
76
rng : XorShiftRng ,
77
77
/// A toggleable idle callback
78
- priv idle_callback : Option < ~PausibleIdleCallback > ,
78
+ idle_callback : Option < ~PausibleIdleCallback > ,
79
79
/// A countdown that starts at a random value and is decremented
80
80
/// every time a yield check is performed. When it hits 0 a task
81
81
/// will yield.
82
- priv yield_check_count : uint ,
82
+ yield_check_count : uint ,
83
83
/// A flag to tell the scheduler loop it needs to do some stealing
84
84
/// in order to introduce randomness as part of a yield
85
- priv steal_for_yield : bool ,
85
+ steal_for_yield : bool ,
86
86
87
87
// n.b. currently destructors of an object are run in top-to-bottom in order
88
88
// of field declaration. Due to its nature, the pausible idle callback
@@ -115,8 +115,8 @@ impl Scheduler {
115
115
// * Initialization Functions
116
116
117
117
pub fn new ( event_loop : ~EventLoop ,
118
- work_queue : WorkQueue < ~Task > ,
119
- work_queues : ~[ WorkQueue < ~Task > ] ,
118
+ work_queue : deque :: Worker < ~Task > ,
119
+ work_queues : ~[ deque :: Stealer < ~Task > ] ,
120
120
sleeper_list : SleeperList )
121
121
-> Scheduler {
122
122
@@ -127,8 +127,8 @@ impl Scheduler {
127
127
}
128
128
129
129
pub fn new_special ( event_loop : ~EventLoop ,
130
- work_queue : WorkQueue < ~Task > ,
131
- work_queues : ~[ WorkQueue < ~Task > ] ,
130
+ work_queue : deque :: Worker < ~Task > ,
131
+ work_queues : ~[ deque :: Stealer < ~Task > ] ,
132
132
sleeper_list : SleeperList ,
133
133
run_anything : bool ,
134
134
friend : Option < SchedHandle > )
@@ -440,11 +440,11 @@ impl Scheduler {
440
440
let start_index = self . rng . gen_range ( 0 , len) ;
441
441
for index in range ( 0 , len) . map ( |i| ( i + start_index) % len) {
442
442
match work_queues[ index] . steal ( ) {
443
- Some ( task) => {
443
+ deque :: Data ( task) => {
444
444
rtdebug ! ( "found task by stealing" ) ;
445
445
return Some ( task)
446
446
}
447
- None => ( )
447
+ _ => ( )
448
448
}
449
449
} ;
450
450
rtdebug ! ( "giving up on stealing" ) ;
@@ -889,6 +889,7 @@ mod test {
889
889
use borrow:: to_uint;
890
890
use rt:: sched:: { Scheduler } ;
891
891
use cell:: Cell ;
892
+ use rt:: deque:: BufferPool ;
892
893
use rt:: thread:: Thread ;
893
894
use rt:: task:: { Task , Sched } ;
894
895
use rt:: basic;
@@ -994,22 +995,22 @@ mod test {
994
995
#[ test]
995
996
fn test_schedule_home_states ( ) {
996
997
use rt:: sleeper_list:: SleeperList ;
997
- use rt:: work_queue:: WorkQueue ;
998
998
use rt:: sched:: Shutdown ;
999
999
use borrow;
1000
1000
use rt:: comm:: * ;
1001
1001
1002
1002
do run_in_bare_thread {
1003
1003
1004
1004
let sleepers = SleeperList :: new ( ) ;
1005
- let normal_queue = WorkQueue :: new ( ) ;
1006
- let special_queue = WorkQueue :: new ( ) ;
1007
- let queues = ~[ normal_queue. clone ( ) , special_queue. clone ( ) ] ;
1005
+ let mut pool = BufferPool :: init ( ) ;
1006
+ let ( normal_worker, normal_stealer) = pool. deque ( ) ;
1007
+ let ( special_worker, special_stealer) = pool. deque ( ) ;
1008
+ let queues = ~[ normal_stealer, special_stealer] ;
1008
1009
1009
1010
// Our normal scheduler
1010
1011
let mut normal_sched = ~Scheduler :: new (
1011
1012
basic:: event_loop ( ) ,
1012
- normal_queue ,
1013
+ normal_worker ,
1013
1014
queues. clone ( ) ,
1014
1015
sleepers. clone ( ) ) ;
1015
1016
@@ -1020,7 +1021,7 @@ mod test {
1020
1021
// Our special scheduler
1021
1022
let mut special_sched = ~Scheduler :: new_special (
1022
1023
basic:: event_loop ( ) ,
1023
- special_queue . clone ( ) ,
1024
+ special_worker ,
1024
1025
queues. clone ( ) ,
1025
1026
sleepers. clone ( ) ,
1026
1027
false ,
@@ -1169,7 +1170,6 @@ mod test {
1169
1170
// Used to deadlock because Shutdown was never recvd.
1170
1171
#[ test]
1171
1172
fn no_missed_messages ( ) {
1172
- use rt:: work_queue:: WorkQueue ;
1173
1173
use rt:: sleeper_list:: SleeperList ;
1174
1174
use rt:: stack:: StackPool ;
1175
1175
use rt:: sched:: { Shutdown , TaskFromFriend } ;
@@ -1178,13 +1178,13 @@ mod test {
1178
1178
do run_in_bare_thread {
1179
1179
stress_factor( ) . times ( || {
1180
1180
let sleepers = SleeperList :: new ( ) ;
1181
- let queue = WorkQueue :: new ( ) ;
1182
- let queues = ~ [ queue . clone ( ) ] ;
1181
+ let mut pool = BufferPool :: init ( ) ;
1182
+ let ( worker , stealer ) = pool . deque ( ) ;
1183
1183
1184
1184
let mut sched = ~Scheduler :: new (
1185
1185
basic:: event_loop ( ) ,
1186
- queue ,
1187
- queues . clone ( ) ,
1186
+ worker ,
1187
+ ~ [ stealer ] ,
1188
1188
sleepers. clone ( ) ) ;
1189
1189
1190
1190
let mut handle = sched. make_handle ( ) ;
5 commit comments
bors commentedon Nov 29, 2013
saw approval from pcwalton
at alexcrichton@a70f9d7
bors commentedon Nov 29, 2013
merging alexcrichton/rust/issue-4877 = a70f9d7 into auto
bors commentedon Nov 29, 2013
alexcrichton/rust/issue-4877 = a70f9d7 merged ok, testing candidate = dd1184e
bors commentedon Nov 29, 2013
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/2702
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-c/builds/548
success: http://buildbot.rust-lang.org/builders/auto-mac-32-nopt-t/builds/548
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/2706
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1812
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1811
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/2719
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1811
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1812
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/2721
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1811
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1811
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/1887
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/2707
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/1811
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/1813
success: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/2483
bors commentedon Nov 29, 2013
fast-forwarding master to auto = dd1184e