26
26
//!
27
27
//! use std::rt::deque::BufferPool;
28
28
//!
29
- //! let mut pool = BufferPool::init ();
29
+ //! let mut pool = BufferPool::new ();
30
30
//! let (mut worker, mut stealer) = pool.deque();
31
31
//!
32
32
//! // Only the worker may push/pop
@@ -139,14 +139,14 @@ struct Buffer<T> {
139
139
impl < T : Send > BufferPool < T > {
140
140
/// Allocates a new buffer pool which in turn can be used to allocate new
141
141
/// deques.
142
- pub fn init ( ) -> BufferPool < T > {
142
+ pub fn new ( ) -> BufferPool < T > {
143
143
BufferPool { pool : Exclusive :: new ( ~[ ] ) }
144
144
}
145
145
146
146
/// Allocates a new work-stealing deque which will send/receiving memory to
147
147
/// and from this buffer pool.
148
148
pub fn deque ( & mut self ) -> ( Worker < T > , Stealer < T > ) {
149
- let ( a, b) = UnsafeArc :: new2 ( Deque :: init ( self . clone ( ) ) ) ;
149
+ let ( a, b) = UnsafeArc :: new2 ( Deque :: new ( self . clone ( ) ) ) ;
150
150
( Worker { deque : a } , Stealer { deque : b } )
151
151
}
152
152
@@ -155,7 +155,7 @@ impl<T: Send> BufferPool<T> {
155
155
self . pool . with ( |pool| {
156
156
match pool. iter ( ) . position ( |x| x. size ( ) >= ( 1 << bits) ) {
157
157
Some ( i) => pool. remove ( i) ,
158
- None => ~Buffer :: init ( bits)
158
+ None => ~Buffer :: new ( bits)
159
159
}
160
160
} )
161
161
}
@@ -221,7 +221,7 @@ impl<T: Send> Clone for Stealer<T> {
221
221
// personally going to heavily comment what's going on here.
222
222
223
223
impl < T : Send > Deque < T > {
224
- fn init ( mut pool : BufferPool < T > ) -> Deque < T > {
224
+ fn new ( mut pool : BufferPool < T > ) -> Deque < T > {
225
225
let buf = pool. alloc ( MIN_BITS ) ;
226
226
Deque {
227
227
bottom : AtomicInt :: new ( 0 ) ,
@@ -341,7 +341,7 @@ impl<T: Send> Drop for Deque<T> {
341
341
}
342
342
343
343
impl < T : Send > Buffer < T > {
344
- unsafe fn init ( log_size : int ) -> Buffer < T > {
344
+ unsafe fn new ( log_size : int ) -> Buffer < T > {
345
345
let size = ( 1 << log_size) * mem:: size_of :: < T > ( ) ;
346
346
let buffer = libc:: malloc ( size as libc:: size_t ) ;
347
347
assert ! ( !buffer. is_null( ) ) ;
@@ -375,7 +375,7 @@ impl<T: Send> Buffer<T> {
375
375
// Again, unsafe because this has incredibly dubious ownership violations.
376
376
// It is assumed that this buffer is immediately dropped.
377
377
unsafe fn resize ( & self , b : int , t : int , delta : int ) -> Buffer < T > {
378
- let mut buf = Buffer :: init ( self . log_size + delta) ;
378
+ let mut buf = Buffer :: new ( self . log_size + delta) ;
379
379
for i in range ( t, b) {
380
380
buf. put ( i, self . get ( i) ) ;
381
381
}
@@ -406,7 +406,7 @@ mod tests {
406
406
407
407
#[ test]
408
408
fn smoke ( ) {
409
- let mut pool = BufferPool :: init ( ) ;
409
+ let mut pool = BufferPool :: new ( ) ;
410
410
let ( mut w, mut s) = pool. deque ( ) ;
411
411
assert_eq ! ( w. pop( ) , None ) ;
412
412
assert_eq ! ( s. steal( ) , Empty ) ;
@@ -421,7 +421,7 @@ mod tests {
421
421
#[ test]
422
422
fn stealpush ( ) {
423
423
static AMT : int = 100000 ;
424
- let mut pool = BufferPool :: < int > :: init ( ) ;
424
+ let mut pool = BufferPool :: < int > :: new ( ) ;
425
425
let ( mut w, s) = pool. deque ( ) ;
426
426
let t = do Thread :: start {
427
427
let mut s = s;
@@ -447,7 +447,7 @@ mod tests {
447
447
#[ test]
448
448
fn stealpush_large ( ) {
449
449
static AMT : int = 100000 ;
450
- let mut pool = BufferPool :: < ( int , int ) > :: init ( ) ;
450
+ let mut pool = BufferPool :: < ( int , int ) > :: new ( ) ;
451
451
let ( mut w, s) = pool. deque ( ) ;
452
452
let t = do Thread :: start {
453
453
let mut s = s;
@@ -509,15 +509,15 @@ mod tests {
509
509
510
510
#[ test]
511
511
fn run_stampede ( ) {
512
- let mut pool = BufferPool :: < ~int > :: init ( ) ;
512
+ let mut pool = BufferPool :: < ~int > :: new ( ) ;
513
513
let ( w, s) = pool. deque ( ) ;
514
514
stampede ( w, s, 8 , 10000 ) ;
515
515
}
516
516
517
517
#[ test]
518
518
fn many_stampede ( ) {
519
519
static AMT : uint = 4 ;
520
- let mut pool = BufferPool :: < ~int > :: init ( ) ;
520
+ let mut pool = BufferPool :: < ~int > :: new ( ) ;
521
521
let threads = range ( 0 , AMT ) . map ( |_| {
522
522
let ( w, s) = pool. deque ( ) ;
523
523
do Thread :: start {
@@ -536,7 +536,7 @@ mod tests {
536
536
static NTHREADS : int = 8 ;
537
537
static mut DONE : AtomicBool = INIT_ATOMIC_BOOL ;
538
538
static mut HITS : AtomicUint = INIT_ATOMIC_UINT ;
539
- let mut pool = BufferPool :: < int > :: init ( ) ;
539
+ let mut pool = BufferPool :: < int > :: new ( ) ;
540
540
let ( mut w, s) = pool. deque ( ) ;
541
541
542
542
let threads = range ( 0 , NTHREADS ) . map ( |_| {
@@ -595,7 +595,7 @@ mod tests {
595
595
static AMT : int = 10000 ;
596
596
static NTHREADS : int = 4 ;
597
597
static mut DONE : AtomicBool = INIT_ATOMIC_BOOL ;
598
- let mut pool = BufferPool :: < ( int , uint ) > :: init ( ) ;
598
+ let mut pool = BufferPool :: < ( int , uint ) > :: new ( ) ;
599
599
let ( mut w, s) = pool. deque ( ) ;
600
600
601
601
let ( threads, hits) = vec:: unzip ( range ( 0 , NTHREADS ) . map ( |_| {
0 commit comments