yeet the mutex

This commit is contained in:
tali 2024-02-02 11:50:22 -05:00
parent 59511905c9
commit cac7a091fe
2 changed files with 7 additions and 1 deletions

View File

@ -36,12 +36,13 @@ let syslog_priority = function
| ERROR -> "3" (* LOG_ERR *) | ERROR -> "3" (* LOG_ERR *)
let writer t ~ts ~ns ~lvl msg = let writer t ~ts ~ns ~lvl msg =
Mutex.lock t.mutex;
let dgram = let dgram =
Mutex.protect t.mutex @@ fun () ->
Buffer.clear t.buf; Buffer.clear t.buf;
ignore ts; ignore ts;
add_field t.buf "MESSAGE" (Printf.sprintf "%s: %s" ns msg); add_field t.buf "MESSAGE" (Printf.sprintf "%s: %s" ns msg);
add_field t.buf "PRIORITY" (syslog_priority lvl); add_field t.buf "PRIORITY" (syslog_priority lvl);
Buffer.to_bytes t.buf Buffer.to_bytes t.buf
in in
Mutex.unlock t.mutex;
Unix.sendto t.sock_fd dgram 0 (Bytes.length dgram) [] t.dest |> ignore Unix.sendto t.sock_fd dgram 0 (Bytes.length dgram) [] t.dest |> ignore

5
lib/logging/mutex.ml Normal file
View File

@ -0,0 +1,5 @@
(* stub implementation since we actually aren't multithreaded *)
type t = unit
external create : unit -> t = "%identity"
external lock : t -> unit = "%identity"
external unlock : t -> unit = "%identity"