Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var minNode: Node? = null
- while (minNode == null) {
- val first = (0 until 2 * workers).random()
- var firstNode: Node? = null
- if (qLocks[first].tryLock()) {
- firstNode = queues[first].poll()
- qLocks[first].unlock()
- }
- val second = (0 until 2 * workers).random()
- var secondNode: Node? = null
- if (qLocks[second].tryLock()) {
- qLocks[second].lock()
- secondNode = queues[second].poll()
- }
- if (firstNode != null && secondNode != null) {
- if (NODE_DISTANCE_COMPARATOR.compare(firstNode, secondNode) > 0) {
- minNode = secondNode
- qLocks[first].lock()
- queues[first].add(firstNode)
- qLocks[first].unlock()
- } else {
- minNode = firstNode
- qLocks[second].lock()
- queues[second].add(secondNode)
- qLocks[second].unlock()
- }
- }
- if (firstNode == null) {
- minNode = secondNode
- }
- if (secondNode == null) {
- minNode = firstNode
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement