Lock mutex when accessing m_env in Server::~Server
authorPerttu Ahola <celeron55@gmail.com>
Fri, 14 Oct 2011 09:39:25 +0000 (12:39 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 14 Oct 2011 09:39:25 +0000 (12:39 +0300)
src/server.cpp

index 73df81dde17cb02a47c9993e46a647b3d9dabfbf..5b9903f5ad42f0bf970f5b2a0430ffede1312ebe 100644 (file)
@@ -1139,19 +1139,23 @@ Server::~Server()
                        {}
                }
        }
+       
+       {
+               JMutexAutoLock envlock(m_env_mutex);
 
-       /*
-               Save players
-       */
-       dstream<<"Server: Saving players"<<std::endl;
-       m_env.serializePlayers(m_mapsavedir);
+               /*
+                       Save players
+               */
+               dstream<<"Server: Saving players"<<std::endl;
+               m_env.serializePlayers(m_mapsavedir);
 
-       /*
-               Save environment metadata
-       */
-       dstream<<"Server: Saving environment metadata"<<std::endl;
-       m_env.saveMeta(m_mapsavedir);
-       
+               /*
+                       Save environment metadata
+               */
+               dstream<<"Server: Saving environment metadata"<<std::endl;
+               m_env.saveMeta(m_mapsavedir);
+       }
+               
        /*
                Stop threads
        */
@@ -1201,6 +1205,8 @@ void Server::start(unsigned short port)
 void Server::stop()
 {
        DSTACK(__FUNCTION_NAME);
+       
+       dout_server<<"Server: Stopping and waiting threads"<<std::endl;
 
        // Stop threads (set run=false first so both start stopping)
        m_thread.setRun(false);