/* * Copyright 2025 Casper Dalgaard Nielsen * Adam Yasser Tallouzi * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. *//// Functions on read-write locks.pubmod Fixpoint3.ReadWriteLock {import java.util.concurrent.locks.{StampedLock => JStampedLock}/// Returns a fresh read-write lock in the given region.pubdefmkLock(_: Region[r]): ReadWriteLock[r] \ r = ReadWriteLock(unsafeIOasr { new JStampedLock().asReadWriteLock() })/// Acquires the read lock of `lock`, blocking until it is available.pubdefreadLock(lock: ReadWriteLock[r]): Unit \ r =let ReadWriteLock(l) = lock;unsafeIOasr { l.readLock().lock() }/// Acquires the write lock of `lock`, blocking until it is available.pubdefwriteLock(lock: ReadWriteLock[r]): Unit \ r =let ReadWriteLock(l) = lock;unsafeIOasr { l.writeLock().lock() }/// Releases the read lock of `lock`.pubdefunlockRead(lock: ReadWriteLock[r]): Unit \ r =let ReadWriteLock(l) = lock;unsafeIOasr { l.readLock().unlock() }/// Releases the write lock of `lock`.pubdefunlockWrite(lock: ReadWriteLock[r]): Unit \ r =let ReadWriteLock(l) = lock;unsafeIOasr { l.writeLock().unlock() }}