fix: improve lock handling in user session interactions #36

Merged
lq64 merged 1 commits from fix/locks into main 2025-11-05 11:19:37 +01:00
2 changed files with 2 additions and 2 deletions
Showing only changes of commit 5165fce746 - Show all commits

View File

@@ -185,7 +185,7 @@ class GameLobby private(
} }
private def getPlayerInteractable(userSession: UserSession, iType: InteractionType): AbstractPlayer = { private def getPlayerInteractable(userSession: UserSession, iType: InteractionType): AbstractPlayer = {
if (!Thread.holdsLock(userSession.lock)) { if (!userSession.lock.isHeldByCurrentThread) {
throw new IllegalStateException("The user session is not locked!") throw new IllegalStateException("The user session is not locked!")
} }
if (userSession.canInteract.isEmpty || userSession.canInteract.get != iType) { if (userSession.canInteract.isEmpty || userSession.canInteract.get != iType) {

View File

@@ -9,7 +9,7 @@ import java.util.concurrent.locks.{Lock, ReentrantLock}
class UserSession(user: User, val host: Boolean) extends PlayerSession { class UserSession(user: User, val host: Boolean) extends PlayerSession {
var canInteract: Option[InteractionType] = None var canInteract: Option[InteractionType] = None
val lock: Lock = ReentrantLock() val lock: ReentrantLock = ReentrantLock()
override def updatePlayer(event: SimpleEvent): Unit = { override def updatePlayer(event: SimpleEvent): Unit = {
event match { event match {