release semaphore does not return anything anymore

This commit is contained in:
craff 2021-12-08 16:38:59 -10:00
parent 9e9fe32347
commit e87428ae51

View file

@ -721,8 +721,13 @@ module Sem_ = struct
let release m t = let release m t =
Mutex.lock t.mutex; Mutex.lock t.mutex;
t.n <- t.n + m; t.n <- t.n + m;
let r = t.n in
Condition.broadcast t.cond; Condition.broadcast t.cond;
Mutex.unlock t.mutex
let available_connection t =
(* locking necessary unless we have atomic read/write for int.*)
Mutex.lock t.mutex;
let r = t.n in
Mutex.unlock t.mutex; Mutex.unlock t.mutex;
r r
end end
@ -1125,13 +1130,17 @@ let run (self:t) : (unit,_) result =
(fun () -> (fun () ->
try try
handle_client_ self client_sock; handle_client_ self client_sock;
let avail = Sem_.release 1 self.sem_max_connections in Sem_.release 1 self.sem_max_connections;
_debug (fun k -> k"closing inactive connections (%d connections available)" avail) _debug (fun k -> k
"closing inactive connections (%d connections available)"
(Sem_.available_connection self.sem_max_connections))
with with
| e -> | e ->
(try Unix.close client_sock with _ -> ()); (try Unix.close client_sock with _ -> ());
let avail = Sem_.release 1 self.sem_max_connections in Sem_.release 1 self.sem_max_connections;
_debug (fun k -> k"closing connections on error (%d connections available)" avail); _debug (fun k -> k
"closing connections on error (%d connections available)"
(Sem_.available_connection self.sem_max_connections));
raise e raise e
); );
with e -> with e ->