Gavin Ray
09/10/2022, 3:46 PMclass DiskManagerImpl(file: File) : DiskManager {
private val channel = AsynchronousFileChannel.open(file.toPath(), StandardOpenOption.READ, StandardOpenOption.WRITE)
override suspend fun readPage(pageId: PageId, buffer: MemorySegment) {
val offset = pageId * PAGE_SIZE
val read = channel.readAsync(buffer.asByteBuffer(), offset.toLong())
require(read == PAGE_SIZE) { "Failed to read page $pageId" }
}
override suspend fun writePage(pageId: PageId, buffer: MemorySegment) {
val offset = pageId * PAGE_SIZE
val written = channel.writeAsync(buffer.asByteBuffer(), offset.toLong())
require(written == PAGE_SIZE) { "Failed to write page $pageId" }
}
}
Giorgos Makris
09/10/2022, 5:13 PMGavin Ray
09/10/2022, 5:17 PMGavin Ray
09/10/2022, 5:18 PMReadWriteMutex
example too which works with Coroutines:
• https://gist.github.com/bobvawter/4ff642d5996dfccb228425909f303306Giorgos Makris
09/10/2022, 7:43 PM