X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fhttp_getter%2Fhttp_getter_map.ml;h=26daa21d5f2695f5b1ddcf6c22ea933b985cb6b9;hb=12e7928b2ce2113d5ac43d453026d0443f58c5e4;hp=9ee87618104003943e0f49484c7e98be736a1a0a;hpb=86e80bc65186bf4c2824dc94f5f4dd5966843f14;p=helm.git diff --git a/helm/http_getter/http_getter_map.ml b/helm/http_getter/http_getter_map.ml index 9ee876181..26daa21d5 100644 --- a/helm/http_getter/http_getter_map.ml +++ b/helm/http_getter/http_getter_map.ml @@ -24,17 +24,23 @@ * http://cs.unibo.it/helm/. *) +let debug = true;; +let debug_print s = if debug then prerr_endline s;; + exception Key_already_in of string;; exception Key_not_found of string;; class map dbname = let perm = 420 in (* permission 644 in decimal notation *) - let db = Dbm.opendbm dbname [ Dbm.Dbm_rdwr; Dbm.Dbm_create ] perm in + let open_dbm () = Dbm.opendbm dbname [ Dbm.Dbm_rdwr; Dbm.Dbm_create ] perm in + object (self) inherit ThreadSafe.threadSafe - initializer Gc.finalise Dbm.close db (* close db on GC *) + val mutable db = open_dbm () + + (*initializer Gc.finalise Dbm.close db (* close db on GC *)*) method add key value = self#doWriter (lazy ( @@ -60,9 +66,26 @@ class map dbname = Dbm.iter f db )) + method sync = + self#doWriter (lazy ( + Dbm.close db; + db <- open_dbm () + )) + method clear = self#doWriter (lazy ( - Dbm.iter (fun k _ -> Dbm.remove db k) db + Dbm.close db; + List.iter + (fun ext -> + let file = dbname ^ ext in + if Sys.file_exists file then Sys.remove file) + [".dir"; ".pag"; ".db"]; + db <- open_dbm () + )) + + method close = + self#doWriter (lazy ( + Dbm.close db )) end