Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package flames.concurrent.execution.handles
- import java.lang.invoke.{MethodHandles, VarHandle as JVarHandle}
- import scala.reflect.{ClassTag, classTag}
- object VarHandle:
- opaque type VarGet[+T] = JVarHandle
- opaque type VarSet[-T] = JVarHandle
- opaque type VarHandle[T] <: VarGet[T] & VarSet[T] = JVarHandle
- opaque type AccessModeTag[T] = T
- sealed trait AccessMode {
- type Tag[x] <: AccessModeTag[x]
- }
- opaque type Plain[T] <: AccessModeTag[T] = T
- object Plain extends AccessMode {
- type Tag[x] = Plain[x]
- }
- opaque type Opaque[T] <: Plain[T] = T
- object Opaque extends AccessMode {
- type Tag[x] = Opaque[x]
- }
- opaque type Acquire[T] <: Opaque[T] = T
- object Acquire {
- type Tag[x] = Acquire[x]
- }
- opaque type Release[T] <: Opaque[T] = T
- object Release {
- type Tag[x] = Release[x]
- }
- opaque type AcquireRelease[T] <: Acquire[T] & Release[T] = T
- object AcquireRelease {
- type Tag[x] = AcquireRelease[x]
- }
- opaque type Volatile[T] <: AcquireRelease[T] = T
- object Volatile {
- type Tag[x] = Volatile[x]
- }
- extension [T](self: Plain[VarGet[T]])
- inline def getPlain: T = self.get().asInstanceOf[T]
- extension[T](self: Opaque[VarGet[T]])
- inline def getOpaque: T = self.getOpaque().asInstanceOf[T]
- extension[T](self: Acquire[VarGet[T]])
- inline def getAcquire: T = self.getAcquire().asInstanceOf[T]
- extension[T](self: Volatile[VarGet[T]])
- inline def getVolatile: T = self.getVolatile().asInstanceOf[T]
- extension [T](self: Plain[VarSet[T]])
- inline def setPlain(value: T): Unit = self.set(value)
- extension [T](self: Opaque[VarSet[T]])
- inline def setOpaque(value: T): Unit = self.setOpaque(value)
- extension [T](self: Release[VarSet[T]])
- inline def setRelease(value: T): Unit = self.setRelease(value)
- extension [T](self: Volatile[VarSet[T]])
- inline def setVolatile(value: T): Unit = self.setVolatile(value)
- extension [T](self: Plain[VarHandle[T]])
- inline def weakCompareAndSetPlain(expected: T, exchanged: T): Boolean =
- self.weakCompareAndSetPlain(expected, exchanged)
- extension [T](self: Acquire[VarHandle[T]]) {
- inline def getAndSetAcquire(value: T): T = self.getAndSetAcquire(value).asInstanceOf[T]
- inline def compareAndExchangeAcquire(expected: T, exchanged: T): T =
- self.compareAndExchangeAcquire(expected, exchanged).asInstanceOf[T]
- inline def weakCompareAndSetAcquire(expected: T, exchanged: T): Boolean =
- self.weakCompareAndSetAcquire(expected, exchanged)
- }
- extension [T](self: Release[VarHandle[T]]) {
- inline def getAndSetRelease(value: T): T = self.getAndSetRelease(value).asInstanceOf[T]
- inline def compareAndExchangeRelease(expected: T, exchanged: T): T =
- self.compareAndExchangeRelease(expected, exchanged).asInstanceOf[T]
- inline def weakCompareAndSetRelease(expected: T, exchanged: T): Boolean =
- self.weakCompareAndSetRelease(expected, exchanged)
- }
- extension [T](self: Volatile[VarHandle[T]]) {
- inline def getAndSetVolatile(value: T): T = self.getAndSet(value).asInstanceOf[T]
- inline def compareAndSetVolatile(expected: T, exchanged: T): Boolean = self.compareAndSet(expected, exchanged)
- inline def compareAndExchangeVolatile(expected: T, exchanged: T): T =
- self.compareAndExchange(expected, exchanged).asInstanceOf[T]
- inline def weakCompareAndSetVolatile(expected: T, exchanged: T): Boolean =
- self.weakCompareAndSet(expected, exchanged)
- }
- inline def apply[From: ClassTag, Type: ClassTag](x: Type, mode: AccessMode): mode.Tag[VarHandle[Type]] =
- ???
- end apply
- end VarHandle
- export VarHandle.{
- VarGet, VarSet, VarHandle,
- AccessModeTag, Plain, Opaque,
- Acquire, Release,
- AcquireRelease, Volatile,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement