mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -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
|
|
@ -181,6 +181,30 @@ Servatrice::Servatrice(QObject *parent)
|
|||
Servatrice::~Servatrice()
|
||||
{
|
||||
gameServer->close();
|
||||
|
||||
// clients live in other threads, we need to lock them
|
||||
clientsLock.lockForRead();
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
QMetaObject::invokeMethod(clients.at(i), "prepareDestroy", Qt::QueuedConnection);
|
||||
clientsLock.unlock();
|
||||
|
||||
// client destruction is asynchronous, wait for all clients to be gone
|
||||
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);
|
||||
|
||||
prepareDestroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue