mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Avoid locking on local server shutdown
This commit is contained in:
parent
d82564d84c
commit
d61d9c98a0
3 changed files with 28 additions and 22 deletions
|
|
@ -59,28 +59,6 @@ Server::~Server()
|
|||
|
||||
void Server::prepareDestroy()
|
||||
{
|
||||
// dirty :(
|
||||
clientsLock.lockForRead();
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection);
|
||||
clientsLock.unlock();
|
||||
|
||||
bool done = false;
|
||||
|
||||
class SleeperThread : public QThread
|
||||
{
|
||||
public:
|
||||
static void msleep(unsigned long msecs) { QThread::usleep(msecs); }
|
||||
};
|
||||
|
||||
do {
|
||||
SleeperThread::msleep(10);
|
||||
clientsLock.lockForRead();
|
||||
if (clients.isEmpty())
|
||||
done = true;
|
||||
clientsLock.unlock();
|
||||
} while (!done);
|
||||
|
||||
roomsLock.lockForWrite();
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue