mirror of
https://github.com/c-cube/linol.git
synced 2025-12-06 11:15:46 -05:00
fix: make server requests thread safe
This commit is contained in:
parent
a779942f95
commit
41a6c3e306
4 changed files with 6 additions and 5 deletions
|
|
@ -31,6 +31,7 @@
|
|||
(and
|
||||
(>= "1.17")
|
||||
(< "1.18")))
|
||||
atomic
|
||||
("jsonrpc"
|
||||
(and
|
||||
(>= "1.17")
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ depends: [
|
|||
"logs"
|
||||
"trace" {>= "0.4"}
|
||||
"lsp" {>= "1.17" & < "1.18"}
|
||||
"atomic"
|
||||
"jsonrpc" {>= "1.17" & < "1.18"}
|
||||
"ocaml" {>= "4.14"}
|
||||
"odoc" {with-doc}
|
||||
|
|
|
|||
2
src/dune
2
src/dune
|
|
@ -3,4 +3,4 @@
|
|||
(public_name linol)
|
||||
(private_modules log)
|
||||
(flags :standard -warn-error -a+8)
|
||||
(libraries yojson lsp logs threads trace.core))
|
||||
(libraries yojson lsp logs threads trace.core atomic))
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ module Make (IO : IO) : S with module IO = IO = struct
|
|||
on_sent: json -> unit;
|
||||
on_received: json -> unit;
|
||||
s: server;
|
||||
mutable id_counter: int;
|
||||
id_counter: int Atomic.t;
|
||||
pending_responses: (Req_id.t, server_request_handler_pair) Hashtbl.t;
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ module Make (IO : IO) : S with module IO = IO = struct
|
|||
ic;
|
||||
oc;
|
||||
s = server;
|
||||
id_counter = 0;
|
||||
id_counter = Atomic.make 0;
|
||||
on_sent;
|
||||
on_received;
|
||||
pending_responses = Hashtbl.create 8;
|
||||
|
|
@ -116,8 +116,7 @@ module Make (IO : IO) : S with module IO = IO = struct
|
|||
|
||||
(** Returns a new, unused [Req_id.t] to send a server request. *)
|
||||
let fresh_lsp_id (self : t) : Req_id.t =
|
||||
let id = self.id_counter in
|
||||
self.id_counter <- id + 1;
|
||||
let id = Atomic.fetch_and_add self.id_counter 1 in
|
||||
`Int id
|
||||
|
||||
(** Registers a new handler for a request response. The return indicates
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue