@@ -54,7 +54,7 @@ type source_t = [ `Fallible | `Infallible ]
54
54
exception Unavailable
55
55
56
56
type streaming_state =
57
- [ `Unavailable | `Ready of unit -> unit | `Done of Frame .t ]
57
+ [ `Unavailable | `Ready of Frame .t Clock_ready .t | `Done of Frame .t ]
58
58
59
59
(* * {1 Proto clocks}
60
60
@@ -546,13 +546,15 @@ class virtual operator ?pos ?(name = "src") sources =
546
546
547
547
method virtual private can_generate_frame : bool
548
548
method virtual private generate_frame : Frame. t
549
- val mutable streaming_state : streaming_state = `Unavailable
549
+ val streaming_state : streaming_state Atomic .t = Atomic .make `Unavailable
550
550
551
551
method is_ready =
552
552
if not content_type_computation_allowed then false
553
553
else (
554
554
self#has_ticked;
555
- match streaming_state with `Ready _ | `Done _ -> true | _ -> false )
555
+ match Atomic. get streaming_state with
556
+ | `Ready _ | `Done _ -> true
557
+ | _ -> false )
556
558
557
559
val mutable _cache = None
558
560
@@ -569,28 +571,25 @@ class virtual operator ?pos ?(name = "src") sources =
569
571
let cache_pos = Frame. position cache in
570
572
let size = Lazy. force Frame. size in
571
573
if cache_pos > 0 || self#can_generate_frame then
572
- streaming_state < -
573
- `Ready
574
- (fun () ->
575
- let buf =
576
- if cache_pos < size then
577
- Frame. append cache self#instrumented_generate_frame
578
- else cache
579
- in
580
- let buf_pos = Frame. position buf in
581
- let buf =
582
- if size < buf_pos then (
583
- _cache < -
584
- Some
585
- (Frame. chunk ~start: size ~stop: (buf_pos - size) buf);
586
- Frame. slice buf size)
587
- else buf
588
- in
589
- streaming_state < - `Done buf)
590
- else streaming_state < - `Unavailable );
574
+ Atomic. set streaming_state
575
+ (`Ready
576
+ (Clock_ready. make (fun () ->
577
+ let buf =
578
+ if cache_pos < size then
579
+ Frame. append cache self#instrumented_generate_frame
580
+ else cache
581
+ in
582
+ let buf_pos = Frame. position buf in
583
+ if size < buf_pos then (
584
+ _cache < -
585
+ Some
586
+ (Frame. chunk ~start: size ~stop: (buf_pos - size) buf);
587
+ Frame. slice buf size)
588
+ else buf)))
589
+ else Atomic. set streaming_state `Unavailable );
591
590
592
591
self#on_after_output (fun () ->
593
- match (streaming_state, consumed) with
592
+ match (Atomic. get streaming_state, consumed) with
594
593
| `Done buf , 0 -> _cache < - Some buf
595
594
| `Done buf , n ->
596
595
let pos = Frame. position buf in
@@ -601,12 +600,12 @@ class virtual operator ?pos ?(name = "src") sources =
601
600
602
601
method peek_frame =
603
602
self#has_ticked;
604
- match streaming_state with
603
+ match Atomic. get streaming_state with
605
604
| `Unavailable ->
606
605
log#critical " source called while not ready!" ;
607
606
raise Unavailable
608
607
| `Ready fn ->
609
- fn ( ) ;
608
+ Atomic. set streaming_state ( `Done ( Clock_ready. process fn) );
610
609
self#peek_frame
611
610
| `Done data -> data
612
611
0 commit comments