forked from sergeych/crypto2
added more KMP platforms, reused protectedop from mp_bintools where it is implemented almost everywhere
This commit is contained in:
1 parent
b86c7a853e
commit
431d91b080
8 files changed
+27
-76
No files matched your search
@@ -2,6 +2,8 @@ package net.sergeych.crypto2
|
||||
|
||||
import net.sergeych.bintools.CRC
|
||||
|
||||
fun isValidContrail(data: UByteArray): Boolean = CRC.crc8(data.copyOfRange(1, data.size)) == data[0]
|
||||
fun isValidContrail(data: UByteArray): Boolean = CRC.crc8(
|
||||
data.copyOfRange(1, data.size).toByteArray()
|
||||
) == data[0]
|
||||
|
||||
fun createContrail(data: UByteArray): UByteArray = ubyteArrayOf(CRC.crc8(data)) + data
|
||||
fun createContrail(data: UByteArray): UByteArray = ubyteArrayOf(CRC.crc8(data.toByteArray())) + data
|
||||
@@ -1,5 +1,8 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
import net.sergeych.synctools.ProtectedOp
|
||||
import net.sergeych.synctools.invoke
|
||||
|
||||
/**
|
||||
* Multiplatform (JS and battery included) atomically mutable value.
|
||||
* Actual value can be either changed in a block of [mutuate] when
|
||||
@@ -18,7 +21,7 @@ open class AtomicValue<T>(initialValue: T) {
|
||||
* @return result of the mutation. Note that immediate call to property [value]
|
||||
* could already return modified bu some other thread value!
|
||||
*/
|
||||
fun mutate(mutator: (T) -> T): T = op {
|
||||
fun mutate(mutator: (T) -> T): T = op.invoke {
|
||||
actualValue = mutator(actualValue)
|
||||
actualValue
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package net.sergeych.tools
|
||||
|
||||
/**
|
||||
* Multiplatform interface to perform a regular (not suspend) operation
|
||||
* protected by a platform mutex (where necessary). Get real implementation
|
||||
* with [ProtectedOp]
|
||||
*/
|
||||
interface ProtectedOpImplementation {
|
||||
/**
|
||||
* Call [f] iin mutually exclusive mode, it means that only one invocation
|
||||
* can be active at a time, all the rest are waiting until the current operation
|
||||
* will finish.
|
||||
*/
|
||||
operator fun <T>invoke(f: ()->T): T
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the platform-depended implementation of a mutex-protected operation.
|
||||
*/
|
||||
expect fun ProtectedOp(): ProtectedOpImplementation
|
||||
Reference in new issue
Block a user