From e87428ae51a47d8a40d7f9cc17115017293066cd Mon Sep 17 00:00:00 2001 From: craff Date: Wed, 8 Dec 2021 16:38:59 -1000 Subject: [PATCH] release semaphore does not return anything anymore --- src/Tiny_httpd.ml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index dd4244c7..eb50e830 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -721,8 +721,13 @@ module Sem_ = struct let release m t = Mutex.lock t.mutex; t.n <- t.n + m; - let r = t.n in 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 end @@ -1125,13 +1130,17 @@ let run (self:t) : (unit,_) result = (fun () -> try handle_client_ self client_sock; - let avail = Sem_.release 1 self.sem_max_connections in - _debug (fun k -> k"closing inactive connections (%d connections available)" avail) + Sem_.release 1 self.sem_max_connections; + _debug (fun k -> k + "closing inactive connections (%d connections available)" + (Sem_.available_connection self.sem_max_connections)) with | e -> (try Unix.close client_sock with _ -> ()); - let avail = Sem_.release 1 self.sem_max_connections in - _debug (fun k -> k"closing connections on error (%d connections available)" avail); + 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)); raise e ); with e ->