1- use crossbeam :: sync :: SegQueue ;
1+ use crossbeam_queue :: SegQueue ;
22use latch:: Latch ;
33use std:: any:: Any ;
44use std:: cell:: UnsafeCell ;
55use std:: mem;
66use unwind;
77
8- pub enum JobResult < T > {
8+ pub ( super ) enum JobResult < T > {
99 None ,
1010 Ok ( T ) ,
1111 Panic ( Box < Any + Send > ) ,
@@ -16,7 +16,7 @@ pub enum JobResult<T> {
1616/// arranged in a deque, so that thieves can take from the top of the
1717/// deque while the main worker manages the bottom of the deque. This
1818/// deque is managed by the `thread_pool` module.
19- pub trait Job {
19+ pub ( super ) trait Job {
2020 /// Unsafe: this may be called from a different thread than the one
2121 /// which scheduled the job, so the implementer must ensure the
2222 /// appropriate traits are met, whether `Send`, `Sync`, or both.
@@ -30,7 +30,7 @@ pub trait Job {
3030/// true type is something like `*const StackJob<...>`, but we hide
3131/// it. We also carry the "execute fn" from the `Job` trait.
3232#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
33- pub struct JobRef {
33+ pub ( super ) struct JobRef {
3434 pointer : * const ( ) ,
3535 execute_fn : unsafe fn ( * const ( ) ) ,
3636}
@@ -41,24 +41,21 @@ unsafe impl Sync for JobRef {}
4141impl JobRef {
4242 /// Unsafe: caller asserts that `data` will remain valid until the
4343 /// job is executed.
44- pub unsafe fn new < T > ( data : * const T ) -> JobRef
44+ pub ( super ) unsafe fn new < T > ( data : * const T ) -> JobRef
4545 where
4646 T : Job ,
4747 {
4848 let fn_ptr: unsafe fn ( * const T ) = <T as Job >:: execute;
4949
5050 // erase types:
51- let fn_ptr: unsafe fn ( * const ( ) ) = mem:: transmute ( fn_ptr) ;
52- let pointer = data as * const ( ) ;
53-
5451 JobRef {
55- pointer : pointer ,
56- execute_fn : fn_ptr,
52+ pointer : data as * const ( ) ,
53+ execute_fn : mem :: transmute ( fn_ptr) ,
5754 }
5855 }
5956
6057 #[ inline]
61- pub unsafe fn execute ( & self ) {
58+ pub ( super ) unsafe fn execute ( & self ) {
6259 ( self . execute_fn ) ( self . pointer )
6360 }
6461}
@@ -67,13 +64,13 @@ impl JobRef {
6764/// executes it need not free any heap data, the cleanup occurs when
6865/// the stack frame is later popped. The function parameter indicates
6966/// `true` if the job was stolen -- executed on a different thread.
70- pub struct StackJob < L , F , R >
67+ pub ( super ) struct StackJob < L , F , R >
7168where
7269 L : Latch + Sync ,
7370 F : FnOnce ( bool ) -> R + Send ,
7471 R : Send ,
7572{
76- pub latch : L ,
73+ pub ( super ) latch : L ,
7774 func : UnsafeCell < Option < F > > ,
7875 result : UnsafeCell < JobResult < R > > ,
7976}
@@ -84,23 +81,23 @@ where
8481 F : FnOnce ( bool ) -> R + Send ,
8582 R : Send ,
8683{
87- pub fn new ( func : F , latch : L ) -> StackJob < L , F , R > {
84+ pub ( super ) fn new ( func : F , latch : L ) -> StackJob < L , F , R > {
8885 StackJob {
89- latch : latch ,
86+ latch,
9087 func : UnsafeCell :: new ( Some ( func) ) ,
9188 result : UnsafeCell :: new ( JobResult :: None ) ,
9289 }
9390 }
9491
95- pub unsafe fn as_job_ref ( & self ) -> JobRef {
92+ pub ( super ) unsafe fn as_job_ref ( & self ) -> JobRef {
9693 JobRef :: new ( self )
9794 }
9895
99- pub unsafe fn run_inline ( self , stolen : bool ) -> R {
96+ pub ( super ) unsafe fn run_inline ( self , stolen : bool ) -> R {
10097 self . func . into_inner ( ) . unwrap ( ) ( stolen)
10198 }
10299
103- pub unsafe fn into_result ( self ) -> R {
100+ pub ( super ) unsafe fn into_result ( self ) -> R {
104101 self . result . into_inner ( ) . into_return_value ( )
105102 }
106103}
@@ -130,7 +127,7 @@ where
130127/// signal that the job executed.
131128///
132129/// (Probably `StackJob` should be refactored in a similar fashion.)
133- pub struct HeapJob < BODY >
130+ pub ( super ) struct HeapJob < BODY >
134131where
135132 BODY : FnOnce ( ) + Send ,
136133{
@@ -141,7 +138,7 @@ impl<BODY> HeapJob<BODY>
141138where
142139 BODY : FnOnce ( ) + Send ,
143140{
144- pub fn new ( func : BODY ) -> Self {
141+ pub ( super ) fn new ( func : BODY ) -> Self {
145142 HeapJob {
146143 job : UnsafeCell :: new ( Some ( func) ) ,
147144 }
@@ -150,7 +147,7 @@ where
150147 /// Creates a `JobRef` from this job -- note that this hides all
151148 /// lifetimes, so it is up to you to ensure that this JobRef
152149 /// doesn't outlive any data that it closes over.
153- pub unsafe fn as_job_ref ( self : Box < Self > ) -> JobRef {
150+ pub ( super ) unsafe fn as_job_ref ( self : Box < Self > ) -> JobRef {
154151 let this: * const Self = mem:: transmute ( self ) ;
155152 JobRef :: new ( this)
156153 }
@@ -172,7 +169,7 @@ impl<T> JobResult<T> {
172169 /// its JobResult is populated) into its return value.
173170 ///
174171 /// NB. This will panic if the job panicked.
175- pub fn into_return_value ( self ) -> T {
172+ pub ( super ) fn into_return_value ( self ) -> T {
176173 match self {
177174 JobResult :: None => unreachable ! ( ) ,
178175 JobResult :: Ok ( x) => x,
@@ -182,18 +179,18 @@ impl<T> JobResult<T> {
182179}
183180
184181/// Indirect queue to provide FIFO job priority.
185- pub struct JobFifo {
182+ pub ( super ) struct JobFifo {
186183 inner : SegQueue < JobRef > ,
187184}
188185
189186impl JobFifo {
190- pub fn new ( ) -> Self {
187+ pub ( super ) fn new ( ) -> Self {
191188 JobFifo {
192189 inner : SegQueue :: new ( ) ,
193190 }
194191 }
195192
196- pub unsafe fn push ( & self , job_ref : JobRef ) -> JobRef {
193+ pub ( super ) unsafe fn push ( & self , job_ref : JobRef ) -> JobRef {
197194 // A little indirection ensures that spawns are always prioritized in FIFO order. The
198195 // jobs in a thread's deque may be popped from the back (LIFO) or stolen from the front
199196 // (FIFO), but either way they will end up popping from the front of this queue.
@@ -205,10 +202,6 @@ impl JobFifo {
205202impl Job for JobFifo {
206203 unsafe fn execute ( this : * const Self ) {
207204 // We "execute" a queue by executing its first job, FIFO.
208- ( * this)
209- . inner
210- . try_pop ( )
211- . expect ( "job in fifo queue" )
212- . execute ( )
205+ ( * this) . inner . pop ( ) . expect ( "job in fifo queue" ) . execute ( )
213206 }
214207}
0 commit comments