@@ -7,6 +7,18 @@ use std::ffi::c_longlong;
77use std:: fmt:: Debug ;
88use std:: sync:: atomic:: { AtomicBool , AtomicU32 , AtomicUsize , Ordering } ;
99
10+ /// Ordered trait for user's datastructures.
11+ pub trait Ordered {
12+ /// The highest precedence.
13+ const HIGHEST_PRECEDENCE : c_longlong = c_longlong:: MIN ;
14+ /// The lowest precedence.
15+ const LOWEST_PRECEDENCE : c_longlong = c_longlong:: MAX ;
16+ /// The default precedence.
17+ const DEFAULT_PRECEDENCE : c_longlong = 0 ;
18+ /// Get the priority of the element.
19+ fn priority ( & self ) -> c_longlong ;
20+ }
21+
1022/// Work stealing global queue, shared by multiple threads.
1123#[ repr( C ) ]
1224#[ derive( Debug ) ]
@@ -33,6 +45,13 @@ impl<T: Debug> Drop for OrderedWorkStealQueue<T> {
3345 }
3446}
3547
48+ impl < T : Debug + Ordered > OrderedWorkStealQueue < T > {
49+ /// Push an element to the global queue.
50+ pub fn push ( & self , item : T ) {
51+ self . push_with_priority ( item. priority ( ) , item) ;
52+ }
53+ }
54+
3655impl < T : Debug > OrderedWorkStealQueue < T > {
3756 /// Create a new `WorkStealQueue` instance.
3857 #[ must_use]
@@ -136,6 +155,14 @@ impl<T: Debug> Drop for OrderedLocalQueue<'_, T> {
136155 }
137156}
138157
158+ impl < T : Debug + Ordered > OrderedLocalQueue < ' _ , T > {
159+ /// If the queue is full, first push half to global,
160+ /// then push the item to global.
161+ pub fn push ( & self , item : T ) {
162+ self . push_with_priority ( item. priority ( ) , item) ;
163+ }
164+ }
165+
139166impl < ' l , T : Debug > OrderedLocalQueue < ' l , T > {
140167 fn new (
141168 shared : & ' l OrderedWorkStealQueue < T > ,
0 commit comments