mdedetrich commented on code in PR #371:
URL: https://github.com/apache/incubator-pekko/pull/371#discussion_r1231977117


##########
actor/src/main/scala/org/apache/pekko/io/dns/IdGenerator.scala:
##########
@@ -58,4 +56,37 @@ private[pekko] object IdGenerator {
    */
   def random(rand: java.util.Random): IdGenerator =
     () => (rand.nextInt(MaxUnsignedShort) - Short.MinValue).toShort
+
+  private[pekko] class EnhancedDoubleHashGenerator(semaphoreTimeout: 
FiniteDuration, seed: Random) extends IdGenerator {
+
+    /**
+     * An efficient thread safe generator of pseudo random shorts based on
+     * https://en.wikipedia.org/wiki/Double_hashing#Enhanced_double_hashing.
+     *
+     * Note that due to the usage of a semaphore this method is optimized
+     * for the happy case (i.e. least contention) on multiple threads.
+     */
+    private val lock = new Semaphore(1)
+    private var index = seed.nextLong
+    private var increment = seed.nextLong
+    private var count = 1L
+
+    private val onAcquireFailure = IdGenerator.random(seed)
+
+    override final def nextId(): Short = {
+      if (lock.tryAcquire(semaphoreTimeout.length, semaphoreTimeout.unit)) {

Review Comment:
   Okay I will do so



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to