Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
7a30b827
Commit
7a30b827
authored
Feb 11, 2013
by
Max-Wilhelm Bruker
Browse files
changed Server_Room::gamesMutex to QReadWriteLock
parent
00029eee
Changes
7
Hide whitespace changes
Inline
Side-by-side
common/server.cpp
View file @
7a30b827
...
...
@@ -273,7 +273,7 @@ void Server::externalUserLeft(const QString &userName)
if
(
!
room
)
continue
;
Q
Mutex
Locker
roomGamesLocker
(
&
room
->
games
Mutex
);
Q
Read
Locker
roomGamesLocker
(
&
room
->
games
Lock
);
Server_Game
*
game
=
room
->
getGames
().
value
(
userGamesIterator
.
key
());
if
(
!
game
)
continue
;
...
...
@@ -399,7 +399,7 @@ void Server::externalGameCommandContainerReceived(const CommandContainer &cont,
throw
Response
::
RespNotInRoom
;
}
Q
Mutex
Locker
roomGamesLocker
(
&
room
->
games
Mutex
);
Q
Read
Locker
roomGamesLocker
(
&
room
->
games
Lock
);
Server_Game
*
game
=
room
->
getGames
().
value
(
cont
.
game_id
());
if
(
!
game
)
{
qDebug
()
<<
"externalGameCommandContainerReceived: game id="
<<
cont
.
game_id
()
<<
"not found"
;
...
...
@@ -509,7 +509,7 @@ int Server::getGamesCount() const
QMapIterator
<
int
,
Server_Room
*>
roomIterator
(
rooms
);
while
(
roomIterator
.
hasNext
())
{
Server_Room
*
room
=
roomIterator
.
next
().
value
();
Q
Mutex
Locker
roomLocker
(
&
room
->
games
Mutex
);
Q
Read
Locker
roomLocker
(
&
room
->
games
Lock
);
result
+=
room
->
getGames
().
size
();
}
return
result
;
...
...
common/server_abstractuserinterface.cpp
View file @
7a30b827
...
...
@@ -78,7 +78,7 @@ void Server_AbstractUserInterface::joinPersistentGames(ResponseContainer &rc)
Server_Room
*
room
=
server
->
getRooms
().
value
(
pr
.
getRoomId
());
if
(
!
room
)
continue
;
Q
Mutex
Locker
roomGamesLocker
(
&
room
->
games
Mutex
);
Q
Read
Locker
roomGamesLocker
(
&
room
->
games
Lock
);
Server_Game
*
game
=
room
->
getGames
().
value
(
pr
.
getGameId
());
if
(
!
game
)
...
...
common/server_game.cpp
View file @
7a30b827
...
...
@@ -91,7 +91,7 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const
Server_Game
::~
Server_Game
()
{
room
->
games
Mutex
.
lock
();
room
->
games
Lock
.
lockForWrite
();
gameMutex
.
lock
();
gameClosed
=
true
;
...
...
@@ -107,7 +107,7 @@ Server_Game::~Server_Game()
creatorInfo
=
0
;
gameMutex
.
unlock
();
room
->
games
Mutex
.
unlock
();
room
->
games
Lock
.
unlock
();
currentReplay
->
set_duration_seconds
(
secondsElapsed
-
startTimeOfThisGame
);
replayList
.
append
(
currentReplay
);
...
...
common/server_protocolhandler.cpp
View file @
7a30b827
...
...
@@ -60,24 +60,24 @@ void Server_ProtocolHandler::prepareDestroy()
Server_Room
*
r
=
server
->
getRooms
().
value
(
gameIterator
.
value
().
first
);
if
(
!
r
)
continue
;
r
->
games
Mutex
.
lock
();
r
->
games
Lock
.
lockForRead
();
Server_Game
*
g
=
r
->
getGames
().
value
(
gameIterator
.
key
());
if
(
!
g
)
{
r
->
games
Mutex
.
unlock
();
r
->
games
Lock
.
unlock
();
continue
;
}
g
->
gameMutex
.
lock
();
Server_Player
*
p
=
g
->
getPlayers
().
value
(
gameIterator
.
value
().
second
);
if
(
!
p
)
{
g
->
gameMutex
.
unlock
();
r
->
games
Mutex
.
unlock
();
r
->
games
Lock
.
unlock
();
continue
;
}
p
->
disconnectClient
();
g
->
gameMutex
.
unlock
();
r
->
games
Mutex
.
unlock
();
r
->
games
Lock
.
unlock
();
}
server
->
roomsLock
.
unlock
();
...
...
@@ -197,7 +197,7 @@ Response::ResponseCode Server_ProtocolHandler::processGameCommandContainer(const
if
(
!
room
)
return
Response
::
RespNotInRoom
;
Q
Mutex
Locker
roomGamesLocker
(
&
room
->
games
Mutex
);
Q
Read
Locker
roomGamesLocker
(
&
room
->
games
Lock
);
Server_Game
*
game
=
room
->
getGames
().
value
(
cont
.
game_id
());
if
(
!
game
)
{
if
(
room
->
getExternalGames
().
contains
(
cont
.
game_id
()))
{
...
...
@@ -410,12 +410,12 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_G
QMapIterator
<
int
,
Server_Room
*>
roomIterator
(
server
->
getRooms
());
while
(
roomIterator
.
hasNext
())
{
Server_Room
*
room
=
roomIterator
.
next
().
value
();
room
->
games
Mutex
.
lock
();
room
->
games
Lock
.
lockForRead
();
room
->
getInfo
(
*
re
->
add_room_list
(),
false
,
true
);
QListIterator
<
ServerInfo_Game
>
gameIterator
(
room
->
getGamesOfUser
(
QString
::
fromStdString
(
cmd
.
user_name
())));
while
(
gameIterator
.
hasNext
())
re
->
add_game_list
()
->
CopyFrom
(
gameIterator
.
next
());
room
->
games
Mutex
.
unlock
();
room
->
games
Lock
.
unlock
();
}
server
->
roomsLock
.
unlock
();
...
...
common/server_room.cpp
View file @
7a30b827
...
...
@@ -13,7 +13,7 @@
#include
<google/protobuf/descriptor.h>
Server_Room
::
Server_Room
(
int
_id
,
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
,
const
QStringList
&
_gameTypes
,
Server
*
parent
)
:
QObject
(
parent
),
id
(
_id
),
name
(
_name
),
description
(
_description
),
autoJoin
(
_autoJoin
),
joinMessage
(
_joinMessage
),
gameTypes
(
_gameTypes
),
games
Mutex
(
QMutex
::
Recursive
)
:
QObject
(
parent
),
id
(
_id
),
name
(
_name
),
description
(
_description
),
autoJoin
(
_autoJoin
),
joinMessage
(
_joinMessage
),
gameTypes
(
_gameTypes
),
games
Lock
(
QReadWriteLock
::
Recursive
)
{
connect
(
this
,
SIGNAL
(
gameListChanged
(
ServerInfo_Game
)),
this
,
SLOT
(
broadcastGameListUpdate
(
ServerInfo_Game
)),
Qt
::
QueuedConnection
);
}
...
...
@@ -22,12 +22,12 @@ Server_Room::~Server_Room()
{
qDebug
(
"Server_Room destructor"
);
games
Mutex
.
lock
();
games
Lock
.
lockForWrite
();
const
QList
<
Server_Game
*>
gameList
=
games
.
values
();
for
(
int
i
=
0
;
i
<
gameList
.
size
();
++
i
)
delete
gameList
[
i
];
games
.
clear
();
games
Mutex
.
unlock
();
games
Lock
.
unlock
();
usersLock
.
lockForWrite
();
users
.
clear
();
...
...
@@ -49,7 +49,7 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
result
.
set_auto_join
(
autoJoin
);
}
games
Mutex
.
lock
();
games
Lock
.
lockForRead
();
result
.
set_game_count
(
games
.
size
()
+
externalGames
.
size
());
if
(
complete
)
{
QMapIterator
<
int
,
Server_Game
*>
gameIterator
(
games
);
...
...
@@ -61,7 +61,7 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
result
.
add_game_list
()
->
CopyFrom
(
externalGameIterator
.
next
().
value
());
}
}
games
Mutex
.
unlock
();
games
Lock
.
unlock
();
usersLock
.
lockForRead
();
result
.
set_player_count
(
users
.
size
()
+
externalUsers
.
size
());
...
...
@@ -158,12 +158,12 @@ void Server_Room::removeExternalUser(const QString &name)
void
Server_Room
::
updateExternalGameList
(
const
ServerInfo_Game
&
gameInfo
)
{
// This function is always called from the Server thread with server->roomsMutex locked.
games
Mutex
.
lock
();
games
Lock
.
lockForWrite
();
if
(
!
gameInfo
.
has_player_count
()
&&
externalGames
.
contains
(
gameInfo
.
game_id
()))
externalGames
.
remove
(
gameInfo
.
game_id
());
else
externalGames
.
insert
(
gameInfo
.
game_id
(),
gameInfo
);
games
Mutex
.
unlock
();
games
Lock
.
unlock
();
broadcastGameListUpdate
(
gameInfo
,
false
);
ServerInfo_Room
roomInfo
;
...
...
@@ -175,7 +175,7 @@ Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGam
// This function is called from the Server thread and from the S_PH thread.
// server->roomsMutex is always locked.
Q
Mutex
Locker
roomGamesLocker
(
&
games
Mutex
);
Q
Read
Locker
roomGamesLocker
(
&
games
Lock
);
Server_Game
*
g
=
games
.
value
(
cmd
.
game_id
());
if
(
!
g
)
{
if
(
externalGames
.
contains
(
cmd
.
game_id
()))
{
...
...
@@ -233,7 +233,7 @@ void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool
void
Server_Room
::
addGame
(
Server_Game
*
game
)
{
games
Mutex
.
lock
();
games
Lock
.
lockForWrite
();
connect
(
game
,
SIGNAL
(
gameInfoChanged
(
ServerInfo_Game
)),
this
,
SLOT
(
broadcastGameListUpdate
(
ServerInfo_Game
)));
game
->
gameMutex
.
lock
();
...
...
@@ -241,7 +241,7 @@ void Server_Room::addGame(Server_Game *game)
ServerInfo_Game
gameInfo
;
game
->
getInfo
(
gameInfo
);
game
->
gameMutex
.
unlock
();
games
Mutex
.
unlock
();
games
Lock
.
unlock
();
emit
gameListChanged
(
gameInfo
);
ServerInfo_Room
roomInfo
;
...
...
@@ -250,7 +250,7 @@ void Server_Room::addGame(Server_Game *game)
void
Server_Room
::
removeGame
(
Server_Game
*
game
)
{
// No need to lock games
Mutex
or gameMutex. This method is only
// No need to lock games
Lock
or gameMutex. This method is only
// called from ~Server_Game, which locks both mutexes anyway beforehand.
disconnect
(
game
,
0
,
this
,
0
);
...
...
@@ -267,7 +267,7 @@ void Server_Room::removeGame(Server_Game *game)
int
Server_Room
::
getGamesCreatedByUser
(
const
QString
&
userName
)
const
{
Q
Mutex
Locker
locker
(
&
games
Mutex
);
Q
Read
Locker
locker
(
&
games
Lock
);
QMapIterator
<
int
,
Server_Game
*>
gamesIterator
(
games
);
int
result
=
0
;
...
...
@@ -279,7 +279,7 @@ int Server_Room::getGamesCreatedByUser(const QString &userName) const
QList
<
ServerInfo_Game
>
Server_Room
::
getGamesOfUser
(
const
QString
&
userName
)
const
{
Q
Mutex
Locker
locker
(
&
games
Mutex
);
Q
Read
Locker
locker
(
&
games
Lock
);
QList
<
ServerInfo_Game
>
result
;
QMapIterator
<
int
,
Server_Game
*>
gamesIterator
(
games
);
...
...
common/server_room.h
View file @
7a30b827
...
...
@@ -43,7 +43,7 @@ private slots:
void
broadcastGameListUpdate
(
const
ServerInfo_Game
&
gameInfo
,
bool
sendToIsl
=
true
);
public:
mutable
QReadWriteLock
usersLock
;
mutable
Q
Mutex
games
Mutex
;
mutable
Q
ReadWriteLock
games
Lock
;
Server_Room
(
int
_id
,
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
,
const
QStringList
&
_gameTypes
,
Server
*
parent
);
~
Server_Room
();
int
getId
()
const
{
return
id
;
}
...
...
servatrice/src/isl_interface.cpp
View file @
7a30b827
...
...
@@ -128,7 +128,7 @@ void IslInterface::initServer()
while
(
roomIterator
.
hasNext
())
{
Server_Room
*
room
=
roomIterator
.
next
().
value
();
room
->
usersLock
.
lockForRead
();
room
->
games
Mutex
.
lock
();
room
->
games
Lock
.
lockForRead
();
room
->
getInfo
(
*
event
.
add_room_list
(),
true
,
true
,
false
,
false
);
}
...
...
@@ -150,7 +150,7 @@ void IslInterface::initServer()
roomIterator
.
toFront
();
while
(
roomIterator
.
hasNext
())
{
roomIterator
.
next
();
roomIterator
.
value
()
->
games
Mutex
.
unlock
();
roomIterator
.
value
()
->
games
Lock
.
unlock
();
roomIterator
.
value
()
->
usersLock
.
unlock
();
}
server
->
roomsLock
.
unlock
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment