Skip to content

Commit

Permalink
paper optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Feb 3, 2024
1 parent 79e4ac0 commit 70519e4
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ object Token {
def grant(using ReplicaId): Mutate = mutate:
if !isOwner then unchanged
else
// We find the “largest” ID that wants the token.
// This is incredibly “unfair” but does prevent deadlocks in case someone needs multiple tokens.
current.wants.elements.maxOption match
case Some(head) if head != replicaId =>
Token(Ownership(current.os.epoche + 1, head), ReplicatedSet.empty)
case _ => unchanged
selectNewOwner match
case None => unchanged
case Some(nextOwner) =>
Token(Ownership(current.os.epoche + 1, nextOwner), ReplicatedSet.empty)

def selectNewOwner(using ReplicaId, PermQuery): Option[Uid] =
// We find the “largest” ID that wants the token.
// This is incredibly “unfair” but does prevent deadlocks in case someone needs multiple tokens.
current.wants.elements.maxOption.filter(id => id != replicaId)

def isOwner(using ReplicaId, PermQuery): Boolean = replicaId == current.os.owner
}
Expand Down

0 comments on commit 70519e4

Please sign in to comment.