From 9b4a1b1197b1438da5cb657b027749aa7864ffd9 Mon Sep 17 00:00:00 2001 From: craff Date: Wed, 8 Dec 2021 17:47:53 -1000 Subject: [PATCH] remove mutex to get available_connections --- src/Tiny_httpd.ml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index eb50e830..c265e440 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -724,12 +724,8 @@ module Sem_ = struct 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; - r + let available_connections t = t.n + end module Route = struct @@ -1133,14 +1129,14 @@ let run (self:t) : (unit,_) result = Sem_.release 1 self.sem_max_connections; _debug (fun k -> k "closing inactive connections (%d connections available)" - (Sem_.available_connection self.sem_max_connections)) + (Sem_.available_connections self.sem_max_connections)) with | e -> (try Unix.close client_sock with _ -> ()); Sem_.release 1 self.sem_max_connections; _debug (fun k -> k "closing connections on error (%d connections available)" - (Sem_.available_connection self.sem_max_connections)); + (Sem_.available_connections self.sem_max_connections)); raise e ); with e ->