All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.sciss.lucre.synth.impl.NodeIdAllocatorImpl.scala Maven / Gradle / Ivy

There is a newer version: 3.30.0
Show newest version
/*
 *  NodeIdAllocatorImpl.scala
 *  (SoundProcesses)
 *
 *  Copyright (c) 2010-2019 Hanns Holger Rutz. All rights reserved.
 *
 *	This software is published under the GNU Lesser General Public License v2.1+
 *
 *
 *  For further information, please contact Hanns Holger Rutz at
 *  [email protected]
 */

package de.sciss.lucre.synth.impl

import de.sciss.lucre.synth.NodeIdAllocator
import scala.concurrent.stm.{InTxn, Ref}

final class NodeIdAllocatorImpl(user: Int, initTemp: Int) extends NodeIdAllocator {
  private val temp = Ref(initTemp)
  private val mask = user << 26

  def alloc()(implicit tx: InTxn): Int = {
    // `getAndTransform`:
    // "Transforms the value referenced by this `Ref` by applying the function
    // `f`, and returns the previous value."
    val x = temp.getAndTransform { old =>
      val next = old + 1
      if (next < 0x03FFFFFF) next else initTemp
    }
    x | mask
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy