Removed locks - this is not threaded app
This commit is contained in:
parent
e993b2ef25
commit
a9325de8f9
@ -6,8 +6,6 @@ from twisted.internet.protocol import Factory
|
|||||||
import syncplay
|
import syncplay
|
||||||
from syncplay.protocols import SyncServerProtocol
|
from syncplay.protocols import SyncServerProtocol
|
||||||
import time
|
import time
|
||||||
import threading
|
|
||||||
|
|
||||||
|
|
||||||
class SyncFactory(Factory):
|
class SyncFactory(Factory):
|
||||||
def __init__(self, password = '', banlist = None , isolateRooms = False):
|
def __init__(self, password = '', banlist = None , isolateRooms = False):
|
||||||
@ -18,8 +16,6 @@ class SyncFactory(Factory):
|
|||||||
self._rooms = {}
|
self._rooms = {}
|
||||||
self._roomStates = {}
|
self._roomStates = {}
|
||||||
self.isolateRooms = isolateRooms
|
self.isolateRooms = isolateRooms
|
||||||
self.roomUpdateLock = threading.RLock()
|
|
||||||
self.roomUsersLock = threading.RLock()
|
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
return SyncServerProtocol(self)
|
return SyncServerProtocol(self)
|
||||||
@ -50,13 +46,11 @@ class SyncFactory(Factory):
|
|||||||
self.broadcast(watcherProtocol, l)
|
self.broadcast(watcherProtocol, l)
|
||||||
|
|
||||||
def getWatcher(self, watcherProtocol):
|
def getWatcher(self, watcherProtocol):
|
||||||
with self.roomUsersLock:
|
|
||||||
for room in self._rooms.itervalues():
|
for room in self._rooms.itervalues():
|
||||||
if(room.has_key(watcherProtocol)):
|
if(room.has_key(watcherProtocol)):
|
||||||
return room[watcherProtocol]
|
return room[watcherProtocol]
|
||||||
|
|
||||||
def getAllWatchers(self, watcherProtocol):
|
def getAllWatchers(self, watcherProtocol):
|
||||||
with self.roomUsersLock:
|
|
||||||
if(self.isolateRooms):
|
if(self.isolateRooms):
|
||||||
room = self.getWatcher(watcherProtocol).room
|
room = self.getWatcher(watcherProtocol).room
|
||||||
return self._rooms[room]
|
return self._rooms[room]
|
||||||
@ -68,14 +62,11 @@ class SyncFactory(Factory):
|
|||||||
return watchers
|
return watchers
|
||||||
|
|
||||||
def _removeWatcherFromTheRoom(self, watcherProtocol):
|
def _removeWatcherFromTheRoom(self, watcherProtocol):
|
||||||
with self.roomUsersLock:
|
|
||||||
for room in self._rooms.itervalues():
|
for room in self._rooms.itervalues():
|
||||||
watcher = room.pop(watcherProtocol, None)
|
watcher = room.pop(watcherProtocol, None)
|
||||||
return watcher
|
return watcher
|
||||||
|
|
||||||
def _deleteRoomIfEmpty(self, room):
|
def _deleteRoomIfEmpty(self, room):
|
||||||
with self.roomUpdateLock:
|
|
||||||
with self.roomUsersLock:
|
|
||||||
if (self._rooms[room] == {}):
|
if (self._rooms[room] == {}):
|
||||||
self._rooms.pop(room)
|
self._rooms.pop(room)
|
||||||
self._roomStates.pop(room)
|
self._roomStates.pop(room)
|
||||||
@ -132,7 +123,6 @@ class SyncFactory(Factory):
|
|||||||
watcher = self.getWatcher(watcherProtocol)
|
watcher = self.getWatcher(watcherProtocol)
|
||||||
self.__updateWatcherPing(latencyCalculation, watcher)
|
self.__updateWatcherPing(latencyCalculation, watcher)
|
||||||
watcher.lastUpdate = time.time()
|
watcher.lastUpdate = time.time()
|
||||||
with self.roomUpdateLock:
|
|
||||||
if(watcher.file):
|
if(watcher.file):
|
||||||
if(position is not None):
|
if(position is not None):
|
||||||
self.__updatePositionState(position, doSeek, watcher)
|
self.__updatePositionState(position, doSeek, watcher)
|
||||||
@ -145,7 +135,6 @@ class SyncFactory(Factory):
|
|||||||
self.broadcastRoom(watcher, l)
|
self.broadcastRoom(watcher, l)
|
||||||
|
|
||||||
def removeWatcher(self, watcherProtocol):
|
def removeWatcher(self, watcherProtocol):
|
||||||
with self.roomUsersLock:
|
|
||||||
watcher = self._removeWatcherFromTheRoom(watcherProtocol)
|
watcher = self._removeWatcherFromTheRoom(watcherProtocol)
|
||||||
if(not watcher):
|
if(not watcher):
|
||||||
return
|
return
|
||||||
@ -162,7 +151,6 @@ class SyncFactory(Factory):
|
|||||||
return self.getWatcher(watcherProtocol).room
|
return self.getWatcher(watcherProtocol).room
|
||||||
|
|
||||||
def watcherSetRoom(self, watcherProtocol, room):
|
def watcherSetRoom(self, watcherProtocol, room):
|
||||||
with self.roomUsersLock:
|
|
||||||
watcher = self._removeWatcherFromTheRoom(watcherProtocol)
|
watcher = self._removeWatcherFromTheRoom(watcherProtocol)
|
||||||
if(not watcher):
|
if(not watcher):
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user