mirror of
https://github.com/c-cube/linol.git
synced 2025-12-05 19:00:34 -05:00
fix: protect Eio's out channel with a mutex
Some checks failed
github pages / deploy (push) Has been cancelled
build / build4 (4.14.x, ubuntu-latest) (push) Has been cancelled
build / build5 (5.1.x, ubuntu-latest) (push) Has been cancelled
build / build5 (5.2.x, ubuntu-latest) (push) Has been cancelled
build / build5 (5.3.x, ubuntu-latest) (push) Has been cancelled
Some checks failed
github pages / deploy (push) Has been cancelled
build / build4 (4.14.x, ubuntu-latest) (push) Has been cancelled
build / build5 (5.1.x, ubuntu-latest) (push) Has been cancelled
build / build5 (5.2.x, ubuntu-latest) (push) Has been cancelled
build / build5 (5.3.x, ubuntu-latest) (push) Has been cancelled
close #58
This commit is contained in:
parent
00479b0f05
commit
fb49472f34
2 changed files with 16 additions and 7 deletions
|
|
@ -1,4 +1,9 @@
|
||||||
|
|
||||||
|
# 0.11
|
||||||
|
|
||||||
|
- breaking: the Eio library now needs the output channel to be paired with
|
||||||
|
an `Eio.Mutex.t` to prevent race conditions (#58)
|
||||||
|
|
||||||
# 0.10
|
# 0.10
|
||||||
|
|
||||||
- use `git subtree` to vendor lsp+jsonrpc, so that they
|
- use `git subtree` to vendor lsp+jsonrpc, so that they
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module IO_eio :
|
||||||
with type 'a t = 'a
|
with type 'a t = 'a
|
||||||
and type env = Eio_unix.Stdenv.base
|
and type env = Eio_unix.Stdenv.base
|
||||||
and type in_channel = Eio.Buf_read.t
|
and type in_channel = Eio.Buf_read.t
|
||||||
and type out_channel = Eio_unix.sink_ty Eio.Std.r = struct
|
and type out_channel = Eio.Mutex.t * Eio_unix.sink_ty Eio.Std.r = struct
|
||||||
type 'a t = 'a
|
type 'a t = 'a
|
||||||
|
|
||||||
let ( let+ ) x f = f x
|
let ( let+ ) x f = f x
|
||||||
|
|
@ -28,17 +28,21 @@ module IO_eio :
|
||||||
let stdin env =
|
let stdin env =
|
||||||
Eio.Buf_read.of_flow ~max_size:1_000_000 (Eio.Stdenv.stdin env)
|
Eio.Buf_read.of_flow ~max_size:1_000_000 (Eio.Stdenv.stdin env)
|
||||||
|
|
||||||
let stdout = Eio.Stdenv.stdout
|
let stdout_mutex = Eio.Mutex.create ()
|
||||||
|
let stdout env = stdout_mutex, Eio.Stdenv.stdout env
|
||||||
|
|
||||||
type env = Eio_unix.Stdenv.base
|
type env = Eio_unix.Stdenv.base
|
||||||
type in_channel = Eio.Buf_read.t
|
type in_channel = Eio.Buf_read.t
|
||||||
type out_channel = Eio_unix.sink_ty Eio.Std.r
|
type out_channel = Eio.Mutex.t * Eio_unix.sink_ty Eio.Std.r
|
||||||
|
|
||||||
let write_string out_ch str = Eio.Flow.copy_string str out_ch
|
let write_string (mutex, out_ch) str =
|
||||||
|
Eio.Mutex.use_rw ~protect:false mutex (fun () ->
|
||||||
|
Eio.Flow.copy_string str out_ch)
|
||||||
|
|
||||||
let write out_ch bytes off len =
|
let write (mutex, out_ch) bytes off len =
|
||||||
Eio.Buf_write.with_flow out_ch @@ fun w ->
|
Eio.Mutex.use_rw ~protect:false mutex (fun () ->
|
||||||
Eio.Buf_write.bytes w ~off ~len bytes
|
Eio.Buf_write.with_flow out_ch @@ fun w ->
|
||||||
|
Eio.Buf_write.bytes w ~off ~len bytes)
|
||||||
|
|
||||||
let read in_ch bytes off len =
|
let read in_ch bytes off len =
|
||||||
let str = Eio.Buf_read.take len in_ch in
|
let str = Eio.Buf_read.take len in_ch in
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue