12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061(*
* Copyright (c) 2013-2022 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openImportincludeAtomic_write_intfmoduleCheck_closed_store(AW:S)=structtypet={closed:boolref;t:AW.t}typekey=AW.keytypevalue=AW.valuetypewatch=AW.watchletmake_closeablet={closed=reffalse;t}letget_if_open_exnt=if!(t.closed)thenraiseStore_properties.Closedelset.tletmemtk=(get_if_open_exnt|>AW.mem)kletfindtk=(get_if_open_exnt|>AW.find)kletsettkv=(get_if_open_exnt|>AW.set)kvlettest_and_settk~test~set=(get_if_open_exnt|>AW.test_and_set)k~test~setletremovetk=(get_if_open_exnt|>AW.remove)kletlistt=get_if_open_exnt|>AW.listletwatcht?initf=(get_if_open_exnt|>AW.watch)?initfletwatch_keytk?initf=(get_if_open_exnt|>AW.watch_key)k?initfletunwatchtw=(get_if_open_exnt|>AW.unwatch)wletcloset=if!(t.closed)thenLwt.return_unitelse(t.closed:=true;AW.closet.t)letcleart=get_if_open_exnt|>AW.clearendmoduleCheck_closed(Make_atomic_write:Maker)(K:Type.S)(V:Type.S)=structmoduleAW=Make_atomic_write(K)(V)includeCheck_closed_store(AW)letvconf=let+t=AW.vconfin{closed=reffalse;t}end