File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -422,7 +422,23 @@ let rec shift_buffers t written =
422422let rec shift_flushes t =
423423 try
424424 let (threshold, f) as flush = Flushes. dequeue_exn t.flushed in
425- if t.bytes_written > = threshold then begin f () ; shift_flushes t end
425+ (* Edited notes from @dinosaure:
426+ *
427+ * The quantities [t.bytes_written] and [threshold] are always going to be
428+ * positive integers. Therefore, we can treat them as unsinged integers for
429+ * the purposes of comparision. Doing so allows us to handle overflows in
430+ * either quantity as long as they're both within one overflow of each other.
431+ * We can accomplish this by subracting [min_int] from both quantities before
432+ * comparision. This shift a quantity that has not overflowed into the
433+ * negative integer range while shifting a quantity that has overflow into
434+ * the positive integer range.
435+ *
436+ * This effectively restablishes the relative difference when an overflow
437+ * has occurred, and otherwise just compares numbers that haven't
438+ * overflowed as similarly, just shifted down a bit.
439+ *)
440+ if t.bytes_written - min_int > = threshold - min_int
441+ then begin f () ; shift_flushes t end
426442 else Flushes. enqueue_front flush t.flushed
427443 with Not_found ->
428444 ()
You can’t perform that action at this time.
0 commit comments