Skip to content

Commit 8868622

Browse files
author
Jeremie Dimino
committed
Fix a race condition in LTerm_read_line
Before this commit, #draw_update could still be executed after Fixes ocaml-community/utop#175
1 parent bec5794 commit 8868622

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/lTerm_read_line.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,9 @@ object(self)
787787
(* The height of the displayed material. *)
788788

789789
val mutable resolver = None
790-
(* The current resolver for resolving input sequences. *)
790+
(* The current resolver for resolving input sequences. *)
791+
792+
val mutable running = true
791793

792794
initializer
793795
completion_start <- (
@@ -826,7 +828,11 @@ object(self)
826828
draw_queued <- true;
827829
Lwt.pause () >>= fun () ->
828830
draw_queued <- false;
829-
Lwt_mutex.with_lock draw_mutex (fun () -> self#draw_update)
831+
Lwt_mutex.with_lock draw_mutex (fun () ->
832+
if running then
833+
self#draw_update
834+
else
835+
return ())
830836
end
831837

832838
method draw_update =
@@ -1221,12 +1227,12 @@ object(self)
12211227
(* Update the size with the current size. *)
12221228
set_size (LTerm.size term);
12231229

1224-
let running = ref true in
1230+
running <- true;
12251231

12261232
(* Redraw everything when needed. *)
12271233
let event =
12281234
E.map_p
1229-
(fun () -> if !running then self#queue_draw_update else return ())
1235+
(fun () -> if running then self#queue_draw_update else return ())
12301236
(E.select [
12311237
E.stamp (S.changes size) ();
12321238
Zed_edit.update self#edit [Zed_edit.cursor self#context];
@@ -1257,7 +1263,7 @@ object(self)
12571263
self#queue_draw_update >>= fun () ->
12581264
self#loop)
12591265
(fun exn ->
1260-
running := false;
1266+
running <- false;
12611267
E.stop event;
12621268
Lwt_mutex.with_lock draw_mutex (fun () -> self#draw_failure) >>= fun () ->
12631269
Lwt.fail exn))
@@ -1268,7 +1274,7 @@ object(self)
12681274
| None ->
12691275
return ())
12701276
end >>= fun result ->
1271-
running := false;
1277+
running <- false;
12721278
E.stop event;
12731279
Lwt_mutex.with_lock draw_mutex (fun () -> self#draw_success) >>= fun () ->
12741280
return result

0 commit comments

Comments
 (0)