KMP-RWMutex is a lightweight Kotlin Multiplatform read-write mutex implementation based on Golang's sync.RWMutex.
Kotlin DSL:
repositories {
mavenCentral()
}
dependencies {
implementation("com.mayakapps.rwmutex:rwmutex:<version>")
}Groovy DSL:
repositories {
mavenCentral()
}
dependencies {
implementation "com.mayakapps.rwmutex:rwmutex:<version>"
}Don't forget to replace <version> with the latest version found on the badges above or the desired version.
val rwMutex = ReadWriteMutex()
// You can use extension functions like `withReadLock` and `withWriteLock` for simpler usage.
rwMutex.withReadLock { /* read lock acquired */ }
rwMutex.withWriteLock { /* write lock acquired */ }
// Or you can use the mutexes directly.
val readMutex = rwMutex.readMutex
val writeMutex = rwMutex.writeMutex
// For state checks, you can use the `state` property which returns a snapshot of the current state.
val state = rwMutex.state
val isReadLocked = state.isReadLockedFor more information, please refer to the API documentation.
See documentation here
All the code in this repository is licensed under the Apache License, Version 2.0. See LICENSE for more information.
All contributions are welcome. If you are reporting an issue, please use the provided template. If you're planning to contribute to the code, please open an issue first describing what feature you're planning to add or what issue you're planning to fix. This allows better discussion and coordination of efforts. You can also check open issues for bugs/features that needs to be fixed/implemented.