@@ -400,6 +400,9 @@ static int _send_block (struct curvecpr_messager *messager, struct curvecpr_bloc
400
400
sent because it could fail for any other arbitrary reason as well and need
401
401
to be reinvoked. */
402
402
}
403
+
404
+ /* Update the last sent time for timeout calcuations. */
405
+ messager -> my_sent_clock = messager -> chicago .clock ;
403
406
}
404
407
405
408
/* Remove all the acknowledged ranges from the pending queue. */
@@ -418,9 +421,6 @@ static int _send_block (struct curvecpr_messager *messager, struct curvecpr_bloc
418
421
if (messager -> their_eof && messager -> their_contiguous_sent_bytes >= messager -> their_total_bytes )
419
422
messager -> their_final = 1 ;
420
423
421
- /* Update the last sent time for timeout calcuations. */
422
- messager -> my_sent_clock = messager -> chicago .clock ;
423
-
424
424
/* Reset last received ID so we don't acknowledge an old message. */
425
425
messager -> their_sent_id = 0 ;
426
426
@@ -490,13 +490,19 @@ long long curvecpr_messager_next_timeout (struct curvecpr_messager *messager)
490
490
491
491
long long at , timeout ;
492
492
493
+ /* If we have anything to be written, we wouldn't spin at all, so don't include an
494
+ adjustment in the timeout for it in that case. */
495
+ int would_spin = 1 ;
496
+
493
497
curvecpr_chicago_refresh_clock (chicago );
494
498
495
499
at = chicago -> clock + 60000000000LL ; /* 60 seconds. */
496
500
497
501
if (!cf -> ops .sendmarkq_is_full (messager )) {
498
502
/* If we have pending data, we might write it. */
499
503
if (!cf -> ops .sendq_is_empty (messager )) {
504
+ would_spin = 0 ;
505
+
500
506
/* Write at the write rate. */
501
507
if (at > messager -> my_sent_clock + chicago -> wr_rate )
502
508
at = messager -> my_sent_clock + chicago -> wr_rate ;
@@ -507,16 +513,20 @@ long long curvecpr_messager_next_timeout (struct curvecpr_messager *messager)
507
513
if (cf -> ops .sendmarkq_head (messager , & block )) {
508
514
/* No earliest block. */
509
515
} else {
516
+ would_spin = 0 ;
517
+
510
518
if (at > block -> clock + chicago -> rtt_timeout )
511
519
at = block -> clock + chicago -> rtt_timeout ;
512
520
}
513
521
514
- /* If the current time is after the next action time, the timeout is 0. However, we
515
- always have at least a 1 millisecond timeout to prevent the CPU from spinning. */
516
522
if (chicago -> clock > at )
517
- timeout = 1000000 ;
523
+ timeout = 0 ;
518
524
else
519
- timeout = at - chicago -> clock + 1000000 ;
525
+ timeout = at - chicago -> clock ;
526
+
527
+ /* Apply spinning adjustment if necessary. */
528
+ if (would_spin )
529
+ timeout += 1000000 ;
520
530
521
531
if (cf -> ops .put_next_timeout )
522
532
cf -> ops .put_next_timeout (messager , timeout );
0 commit comments