@@ -20,6 +20,8 @@ export select, select2, selecti, select2i, selectable;
20
20
export spawn_service, spawn_service_recv;
21
21
export stream, port, chan, shared_chan, port_set, channel;
22
22
23
+ const SPIN_COUNT : uint = 0 ;
24
+
23
25
macro_rules! move {
24
26
{ $x: expr } => { unsafe { let y <- * ptr:: addr_of( $x) ; y } }
25
27
}
@@ -272,15 +274,15 @@ unsafe fn get_buffer<T: send>(p: *packet_header) -> ~buffer<T> {
272
274
class buffer_resource<T : send> {
273
275
let buffer: ~buffer < T > ;
274
276
new( +b: ~buffer<T >) {
275
- let p = ptr:: addr_of ( * b) ;
277
+ // let p = ptr::addr_of(*b);
276
278
//#error("take %?", p);
277
279
atomic_add_acq ( b. header . ref_count , 1 ) ;
278
280
self . buffer = b;
279
281
}
280
282
281
283
drop unsafe {
282
284
let b = move !{ self . buffer } ;
283
- let p = ptr:: addr_of ( * b) ;
285
+ // let p = ptr::addr_of(*b);
284
286
//#error("drop %?", p);
285
287
let old_count = atomic_sub_rel ( b. header . ref_count , 1 ) ;
286
288
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
@@ -345,14 +347,26 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>)
345
347
rustrt:: task_clear_event_reject ( this) ;
346
348
p. header . blocked_task = some ( this) ;
347
349
let mut first = true ;
350
+ let mut count = SPIN_COUNT ;
348
351
loop {
349
352
rustrt:: task_clear_event_reject ( this) ;
350
353
let old_state = swap_state_acq ( p. header . state ,
351
354
blocked) ;
352
355
alt old_state {
353
356
empty {
354
357
#debug( "no data available on %?, going to sleep." , p_) ;
355
- wait_event ( this) ;
358
+ if count == 0 {
359
+ wait_event ( this) ;
360
+ }
361
+ else {
362
+ count -= 1 ;
363
+ // FIXME (#524): Putting the yield here destroys a lot
364
+ // of the benefit of spinning, since we still go into
365
+ // the scheduler at every iteration. However, without
366
+ // this everything spins too much because we end up
367
+ // sometimes blocking the thing we are waiting on.
368
+ task:: yield ( ) ;
369
+ }
356
370
#debug ( "woke up, p.state = %?" , copy p. header . state ) ;
357
371
}
358
372
blocked {
0 commit comments