replace lock with lock_guard

Change-Id: I778fd472546a0287f068f04569a67315045ee901
diff --git a/src/chat-dialog-backend.cpp b/src/chat-dialog-backend.cpp
index 801db7d..216f465 100644
--- a/src/chat-dialog-backend.cpp
+++ b/src/chat-dialog-backend.cpp
@@ -65,10 +65,11 @@
 
     m_face->getIoService().run();
 
-    m_mutex.lock();
-    shouldResume = m_shouldResume;
-    m_shouldResume = false;
-    m_mutex.unlock();
+    {
+      std::lock_guard<std::mutex>lock(m_mutex);
+      shouldResume = m_shouldResume;
+      m_shouldResume = false;
+    }
 
   } while (shouldResume);
 
@@ -486,9 +487,10 @@
     // Update localPrefix
     m_localRoutingPrefix = newLocalRoutingPrefix;
 
-    m_mutex.lock();
-    m_shouldResume = true;
-    m_mutex.unlock();
+    {
+      std::lock_guard<std::mutex>lock(m_mutex);
+      m_shouldResume = true;
+    }
 
     close();
 
@@ -501,9 +503,10 @@
 void
 ChatDialogBackend::shutdown()
 {
-  m_mutex.lock();
-  m_shouldResume = false;
-  m_mutex.unlock();
+  {
+    std::lock_guard<std::mutex>lock(m_mutex);
+    m_shouldResume = false;
+  }
 
   close();
 
diff --git a/src/chat-dialog-backend.hpp b/src/chat-dialog-backend.hpp
index f8133f7..26f588b 100644
--- a/src/chat-dialog-backend.hpp
+++ b/src/chat-dialog-backend.hpp
@@ -11,12 +11,12 @@
 #define CHRONOCHAT_CHAT_DIALOG_BACKEND_HPP
 
 #include <QThread>
-#include <QMutex>
 
 #ifndef Q_MOC_RUN
 #include "common.hpp"
 #include "chatroom-info.hpp"
 #include "chatbuf.pb.h"
+#include <mutex>
 #include <socket.hpp>
 #endif
 
@@ -165,7 +165,7 @@
 
   BackendRoster m_roster;                // User roster
 
-  QMutex m_mutex;
+  std::mutex m_mutex;
   bool m_shouldResume;
 };
 
diff --git a/src/chatroom-discovery-backend.cpp b/src/chatroom-discovery-backend.cpp
index 933a2f1..0da409d 100644
--- a/src/chatroom-discovery-backend.cpp
+++ b/src/chatroom-discovery-backend.cpp
@@ -61,14 +61,15 @@
 
     m_face->getIoService().run();
 
-    m_mutex.lock();
-    shouldResume = m_shouldResume;
-    m_shouldResume = false;
-    m_mutex.unlock();
+    {
+      std::lock_guard<std::mutex>lock(m_mutex);
+      shouldResume = m_shouldResume;
+      m_shouldResume = false;
+    }
 
   } while (shouldResume);
 
-  std::cerr << "Bye!" << std::endl;
+  std::cerr << "DiscoveryBackend: Bye!" << std::endl;
 }
 
 void
@@ -273,9 +274,10 @@
 
     updatePrefixes();
 
-    m_mutex.lock();
-    m_shouldResume = true;
-    m_mutex.unlock();
+    {
+      std::lock_guard<std::mutex>lock(m_mutex);
+      m_shouldResume = true;
+    }
 
     close();
 
@@ -403,9 +405,10 @@
   m_userDiscoveryPrefix.append(m_identity).append("CHRONOCHAT-DISCOVERYDATA");
   updatePrefixes();
 
-  m_mutex.lock();
-  m_shouldResume = true;
-  m_mutex.unlock();
+  {
+    std::lock_guard<std::mutex>lock(m_mutex);
+    m_shouldResume = true;
+  }
 
   close();
 
@@ -439,9 +442,10 @@
 void
 ChatroomDiscoveryBackend::shutdown()
 {
-  m_mutex.lock();
-  m_shouldResume = false;
-  m_mutex.unlock();
+  {
+    std::lock_guard<std::mutex>lock(m_mutex);
+    m_shouldResume = false;
+  }
 
   close();
 
diff --git a/src/chatroom-discovery-backend.hpp b/src/chatroom-discovery-backend.hpp
index 986c3a1..b3f809f 100644
--- a/src/chatroom-discovery-backend.hpp
+++ b/src/chatroom-discovery-backend.hpp
@@ -11,14 +11,14 @@
 #ifndef CHRONOCHAT_CHATROOM_DISCOVERY_BACKEND_HPP
 #define CHRONOCHAT_CHATROOM_DISCOVERY_BACKEND_HPP
 
-#include <ndn-cxx/util/scheduler.hpp>
-#include <boost/random.hpp>
 #include <QThread>
-#include <QMutex>
 
 #ifndef Q_MOC_RUN
 #include "common.hpp"
 #include "chatroom-info.hpp"
+#include <ndn-cxx/util/scheduler.hpp>
+#include <boost/random.hpp>
+#include <mutex>
 #include <socket.hpp>
 #endif
 
@@ -224,7 +224,7 @@
   shared_ptr<chronosync::Socket> m_sock; // SyncSocket
 
   ChatroomList m_chatroomList;
-  QMutex m_mutex;
+  std::mutex m_mutex;
 
   bool m_shouldResume;
 };