remove mutex to get available_connections

This commit is contained in:
craff 2021-12-08 17:47:53 -10:00
parent 8da6967039
commit 9b4a1b1197

View file

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