Skip to content

Commit

Permalink
toggle for NonBlockingHashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
rnewson committed Dec 3, 2024
1 parent 15c8e17 commit 0e14f4f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
30 changes: 25 additions & 5 deletions src/main/scala/scalang/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ trait Node extends ClusterListener with ClusterPublisher {
def timer : HashedWheelTimer
}

object ErlangNode {

def newConcurrentMap[K,V](config : NodeConfig): ConcurrentMap[K,V] = {
if (config.useNBHM) {
new NonBlockingHashMap[K,V]
} else {
new ConcurrentHashMap[K,V]
}
}

def newAtomicMap[K,V](config : NodeConfig): AtomicMap[K,V] = {
if (config.useNBHM) {
AtomicMap.atomicNBHM[K,V]
} else {
AtomicMap.atomicCHM[K,V]
}
}

}

class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) extends Node
with ExitListener
with SendListener
Expand All @@ -198,11 +218,11 @@ class ErlangNode(val name : Symbol, val cookie : String, config : NodeConfig) ex
val tickTime = config.tickTime
val poolFactory = config.poolFactory
var creation : Int = 0
val processes = new NonBlockingHashMap[Pid,ProcessAdapter]
val registeredNames = new NonBlockingHashMap[Symbol,Pid]
val channels = AtomicMap.atomicNBHM[Symbol,Channel]
val links = AtomicMap.atomicNBHM[Channel,NonBlockingHashSet[Link]]
val monitors = AtomicMap.atomicNBHM[Channel,NonBlockingHashSet[Monitor]]
val processes = ErlangNode.newConcurrentMap[Pid,ProcessAdapter](config)
val registeredNames = ErlangNode.newConcurrentMap[Symbol,Pid](config)
val channels = ErlangNode.newAtomicMap[Symbol,Channel](config)
val links = ErlangNode.newAtomicMap[Channel,NonBlockingHashSet[Link]](config)
val monitors = ErlangNode.newAtomicMap[Channel,NonBlockingHashSet[Monitor]](config)
val pidCount = new AtomicInteger(0)
val pidSerial = new AtomicInteger(0)
val executor = poolFactory.createActorPool
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/scalang/NodeConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ case class NodeConfig(
typeFactory : TypeFactory = NoneTypeFactory,
typeEncoder: TypeEncoder = NoneTypeEncoder,
typeDecoder : TypeDecoder = NoneTypeDecoder,
tickTime : Int = 60)
tickTime : Int = 60,
useNBHM: Boolean = true)

object NoneTypeFactory extends TypeFactory {
def createType(name : Symbol, arity : Int, reader : TermReader) = None
Expand Down

0 comments on commit 0e14f4f

Please sign in to comment.