Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.55 KB | None | 0 0
  1. var minNode: Node? = null
  2.  
  3.                 while (minNode == null) {
  4.                     val first = (0 until 2 * workers).random()
  5.                     var firstNode: Node? = null
  6.                     if (qLocks[first].tryLock()) {
  7.                         firstNode = queues[first].poll()
  8.                         qLocks[first].unlock()
  9.                     }
  10.  
  11.                     val second = (0 until 2 * workers).random()
  12.                     var secondNode: Node? = null
  13.                     if (qLocks[second].tryLock()) {
  14.                         qLocks[second].lock()
  15.                         secondNode = queues[second].poll()
  16.                     }
  17.  
  18.                     if (firstNode != null && secondNode != null) {
  19.                         if (NODE_DISTANCE_COMPARATOR.compare(firstNode, secondNode) > 0) {
  20.                             minNode = secondNode
  21.                             qLocks[first].lock()
  22.                             queues[first].add(firstNode)
  23.                             qLocks[first].unlock()
  24.                         } else {
  25.                             minNode = firstNode
  26.                             qLocks[second].lock()
  27.                             queues[second].add(secondNode)
  28.                             qLocks[second].unlock()
  29.                         }
  30.                     }
  31.  
  32.                     if (firstNode == null) {
  33.                         minNode = secondNode
  34.                     }
  35.  
  36.                     if (secondNode == null) {
  37.                         minNode = firstNode
  38.                     }
  39.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement