1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071(*
* BatMutex - Additional functions for Mutexes
* Copyright (C) 1996 Xavier Leroy
* 1996 Damien Doligez
* 2008 David Teller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version,
* with the special exception on linking described in file LICENSE.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)moduleDebugMutex=structmoduleM=structtypet={mutex:Mutex.t;id:int}letunique=letcounter=ref0andmutex =Mutex.create()infun()->Mutex.lockmutex;letresult =!counterinincrcounter;Mutex.unlockmutex;resultletcreate()={mutex=Mutex.create();id=unique()}letlockt=Printf.eprintf"[Mutex] Attempting to lock mutex %d\n"t.id;Mutex.lockt.mutex;Printf.eprintf"[Mutex] Mutex %d locked\n"t.idletunlockt=Printf.eprintf"[Mutex] Attempting to unlock mutex %d\n"t.id;Mutex.unlockt.mutex;Printf.eprintf"[Mutex] Mutex %d unlocked\n"t.idlettry_lockt=Printf.eprintf"[Mutex] Attempting to trylock mutex %d\n"t.id;letresult=Mutex.try_lockt.mutexinPrintf.eprintf"[Mutex] Mutex %d trylocked\n"t.id;resultendincludeMmoduleLock=BatConcurrent.MakeLock(M)letmake=Lock.makeletsynchronize=Lock.synchronizeendmoduleLock=BatConcurrent.MakeLock(Mutex)letmake=Lock.makeletsynchronize=Lock.synchronize