]> git.stg.codes - stg.git/commitdiff
Use std::lock_guard instead of STG_LOCKER. master
authorMaksym Mamontov <madf@madf.info>
Wed, 31 Aug 2022 15:46:16 +0000 (18:46 +0300)
committerMaksym Mamontov <madf@madf.info>
Wed, 31 Aug 2022 15:46:16 +0000 (18:46 +0300)
30 files changed:
include/stg/locker.h [deleted file]
include/stg/user_property.h
projects/rscriptd/listener.cpp
projects/stargazer/corps_impl.h
projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp
projects/stargazer/plugins/other/ping/ping.cpp
projects/stargazer/plugins/other/rscript/rscript.cpp
projects/stargazer/plugins/store/files/file_store.cpp
projects/stargazer/plugins/store/files/file_store.h
projects/stargazer/plugins/store/firebird/firebird_store.cpp
projects/stargazer/plugins/store/firebird/firebird_store.h
projects/stargazer/plugins/store/firebird/firebird_store_admins.cpp
projects/stargazer/plugins/store/firebird/firebird_store_corporations.cpp
projects/stargazer/plugins/store/firebird/firebird_store_messages.cpp
projects/stargazer/plugins/store/firebird/firebird_store_services.cpp
projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp
projects/stargazer/plugins/store/firebird/firebird_store_users.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store.h
projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp
projects/stargazer/services_impl.h
projects/stargazer/tariffs_impl.cpp
projects/stargazer/traffcounter_impl.cpp
projects/stargazer/user_impl.cpp
projects/stargazer/user_impl.h

diff --git a/include/stg/locker.h b/include/stg/locker.h
deleted file mode 100644 (file)
index 16b0323..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *    This program is free software; you can redistribute it and/or modify
- *    it under the terms of the GNU General Public License as published by
- *    the Free Software Foundation; either version 2 of the License, or
- *    (at your option) any later version.
- *
- *    This program is distributed in the hope that it will be useful,
- *    but WITHOUT ANY WARRANTY; without even the implied warranty of
- *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *    GNU General Public License for more details.
- *
- *    You should have received a copy of the GNU General Public License
- *    along with this program; if not, write to the Free Software
- *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*
- *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
-/*
- $Revision: 1.5 $
- $Date: 2010/03/04 11:57:11 $
- $Author: faust $
-*/
-
-
-#ifndef STG_LOCKER_H
-#define STG_LOCKER_H
-
-#include <pthread.h>
-
-//-----------------------------------------------------------------------------
-class STG_LOCKER
-{
-public:
-    explicit STG_LOCKER(pthread_mutex_t& m)
-        : mutex(&m)
-        {
-        pthread_mutex_lock(mutex);
-        }
-    explicit STG_LOCKER(pthread_mutex_t * m)
-        : mutex(m)
-        {
-        pthread_mutex_lock(mutex);
-        }
-
-    ~STG_LOCKER()
-        {
-        pthread_mutex_unlock(mutex);
-        }
-private:
-    STG_LOCKER(const STG_LOCKER & rvalue);
-    STG_LOCKER & operator=(const STG_LOCKER & rvalue);
-
-    pthread_mutex_t * mutex;
-};
-//-----------------------------------------------------------------------------
-
-#endif //STG_LOCKER_H
index d73a636b2df42b82ae0296f395dfd6ef4caac6d4..3400abd0494f4a19913f42b0d13790f9bd5beb9a 100644 (file)
@@ -7,7 +7,6 @@
 #include "stg/subscriptions.h"
 #include "stg/admin_conf.h"
 #include "stg/logger.h"
 #include "stg/subscriptions.h"
 #include "stg/admin_conf.h"
 #include "stg/logger.h"
-#include "stg/locker.h"
 #include "stg/settings.h"
 #include "stg/scriptexecuter.h"
 #include "stg/common.h"
 #include "stg/settings.h"
 #include "stg/scriptexecuter.h"
 #include "stg/common.h"
index a1193527b9bc3d7c9f4f9969e6bcf31655c6b8bd..e4f1e2cd7f9097bf9cd5d21aa57da7f15a770cf2 100644 (file)
@@ -22,7 +22,6 @@
 #include "listener.h"
 
 #include "stg/scriptexecuter.h"
 #include "listener.h"
 
 #include "stg/scriptexecuter.h"
-#include "stg/locker.h"
 #include "stg/common.h"
 #include "stg/const.h"
 
 #include "stg/common.h"
 #include "stg/const.h"
 
index 193c5dbd443b15f8ab089d3554c2859ef58fec04..e4601301bc54369dc7859482759b154c2749b88b 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "stg/corporations.h"
 #include "stg/corp_conf.h"
 
 #include "stg/corporations.h"
 #include "stg/corp_conf.h"
-#include "stg/locker.h"
 #include "stg/logger.h"
 
 #include <vector>
 #include "stg/logger.h"
 
 #include <vector>
index c607b2ac714d9f859d13a46298e97517b83cafd7..60d3846cee42383e6da27ee6d6258d3f48749b3d 100644 (file)
@@ -25,7 +25,6 @@
 #include "inetaccess.h"
 
 #include "stg/common.h"
 #include "inetaccess.h"
 
 #include "stg/common.h"
-#include "stg/locker.h"
 #include "stg/tariff.h"
 #include "stg/settings.h"
 
 #include "stg/tariff.h"
 #include "stg/settings.h"
 
index 2cbd1f8b12c5da83ccb79410084e74a79021c509..892331f69d57b247ee33f519fab6eae7110604a5 100644 (file)
@@ -1,7 +1,6 @@
 #include "ping.h"
 
 #include "stg/user.h"
 #include "ping.h"
 
 #include "stg/user.h"
-#include "stg/locker.h"
 #include "stg/user_property.h"
 
 #include <algorithm>
 #include "stg/user_property.h"
 
 #include <algorithm>
index 36e84be832cc1a7c68cfadd2095238840730dfe1..24a8bd714cb6c7997acf9889b25d243c2e0a7b18 100644 (file)
@@ -24,7 +24,6 @@
 #include "ur_functor.h"
 
 #include "stg/common.h"
 #include "ur_functor.h"
 
 #include "stg/common.h"
-#include "stg/locker.h"
 #include "stg/users.h"
 #include "stg/user_property.h"
 #include "stg/logger.h"
 #include "stg/users.h"
 #include "stg/user_property.h"
 #include "stg/logger.h"
index eedb60e8715556a63f812227fd5ae4d9347ae202..d654a28c54913356d1bb92255962640216e1daf7 100644 (file)
@@ -37,7 +37,6 @@
 #include "stg/const.h"
 #include "stg/blowfish.h"
 #include "stg/logger.h"
 #include "stg/const.h"
 #include "stg/blowfish.h"
 #include "stg/logger.h"
-#include "stg/locker.h"
 #include "stg/admin_conf.h"
 #include "stg/tariff.h"
 #include "stg/tariff_conf.h"
 #include "stg/admin_conf.h"
 #include "stg/tariff.h"
 #include "stg/tariff_conf.h"
@@ -369,10 +368,6 @@ FILES_STORE::FILES_STORE()
     : m_version("file_store v.1.04"),
       m_logger(STG::PluginLogger::get("store_files"))
 {
     : m_version("file_store v.1.04"),
       m_logger(STG::PluginLogger::get("store_files"))
 {
-pthread_mutexattr_t attr;
-pthread_mutexattr_init(&attr);
-pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-pthread_mutex_init(&m_mutex, &attr);
 }
 //-----------------------------------------------------------------------------
 int FILES_STORE::ParseSettings()
 }
 //-----------------------------------------------------------------------------
 int FILES_STORE::ParseSettings()
@@ -380,7 +375,7 @@ int FILES_STORE::ParseSettings()
 int ret = m_storeSettings.ParseSettings(m_settings);
 if (ret)
     {
 int ret = m_storeSettings.ParseSettings(m_settings);
 if (ret)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = m_storeSettings.GetStrError();
     }
 return ret;
     m_errorStr = m_storeSettings.GetStrError();
     }
 return ret;
@@ -392,12 +387,12 @@ std::vector<std::string> files;
 
 if (GetFileList(&files, m_storeSettings.GetUsersDir(), S_IFDIR, ""))
     {
 
 if (GetFileList(&files, m_storeSettings.GetUsersDir(), S_IFDIR, ""))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Failed to open '" + m_storeSettings.GetUsersDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
     m_errorStr = "Failed to open '" + m_storeSettings.GetUsersDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 userList->swap(files);
 
 
 userList->swap(files);
 
@@ -410,12 +405,12 @@ std::vector<std::string> files;
 
 if (GetFileList(&files, m_storeSettings.GetAdminsDir(), S_IFREG, ".adm"))
     {
 
 if (GetFileList(&files, m_storeSettings.GetAdminsDir(), S_IFREG, ".adm"))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Failed to open '" + m_storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
     m_errorStr = "Failed to open '" + m_storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 adminList->swap(files);
 
 
 adminList->swap(files);
 
@@ -428,12 +423,12 @@ std::vector<std::string> files;
 
 if (GetFileList(&files, m_storeSettings.GetTariffsDir(), S_IFREG, ".tf"))
     {
 
 if (GetFileList(&files, m_storeSettings.GetTariffsDir(), S_IFREG, ".tf"))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Failed to open '" + m_storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
     m_errorStr = "Failed to open '" + m_storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 tariffList->swap(files);
 
 
 tariffList->swap(files);
 
@@ -446,12 +441,12 @@ std::vector<std::string> files;
 
 if (GetFileList(&files, m_storeSettings.GetServicesDir(), S_IFREG, ".serv"))
     {
 
 if (GetFileList(&files, m_storeSettings.GetServicesDir(), S_IFREG, ".serv"))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Failed to open '" + m_storeSettings.GetServicesDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
     m_errorStr = "Failed to open '" + m_storeSettings.GetServicesDir() + "': " + std::string(strerror(errno));
     return -1;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 list->swap(files);
 
 
 list->swap(files);
 
@@ -488,7 +483,7 @@ while ((entry = readdir(d)))
         {
         if (unlink(str.c_str()))
             {
         {
         if (unlink(str.c_str()))
             {
-            STG_LOCKER lock(&m_mutex);
+            std::lock_guard lock(m_mutex);
             m_errorStr = "unlink failed. Message: '";
             m_errorStr += strerror(errno);
             m_errorStr += "'";
             m_errorStr = "unlink failed. Message: '";
             m_errorStr += strerror(errno);
             m_errorStr += "'";
@@ -513,7 +508,7 @@ closedir(d);
 
 if (rmdir(path))
     {
 
 if (rmdir(path))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "rmdir failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
     m_errorStr = "rmdir failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
@@ -532,7 +527,7 @@ strprintf(&fileName, "%s%s", m_storeSettings.GetUsersDir().c_str(), login.c_str(
 
 if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1)
     {
 
 if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'";
     printfd(__FILE__, "FILES_STORE::AddUser - mkdir failed. Message: '%s'\n", strerror(errno));
     return -1;
     m_errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'";
     printfd(__FILE__, "FILES_STORE::AddUser - mkdir failed. Message: '%s'\n", strerror(errno));
     return -1;
@@ -541,7 +536,7 @@ if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) ==
 strprintf(&fileName, "%s%s/conf", m_storeSettings.GetUsersDir().c_str(), login.c_str());
 if (Touch(fileName))
     {
 strprintf(&fileName, "%s%s/conf", m_storeSettings.GetUsersDir().c_str(), login.c_str());
 if (Touch(fileName))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file \"" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
     m_errorStr = "Cannot create file \"" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
@@ -550,7 +545,7 @@ if (Touch(fileName))
 strprintf(&fileName, "%s%s/stat", m_storeSettings.GetUsersDir().c_str(), login.c_str());
 if (Touch(fileName))
     {
 strprintf(&fileName, "%s%s/stat", m_storeSettings.GetUsersDir().c_str(), login.c_str());
 if (Touch(fileName))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file \"" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
     m_errorStr = "Cannot create file \"" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
@@ -568,7 +563,7 @@ if (access(dirName.c_str(), F_OK) != 0)
     {
     if (mkdir(dirName.c_str(), 0700) != 0)
         {
     {
     if (mkdir(dirName.c_str(), 0700) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Directory '" + dirName + "' cannot be created.";
         printfd(__FILE__, "FILES_STORE::DelUser - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
         m_errorStr = "Directory '" + dirName + "' cannot be created.";
         printfd(__FILE__, "FILES_STORE::DelUser - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
@@ -581,7 +576,7 @@ if (access(dirName.c_str(), F_OK) == 0)
     strprintf(&dirName1, "%s/%s", m_storeSettings.GetUsersDir().c_str(), login.c_str());
     if (rename(dirName1.c_str(), dirName.c_str()))
         {
     strprintf(&dirName1, "%s/%s", m_storeSettings.GetUsersDir().c_str(), login.c_str());
     if (rename(dirName1.c_str(), dirName.c_str()))
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Error moving dir from " + dirName1 + " to " + dirName;
         printfd(__FILE__, "FILES_STORE::DelUser - rename failed. Message: '%s'\n", strerror(errno));
         return -1;
         m_errorStr = "Error moving dir from " + dirName1 + " to " + dirName;
         printfd(__FILE__, "FILES_STORE::DelUser - rename failed. Message: '%s'\n", strerror(errno));
         return -1;
@@ -620,7 +615,7 @@ int e = cf.Error();
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - conf read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' data not read.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - conf read failed for user '%s'\n", login.c_str());
     return -1;
@@ -628,14 +623,14 @@ if (e)
 
 if (cf.ReadString("Password", &conf->password, "") < 0)
     {
 
 if (cf.ReadString("Password", &conf->password, "") < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter Password.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - password read failed for user '%s'\n", login.c_str());
     return -1;
     }
 if (conf->password.empty())
     {
     m_errorStr = "User \'" + login + "\' data not read. Parameter Password.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - password read failed for user '%s'\n", login.c_str());
     return -1;
     }
 if (conf->password.empty())
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' password is blank.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - password is blank for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' password is blank.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - password is blank for user '%s'\n", login.c_str());
     return -1;
@@ -643,14 +638,14 @@ if (conf->password.empty())
 
 if (cf.ReadString("tariff", &conf->tariffName, "") < 0)
     {
 
 if (cf.ReadString("tariff", &conf->tariffName, "") < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter Tariff.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff read failed for user '%s'\n", login.c_str());
     return -1;
     }
 if (conf->tariffName.empty())
     {
     m_errorStr = "User \'" + login + "\' data not read. Parameter Tariff.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff read failed for user '%s'\n", login.c_str());
     return -1;
     }
 if (conf->tariffName.empty())
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' tariff is blank.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff is blank for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' tariff is blank.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - tariff is blank for user '%s'\n", login.c_str());
     return -1;
@@ -664,7 +659,7 @@ try
     }
 catch (const std::string & s)
     {
     }
 catch (const std::string & s)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s;
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - ip read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s;
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - ip read failed for user '%s'\n", login.c_str());
     return -1;
@@ -672,7 +667,7 @@ catch (const std::string & s)
 
 if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0)
     {
 
 if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter AlwaysOnline.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - alwaysonline read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' data not read. Parameter AlwaysOnline.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - alwaysonline read failed for user '%s'\n", login.c_str());
     return -1;
@@ -680,7 +675,7 @@ if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0)
 
 if (cf.ReadInt("down", &conf->disabled, 0) != 0)
     {
 
 if (cf.ReadInt("down", &conf->disabled, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter Down.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - down read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' data not read. Parameter Down.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - down read failed for user '%s'\n", login.c_str());
     return -1;
@@ -688,7 +683,7 @@ if (cf.ReadInt("down", &conf->disabled, 0) != 0)
 
 if (cf.ReadInt("passive", &conf->passive, 0) != 0)
     {
 
 if (cf.ReadInt("passive", &conf->passive, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter Passive.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - passive read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' data not read. Parameter Passive.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - passive read failed for user '%s'\n", login.c_str());
     return -1;
@@ -713,7 +708,7 @@ for (int i = 0; i < USERDATA_NUM; i++)
 
 if (cf.ReadDouble("Credit", &conf->credit, 0) != 0)
     {
 
 if (cf.ReadDouble("Credit", &conf->credit, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' data not read. Parameter Credit.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - credit read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' data not read. Parameter Credit.";
     printfd(__FILE__, "FILES_STORE::RestoreUserConf - credit read failed for user '%s'\n", login.c_str());
     return -1;
@@ -746,7 +741,7 @@ int e = cf.Error();
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "User \'" + login + "\' stat not read. Cannot open file " + fileName + ".";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - stat read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "User \'" + login + "\' stat not read. Cannot open file " + fileName + ".";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - stat read failed for user '%s'\n", login.c_str());
     return -1;
@@ -760,7 +755,7 @@ for (int i = 0; i < DIR_NUM; i++)
     snprintf(s, 22, "D%d", i);
     if (cf.ReadULongLongInt(s, &traff, 0) != 0)
         {
     snprintf(s, 22, "D%d", i);
     if (cf.ReadULongLongInt(s, &traff, 0) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
         printfd(__FILE__, "FILES_STORE::RestoreUserStat - download stat read failed for user '%s'\n", login.c_str());
         return -1;
         m_errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s);
         printfd(__FILE__, "FILES_STORE::RestoreUserStat - download stat read failed for user '%s'\n", login.c_str());
         return -1;
@@ -770,7 +765,7 @@ for (int i = 0; i < DIR_NUM; i++)
     snprintf(s, 22, "U%d", i);
     if (cf.ReadULongLongInt(s, &traff, 0) != 0)
         {
     snprintf(s, 22, "U%d", i);
     if (cf.ReadULongLongInt(s, &traff, 0) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr =   "User \'" + login + "\' stat not read. Parameter " + std::string(s);
         printfd(__FILE__, "FILES_STORE::RestoreUserStat - upload stat read failed for user '%s'\n", login.c_str());
         return -1;
         m_errorStr =   "User \'" + login + "\' stat not read. Parameter " + std::string(s);
         printfd(__FILE__, "FILES_STORE::RestoreUserStat - upload stat read failed for user '%s'\n", login.c_str());
         return -1;
@@ -780,7 +775,7 @@ for (int i = 0; i < DIR_NUM; i++)
 
 if (cf.ReadDouble("Cash", &stat->cash, 0) != 0)
     {
 
 if (cf.ReadDouble("Cash", &stat->cash, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter Cash";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - cash read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter Cash";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - cash read failed for user '%s'\n", login.c_str());
     return -1;
@@ -788,7 +783,7 @@ if (cf.ReadDouble("Cash", &stat->cash, 0) != 0)
 
 if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0)
     {
 
 if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter FreeMb";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - freemb read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter FreeMb";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - freemb read failed for user '%s'\n", login.c_str());
     return -1;
@@ -796,7 +791,7 @@ if (cf.ReadDouble("FreeMb", &stat->freeMb, 0) != 0)
 
 if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0)
     {
 
 if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter LastCashAddTime";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashaddtime read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter LastCashAddTime";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashaddtime read failed for user '%s'\n", login.c_str());
     return -1;
@@ -804,7 +799,7 @@ if (cf.ReadTime("LastCashAddTime", &stat->lastCashAddTime, 0) != 0)
 
 if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0)
     {
 
 if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter PassiveTime";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - passivetime read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter PassiveTime";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - passivetime read failed for user '%s'\n", login.c_str());
     return -1;
@@ -812,7 +807,7 @@ if (cf.ReadTime("PassiveTime", &stat->passiveTime, 0) != 0)
 
 if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0)
     {
 
 if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter LastCashAdd";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashadd read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter LastCashAdd";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastcashadd read failed for user '%s'\n", login.c_str());
     return -1;
@@ -820,7 +815,7 @@ if (cf.ReadDouble("LastCashAdd", &stat->lastCashAdd, 0) != 0)
 
 if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0)
     {
 
 if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter LastActivityTime";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastactivitytime read failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr =   "User \'" + login + "\' stat not read. Parameter LastActivityTime";
     printfd(__FILE__, "FILES_STORE::RestoreUserStat - lastactivitytime read failed for user '%s'\n", login.c_str());
     return -1;
@@ -840,7 +835,7 @@ int e = cfstat.Error();
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = std::string("User \'") + login + "\' conf not written\n";
     printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = std::string("User \'") + login + "\' conf not written\n";
     printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str());
     return -1;
@@ -851,7 +846,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetConfUID(), m_storeSettings.GetCo
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -896,7 +891,7 @@ fileName = m_storeSettings.GetUsersDir() + "/" + login + "/stat";
 
     if (e)
         {
 
     if (e)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = std::string("User \'") + login + "\' stat not written\n";
         printfd(__FILE__, "FILES_STORE::SaveUserStat - stat write failed for user '%s'\n", login.c_str());
         return -1;
         m_errorStr = std::string("User \'") + login + "\' stat not written\n";
         printfd(__FILE__, "FILES_STORE::SaveUserStat - stat write failed for user '%s'\n", login.c_str());
         return -1;
@@ -924,7 +919,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetStatUID(), m_storeSettings.GetSt
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -949,7 +944,7 @@ if (f)
     }
 else
     {
     }
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot open \'" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "Cannot open \'" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
     return -1;
@@ -960,7 +955,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetLogUID(), m_storeSettings.GetLog
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -985,7 +980,7 @@ if (f)
     }
 else
     {
     }
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot open \'" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "Cannot open \'" + fileName + "\'";
     printfd(__FILE__, "FILES_STORE::WriteLogString - log write failed for user '%s'\n", login.c_str());
     return -1;
@@ -996,7 +991,7 @@ e += chown(fileName.c_str(), m_storeSettings.GetLogUID(), m_storeSettings.GetLog
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::WriteLogString - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -1073,7 +1068,7 @@ CONFIGFILE s(stat1, true);
 
 if (s.Error())
     {
 
 if (s.Error())
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file '" + stat1 + "'";
     printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "Cannot create file '" + stat1 + "'";
     printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
     return -1;
@@ -1088,7 +1083,7 @@ CONFIGFILE s2(stat2, true);
 
 if (s2.Error())
     {
 
 if (s2.Error())
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file '" + stat2 + "'";
     printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
     return -1;
     m_errorStr = "Cannot create file '" + stat2 + "'";
     printfd(__FILE__, "FILES_STORE::SaveMonthStat - month stat write failed for user '%s'\n", login.c_str());
     return -1;
@@ -1126,7 +1121,7 @@ strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.
 
 if (Touch(fileName))
     {
 
 if (Touch(fileName))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file " + fileName;
     printfd(__FILE__, "FILES_STORE::AddAdmin - failed to add admin '%s'\n", login.c_str());
     return -1;
     m_errorStr = "Cannot create file " + fileName;
     printfd(__FILE__, "FILES_STORE::AddAdmin - failed to add admin '%s'\n", login.c_str());
     return -1;
@@ -1141,7 +1136,7 @@ std::string fileName;
 strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.c_str());
 if (unlink(fileName.c_str()))
     {
 strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), login.c_str());
 if (unlink(fileName.c_str()))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "unlink failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
     m_errorStr = "unlink failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
@@ -1163,7 +1158,7 @@ strprintf(&fileName, "%s/%s.adm", m_storeSettings.GetAdminsDir().c_str(), ac.log
 
     if (e)
         {
 
     if (e)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot write admin " + ac.login + ". " + fileName;
         printfd(__FILE__, "FILES_STORE::SaveAdmin - failed to save admin '%s'\n", ac.login.c_str());
         return -1;
         m_errorStr = "Cannot write admin " + ac.login + ". " + fileName;
         printfd(__FILE__, "FILES_STORE::SaveAdmin - failed to save admin '%s'\n", ac.login.c_str());
         return -1;
@@ -1219,7 +1214,7 @@ std::string p;
 
 if (cf.Error())
     {
 
 if (cf.Error())
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot open " + fileName;
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - failed to restore admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Cannot open " + fileName;
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - failed to restore admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1227,7 +1222,7 @@ if (cf.Error())
 
 if (cf.ReadString("password", &p, "*"))
     {
 
 if (cf.ReadString("password", &p, "*"))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter password";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - password read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter password";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - password read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1261,7 +1256,7 @@ if (cf.ReadUShortInt("ChgConf", &a, 0) == 0)
     ac->priv.userConf = a;
 else
     {
     ac->priv.userConf = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter ChgConf";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgconf read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter ChgConf";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgconf read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1271,7 +1266,7 @@ if (cf.ReadUShortInt("ChgPassword", &a, 0) == 0)
     ac->priv.userPasswd = a;
 else
     {
     ac->priv.userPasswd = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter ChgPassword";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgpassword read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter ChgPassword";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgpassword read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1281,7 +1276,7 @@ if (cf.ReadUShortInt("ChgStat", &a, 0) == 0)
     ac->priv.userStat = a;
 else
     {
     ac->priv.userStat = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter ChgStat";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgstat read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter ChgStat";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgstat read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1291,7 +1286,7 @@ if (cf.ReadUShortInt("ChgCash", &a, 0) == 0)
     ac->priv.userCash = a;
 else
     {
     ac->priv.userCash = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter ChgCash";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgcash read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter ChgCash";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgcash read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1301,7 +1296,7 @@ if (cf.ReadUShortInt("UsrAddDel", &a, 0) == 0)
     ac->priv.userAddDel = a;
 else
     {
     ac->priv.userAddDel = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter UsrAddDel";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - usradddel read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter UsrAddDel";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - usradddel read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1311,7 +1306,7 @@ if (cf.ReadUShortInt("ChgAdmin", &a, 0) == 0)
     ac->priv.adminChg = a;
 else
     {
     ac->priv.adminChg = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter ChgAdmin";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgadmin read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter ChgAdmin";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgadmin read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1321,7 +1316,7 @@ if (cf.ReadUShortInt("ChgTariff", &a, 0) == 0)
     ac->priv.tariffChg = a;
 else
     {
     ac->priv.tariffChg = a;
 else
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter ChgTariff";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgtariff read failed for admin '%s'\n", ac->login.c_str());
     return -1;
     m_errorStr = "Error in parameter ChgTariff";
     printfd(__FILE__, "FILES_STORE::RestoreAdmin - chgtariff read failed for admin '%s'\n", ac->login.c_str());
     return -1;
@@ -1346,7 +1341,7 @@ std::string fileName;
 strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
 if (Touch(fileName))
     {
 strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
 if (Touch(fileName))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file " + fileName;
     printfd(__FILE__, "FILES_STORE::AddTariff - failed to add tariff '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Cannot create file " + fileName;
     printfd(__FILE__, "FILES_STORE::AddTariff - failed to add tariff '%s'\n", name.c_str());
     return -1;
@@ -1360,7 +1355,7 @@ std::string fileName;
 strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
 if (unlink(fileName.c_str()))
     {
 strprintf(&fileName, "%s/%s.tf", m_storeSettings.GetTariffsDir().c_str(), name.c_str());
 if (unlink(fileName.c_str()))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "unlink failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
     m_errorStr = "unlink failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
@@ -1378,7 +1373,7 @@ td->tariffConf.name = tariffName;
 
 if (conf.Error() != 0)
     {
 
 if (conf.Error() != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot read file " + fileName;
     printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to read tariff '%s'\n", tariffName.c_str());
     return -1;
     m_errorStr = "Cannot read file " + fileName;
     printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to read tariff '%s'\n", tariffName.c_str());
     return -1;
@@ -1390,7 +1385,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "Time%d", i);
     if (conf.ReadString(param, &str, "00:00-00:00") < 0)
         {
     strprintf(&param, "Time%d", i);
     if (conf.ReadString(param, &str, "00:00-00:00") < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - time%d read failed for tariff '%s'\n", i, tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - time%d read failed for tariff '%s'\n", i, tariffName.c_str());
         return -1;
@@ -1405,7 +1400,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "PriceDayA%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceDayA, 0.0) < 0)
         {
     strprintf(&param, "PriceDayA%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceDayA, 0.0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedaya read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedaya read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1415,7 +1410,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "PriceDayB%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceDayB, 0.0) < 0)
         {
     strprintf(&param, "PriceDayB%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceDayB, 0.0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedayb read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricedayb read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1425,7 +1420,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "PriceNightA%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceNightA, 0.0) < 0)
         {
     strprintf(&param, "PriceNightA%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceNightA, 0.0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenighta read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenighta read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1435,7 +1430,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "PriceNightB%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceNightB, 0.0) < 0)
         {
     strprintf(&param, "PriceNightB%d", i);
     if (conf.ReadDouble(param, &td->dirPrice[i].priceNightB, 0.0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenightb read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - pricenightb read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1445,7 +1440,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "Threshold%d", i);
     if (conf.ReadInt(param, &td->dirPrice[i].threshold, 0) < 0)
         {
     strprintf(&param, "Threshold%d", i);
     if (conf.ReadInt(param, &td->dirPrice[i].threshold, 0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - threshold read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - threshold read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1454,7 +1449,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "SinglePrice%d", i);
     if (conf.ReadInt(param, &td->dirPrice[i].singlePrice, 0) < 0)
         {
     strprintf(&param, "SinglePrice%d", i);
     if (conf.ReadInt(param, &td->dirPrice[i].singlePrice, 0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - singleprice read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - singleprice read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1463,7 +1458,7 @@ for (int i = 0; i<DIR_NUM; i++)
     strprintf(&param, "NoDiscount%d", i);
     if (conf.ReadInt(param, &td->dirPrice[i].noDiscount, 0) < 0)
         {
     strprintf(&param, "NoDiscount%d", i);
     if (conf.ReadInt(param, &td->dirPrice[i].noDiscount, 0) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - nodiscount read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
         m_errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - nodiscount read failed for tariff '%s'\n", tariffName.c_str());
         return -1;
@@ -1472,7 +1467,7 @@ for (int i = 0; i<DIR_NUM; i++)
 
 if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0)
     {
 
 if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Fee";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - fee read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Fee";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - fee read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
@@ -1480,7 +1475,7 @@ if (conf.ReadDouble("Fee", &td->tariffConf.fee, 0) < 0)
 
 if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0)
     {
 
 if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Free";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - free read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter Free";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - free read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
@@ -1488,7 +1483,7 @@ if (conf.ReadDouble("Free", &td->tariffConf.free, 0) < 0)
 
 if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0)
     {
 
 if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter PassiveCost";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - passivecost read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter PassiveCost";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - passivecost read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
@@ -1496,7 +1491,7 @@ if (conf.ReadDouble("PassiveCost", &td->tariffConf.passiveCost, 0) < 0)
 
 if (conf.ReadString("TraffType", &str, "") < 0)
     {
 
 if (conf.ReadString("TraffType", &str, "") < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - trafftype read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
     m_errorStr = "Cannot read tariff " + tariffName + ". Parameter TraffType";
     printfd(__FILE__, "FILES_STORE::RestoreTariff - trafftype read failed for tariff '%s'\n", tariffName.c_str());
     return -1;
@@ -1529,7 +1524,7 @@ std::string fileName = m_storeSettings.GetTariffsDir() + "/" + tariffName + ".tf
 
     if (e)
         {
 
     if (e)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Error writing tariff " + tariffName;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to save tariff '%s'\n", tariffName.c_str());
         return e;
         m_errorStr = "Error writing tariff " + tariffName;
         printfd(__FILE__, "FILES_STORE::RestoreTariff - failed to save tariff '%s'\n", tariffName.c_str());
         return e;
@@ -1590,7 +1585,7 @@ strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), nam
 
 if (Touch(fileName))
     {
 
 if (Touch(fileName))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot create file " + fileName;
     printfd(__FILE__, "FILES_STORE::AddService - failed to add service '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Cannot create file " + fileName;
     printfd(__FILE__, "FILES_STORE::AddService - failed to add service '%s'\n", name.c_str());
     return -1;
@@ -1605,7 +1600,7 @@ std::string fileName;
 strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), name.c_str());
 if (unlink(fileName.c_str()))
     {
 strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), name.c_str());
 if (unlink(fileName.c_str()))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "unlink failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
     m_errorStr = "unlink failed. Message: '";
     m_errorStr += strerror(errno);
     m_errorStr += "'";
@@ -1627,7 +1622,7 @@ strprintf(&fileName, "%s/%s.serv", m_storeSettings.GetServicesDir().c_str(), con
 
     if (e)
         {
 
     if (e)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot write service " + conf.name + ". " + fileName;
         printfd(__FILE__, "FILES_STORE::SaveService - failed to save service '%s'\n", conf.name.c_str());
         return -1;
         m_errorStr = "Cannot write service " + conf.name + ". " + fileName;
         printfd(__FILE__, "FILES_STORE::SaveService - failed to save service '%s'\n", conf.name.c_str());
         return -1;
@@ -1650,7 +1645,7 @@ CONFIGFILE cf(fileName);
 
 if (cf.Error())
     {
 
 if (cf.Error())
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Cannot open " + fileName;
     printfd(__FILE__, "FILES_STORE::RestoreService - failed to restore service '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Cannot open " + fileName;
     printfd(__FILE__, "FILES_STORE::RestoreService - failed to restore service '%s'\n", name.c_str());
     return -1;
@@ -1658,7 +1653,7 @@ if (cf.Error())
 
 if (cf.ReadString("name", &conf->name, name))
     {
 
 if (cf.ReadString("name", &conf->name, name))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter 'name'";
     printfd(__FILE__, "FILES_STORE::RestoreService - name read failed for service '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Error in parameter 'name'";
     printfd(__FILE__, "FILES_STORE::RestoreService - name read failed for service '%s'\n", name.c_str());
     return -1;
@@ -1666,7 +1661,7 @@ if (cf.ReadString("name", &conf->name, name))
 
 if (cf.ReadString("comment", &conf->comment, ""))
     {
 
 if (cf.ReadString("comment", &conf->comment, ""))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter 'comment'";
     printfd(__FILE__, "FILES_STORE::RestoreService - comment read failed for service '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Error in parameter 'comment'";
     printfd(__FILE__, "FILES_STORE::RestoreService - comment read failed for service '%s'\n", name.c_str());
     return -1;
@@ -1674,7 +1669,7 @@ if (cf.ReadString("comment", &conf->comment, ""))
 
 if (cf.ReadDouble("cost", &conf->cost, 0.0))
     {
 
 if (cf.ReadDouble("cost", &conf->cost, 0.0))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter 'cost'";
     printfd(__FILE__, "FILES_STORE::RestoreService - cost read failed for service '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Error in parameter 'cost'";
     printfd(__FILE__, "FILES_STORE::RestoreService - cost read failed for service '%s'\n", name.c_str());
     return -1;
@@ -1683,7 +1678,7 @@ if (cf.ReadDouble("cost", &conf->cost, 0.0))
 unsigned short value = 0;
 if (cf.ReadUShortInt("pay_day", &value, 0))
     {
 unsigned short value = 0;
 if (cf.ReadUShortInt("pay_day", &value, 0))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error in parameter 'pay_day'";
     printfd(__FILE__, "FILES_STORE::RestoreService - pay day read failed for service '%s'\n", name.c_str());
     return -1;
     m_errorStr = "Error in parameter 'pay_day'";
     printfd(__FILE__, "FILES_STORE::RestoreService - pay day read failed for service '%s'\n", name.c_str());
     return -1;
@@ -1710,7 +1705,7 @@ if (access(dn, F_OK) != 0)
     {
     if (mkdir(dn, 0700) != 0)
         {
     {
     if (mkdir(dn, 0700) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
         printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
         m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
         printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
@@ -1722,7 +1717,7 @@ e += chmod(dn, m_storeSettings.GetStatModeDir());
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -1743,7 +1738,7 @@ if (access(dn, F_OK) != 0)
     {
     if (mkdir(dn, 0700) != 0)
         {
     {
     if (mkdir(dn, 0700) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
         printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
         m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
         printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
@@ -1755,7 +1750,7 @@ e += chmod(dn, m_storeSettings.GetStatModeDir());
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -1769,7 +1764,7 @@ if (access(dn, F_OK) != 0)
     {
     if (mkdir(dn, 0700) != 0)
         {
     {
     if (mkdir(dn, 0700) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
         printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
         m_errorStr = "Directory \'" + std::string(dn) + "\' cannot be created.";
         printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno));
         return -1;
@@ -1781,7 +1776,7 @@ e += chmod(dn, m_storeSettings.GetStatModeDir());
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -1791,7 +1786,7 @@ statFile = fopen (fn, "at");
 
 if (!statFile)
     {
 
 if (!statFile)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "File \'" + std::string(fn) + "\' cannot be written.";
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
     m_errorStr = "File \'" + std::string(fn) + "\' cannot be written.";
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
@@ -1818,7 +1813,7 @@ s2 = lt2->tm_sec;
 if (fprintf(statFile, "-> %02d.%02d.%02d - %02d.%02d.%02d\n",
             h1, m1, s1, h2, m2, s2) < 0)
     {
 if (fprintf(statFile, "-> %02d.%02d.%02d - %02d.%02d.%02d\n",
             h1, m1, s1, h2, m2, s2) < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'";
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno));
     fclose(statFile);
     m_errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'";
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno));
     fclose(statFile);
@@ -1840,7 +1835,7 @@ while (stIter != statTree.end())
                 u.c_str(),
                 stIter->second.cash) < 0)
         {
                 u.c_str(),
                 stIter->second.cash) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "fprint failed. Message: '";
         m_errorStr += strerror(errno);
         m_errorStr += "'";
         m_errorStr = "fprint failed. Message: '";
         m_errorStr += strerror(errno);
         m_errorStr += "'";
@@ -1856,7 +1851,7 @@ while (stIter != statTree.end())
                 u.c_str(),
                 stIter->second.cash) < 0)
         {
                 u.c_str(),
                 stIter->second.cash) < 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = std::string("fprint failed. Message: '");
         m_errorStr += strerror(errno);
         m_errorStr += "'";
         m_errorStr = std::string("fprint failed. Message: '");
         m_errorStr += strerror(errno);
         m_errorStr += "'";
@@ -1876,7 +1871,7 @@ e += chmod(fn, m_storeSettings.GetStatMode());
 
 if (e)
     {
 
 if (e)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
     printfd(__FILE__, "FILES_STORE::WriteDetailStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
     }
 
@@ -1894,7 +1889,7 @@ if (access(dn.c_str(), F_OK) != 0)
     {
     if (mkdir(dn.c_str(), 0700) != 0)
         {
     {
     if (mkdir(dn.c_str(), 0700) != 0)
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Directory \'";
         m_errorStr += dn;
         m_errorStr += "\' cannot be created.";
         m_errorStr = "Directory \'";
         m_errorStr += dn;
         m_errorStr += "\' cannot be created.";
@@ -1912,7 +1907,7 @@ strprintf(&fn, "%s/%lld", dn.c_str(), msg->header.id);
 
 if (Touch(fn))
     {
 
 if (Touch(fn))
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "File \'";
     m_errorStr += fn;
     m_errorStr += "\' cannot be writen.";
     m_errorStr = "File \'";
     m_errorStr += fn;
     m_errorStr += "\' cannot be writen.";
@@ -1932,7 +1927,7 @@ strprintf(&fileName, "%s/%s/messages/%lld", m_storeSettings.GetUsersDir().c_str(
 
 if (access(fileName.c_str(), F_OK) != 0)
     {
 
 if (access(fileName.c_str(), F_OK) != 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Message for user \'";
     m_errorStr += login + "\' with ID \'";
     m_errorStr += std::to_string(msg.header.id) + "\' does not exist.";
     m_errorStr = "Message for user \'";
     m_errorStr += login + "\' with ID \'";
     m_errorStr += std::to_string(msg.header.id) + "\' does not exist.";
@@ -1945,7 +1940,7 @@ Touch(fileName + ".new");
 msgFile = fopen((fileName + ".new").c_str(), "wt");
 if (!msgFile)
     {
 msgFile = fopen((fileName + ".new").c_str(), "wt");
 if (!msgFile)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "File \'" + fileName + "\' cannot be writen.";
     printfd(__FILE__, "FILES_STORE::EditMessage - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
     m_errorStr = "File \'" + fileName + "\' cannot be writen.";
     printfd(__FILE__, "FILES_STORE::EditMessage - fopen failed. Message: '%s'\n", strerror(errno));
     return -1;
@@ -1962,7 +1957,7 @@ res &= (fprintf(msgFile, "%s", msg.text.c_str()) >= 0);
 
 if (!res)
     {
 
 if (!res)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'";
     printfd(__FILE__, "FILES_STORE::EditMessage - fprintf failed. Message: '%s'\n", strerror(errno));
     fclose(msgFile);
     m_errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'";
     printfd(__FILE__, "FILES_STORE::EditMessage - fprintf failed. Message: '%s'\n", strerror(errno));
     fclose(msgFile);
@@ -1975,7 +1970,7 @@ chmod((fileName + ".new").c_str(), m_storeSettings.GetConfMode());
 
 if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
     {
 
 if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
     printfd(__FILE__, "FILES_STORE::EditMessage - rename failed. Message: '%s'\n", strerror(errno));
     return -1;
     m_errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
     printfd(__FILE__, "FILES_STORE::EditMessage - rename failed. Message: '%s'\n", strerror(errno));
     return -1;
@@ -2020,7 +2015,7 @@ for (unsigned i = 0; i < messages.size(); i++)
         {
         if (unlink((dn + messages[i]).c_str()))
             {
         {
         if (unlink((dn + messages[i]).c_str()))
             {
-            STG_LOCKER lock(&m_mutex);
+            std::lock_guard lock(m_mutex);
             m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
             printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
             return -1;
             m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
             printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
             return -1;
@@ -2038,7 +2033,7 @@ for (unsigned i = 0; i < messages.size(); i++)
         {
         if (unlink((dn + messages[i]).c_str()))
             {
         {
         if (unlink((dn + messages[i]).c_str()))
             {
-            STG_LOCKER lock(&m_mutex);
+            std::lock_guard lock(m_mutex);
             m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
             printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
             return -1;
             m_errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'";
             printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno));
             return -1;
@@ -2060,7 +2055,7 @@ FILE * msgFile;
 msgFile = fopen(fileName.c_str(), "rt");
 if (!msgFile)
     {
 msgFile = fopen(fileName.c_str(), "rt");
 if (!msgFile)
     {
-    STG_LOCKER lock(&m_mutex);
+    std::lock_guard lock(m_mutex);
     m_errorStr = "File \'";
     m_errorStr += fileName;
     m_errorStr += "\' cannot be openned.";
     m_errorStr = "File \'";
     m_errorStr += fileName;
     m_errorStr += "\' cannot be openned.";
@@ -2081,7 +2076,7 @@ memset(p, 0, sizeof(p));
 for (int pos = 0; pos < 6; pos++)
     {
     if (fgets(p, sizeof(p) - 1, msgFile) == NULL) {
 for (int pos = 0; pos < 6; pos++)
     {
     if (fgets(p, sizeof(p) - 1, msgFile) == NULL) {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read file \'";
         m_errorStr += fileName;
         m_errorStr += "\'. Missing data.";
         m_errorStr = "Cannot read file \'";
         m_errorStr += fileName;
         m_errorStr += "\'. Missing data.";
@@ -2099,7 +2094,7 @@ for (int pos = 0; pos < 6; pos++)
 
     if (feof(msgFile))
         {
 
     if (feof(msgFile))
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read file \'";
         m_errorStr += fileName;
         m_errorStr += "\'. Missing data.";
         m_errorStr = "Cannot read file \'";
         m_errorStr += fileName;
         m_errorStr += "\'. Missing data.";
@@ -2111,7 +2106,7 @@ for (int pos = 0; pos < 6; pos++)
 
     if (str2x(p, *(d[pos])))
         {
 
     if (str2x(p, *(d[pos])))
         {
-        STG_LOCKER lock(&m_mutex);
+        std::lock_guard lock(m_mutex);
         m_errorStr = "Cannot read file \'";
         m_errorStr += fileName;
         m_errorStr += "\'. Incorrect value. \'";
         m_errorStr = "Cannot read file \'";
         m_errorStr += fileName;
         m_errorStr += "\'. Incorrect value. \'";
index dbb8ab61fdc371bd70f7a0765acaed780ed5f986..3153665b033172bf91338163968bbd1f66f51497 100644 (file)
@@ -27,9 +27,9 @@
 #include "stg/logger.h"
 
 #include <string>
 #include "stg/logger.h"
 
 #include <string>
+#include <mutex>
 
 #include <sys/types.h>
 
 #include <sys/types.h>
-#include <pthread.h>
 
 //-----------------------------------------------------------------------------
 class FILES_STORE_SETTINGS
 
 //-----------------------------------------------------------------------------
 class FILES_STORE_SETTINGS
@@ -201,7 +201,7 @@ class FILES_STORE: public STG::Store
         std::string m_version;
         FILES_STORE_SETTINGS m_storeSettings;
         STG::ModuleSettings m_settings;
         std::string m_version;
         FILES_STORE_SETTINGS m_storeSettings;
         STG::ModuleSettings m_settings;
-        mutable pthread_mutex_t m_mutex;
+        mutable std::mutex m_mutex;
 
         STG::PluginLogger m_logger;
 };
 
         STG::PluginLogger m_logger;
 };
index c11b442be93e390e37a31fafa9dc1a7eb351fd70..fc588fcc4a5ebe6edb9926ae1bfeba955de2b686 100644 (file)
@@ -52,7 +52,6 @@ FIREBIRD_STORE::FIREBIRD_STORE()
       schemaVersion(0),
       logger(STG::PluginLogger::get("store_firebird"))
 {
       schemaVersion(0),
       logger(STG::PluginLogger::get("store_firebird"))
 {
-pthread_mutex_init(&mutex, NULL);
 }
 //-----------------------------------------------------------------------------
 FIREBIRD_STORE::~FIREBIRD_STORE()
 }
 //-----------------------------------------------------------------------------
 FIREBIRD_STORE::~FIREBIRD_STORE()
index 4e3dfb6849221e9a06f3944eb790c5f39225784d..a34b758f0e28591aec1d23fcc96cc87e53163758 100644 (file)
@@ -21,7 +21,6 @@
 #pragma once
 
 #include "stg/store.h"
 #pragma once
 
 #include "stg/store.h"
-#include "stg/locker.h"
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wold-style-cast"
 #include "stg/ibpp.h"
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wold-style-cast"
 #include "stg/ibpp.h"
@@ -32,6 +31,7 @@
 #include <ctime>
 #include <string>
 #include <vector>
 #include <ctime>
 #include <string>
 #include <vector>
+#include <mutex>
 
 class FIREBIRD_STORE : public STG::Store
 {
 
 class FIREBIRD_STORE : public STG::Store
 {
@@ -114,7 +114,7 @@ class FIREBIRD_STORE : public STG::Store
         std::string db_server, db_database, db_user, db_password;
         STG::ModuleSettings settings;
         mutable IBPP::Database db;
         std::string db_server, db_database, db_user, db_password;
         STG::ModuleSettings settings;
         mutable IBPP::Database db;
-        mutable pthread_mutex_t mutex;
+        mutable std::mutex m_mutex;
         IBPP::TIL til;
         IBPP::TLR tlr;
         int schemaVersion;
         IBPP::TIL til;
         IBPP::TLR tlr;
         int schemaVersion;
index 87d633440b0bb89be14d8d7e1a449efb71cd0c7e..fd00a7e91064704714baa2794cf9e749638823d1 100644 (file)
@@ -40,7 +40,7 @@
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetAdminsList(std::vector<std::string> * adminsList) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetAdminsList(std::vector<std::string> * adminsList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -71,7 +71,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveAdmin(const STG::AdminConf & ac) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveAdmin(const STG::AdminConf & ac) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -129,7 +129,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -192,7 +192,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddAdmin(const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddAdmin(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -230,7 +230,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelAdmin(const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelAdmin(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
index 0d088759dca26b0f28aa255c9cce8e379943bdc9..4e9cac4d6cd56c01a440c77731a23e44cd3b8383 100644 (file)
@@ -35,7 +35,7 @@
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetCorpsList(std::vector<std::string> * corpsList) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetCorpsList(std::vector<std::string> * corpsList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -66,7 +66,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveCorp(const STG::CorpConf & cc) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveCorp(const STG::CorpConf & cc) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -94,7 +94,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -132,7 +132,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddCorp(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddCorp(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -159,7 +159,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelCorp(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelCorp(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
index 90c3e573b9ef666d04220c50cd711e52206cda2d..d2c4a3eebb8db5409746db85ce22da8cac7b73b2 100644 (file)
@@ -36,7 +36,7 @@
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddMessage(STG::Message * msg, const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddMessage(STG::Message * msg, const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -73,7 +73,7 @@ return 0;
 int FIREBIRD_STORE::EditMessage(const STG::Message & msg,
                                 const std::string & login) const
 {
 int FIREBIRD_STORE::EditMessage(const STG::Message & msg,
                                 const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -111,7 +111,7 @@ int FIREBIRD_STORE::GetMessage(uint64_t id,
                                STG::Message * msg,
                                const std::string &) const
 {
                                STG::Message * msg,
                                const std::string &) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -157,7 +157,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelMessage(uint64_t id, const std::string &) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelMessage(uint64_t id, const std::string &) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -185,7 +185,7 @@ return 0;
 int FIREBIRD_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList,
                                    const std::string & login) const
 {
 int FIREBIRD_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList,
                                    const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
index 539fcf73d31868d848705cdc86ef92bc93aea9d5..2afe11812b5f04df0e62638d9b6eb5cd3d082881 100644 (file)
@@ -36,7 +36,7 @@
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetServicesList(std::vector<std::string> * servicesList) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetServicesList(std::vector<std::string> * servicesList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -67,7 +67,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveService(const STG::ServiceConf & sc) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveService(const STG::ServiceConf & sc) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -102,7 +102,7 @@ return 0;
 int FIREBIRD_STORE::RestoreService(STG::ServiceConf * sc,
                                    const std::string & name) const
 {
 int FIREBIRD_STORE::RestoreService(STG::ServiceConf * sc,
                                    const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -144,7 +144,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddService(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -172,7 +172,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelService(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
index 58b571395cbee6c471bd322da8bd66de3df969f3..93360f219bf72f4a089c50d0b3521b8dfd3f49b1 100644 (file)
@@ -45,7 +45,7 @@ const int pt_mega = 1024 * 1024;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -76,7 +76,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddTariff(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddTariff(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -104,7 +104,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelTariff(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelTariff(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -132,7 +132,7 @@ return 0;
 int FIREBIRD_STORE::SaveTariff(const STG::TariffData & td,
                                const std::string & tariffName) const
 {
 int FIREBIRD_STORE::SaveTariff(const STG::TariffData & td,
                                const std::string & tariffName) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -267,7 +267,7 @@ return 0;
 int FIREBIRD_STORE::RestoreTariff(STG::TariffData * td,
                                   const std::string & tariffName) const
 {
 int FIREBIRD_STORE::RestoreTariff(STG::TariffData * td,
                                   const std::string & tariffName) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
index ba21aa618c0f0df9eaf09b0d5625ed2fc4955691..075f95b8c55fa3635e71bdf6665b9bf9da0faf09 100644 (file)
@@ -39,7 +39,7 @@
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetUsersList(std::vector<std::string> * usersList) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::GetUsersList(std::vector<std::string> * usersList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -70,7 +70,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddUser(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::AddUser(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -98,7 +98,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelUser(const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::DelUser(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -126,7 +126,7 @@ return 0;
 int FIREBIRD_STORE::SaveUserStat(const STG::UserStat & stat,
                                  const std::string & login) const
 {
 int FIREBIRD_STORE::SaveUserStat(const STG::UserStat & stat,
                                  const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 return SaveStat(stat, login);
 }
 
 return SaveStat(stat, login);
 }
@@ -231,7 +231,7 @@ return 0;
 int FIREBIRD_STORE::SaveUserConf(const STG::UserConf & conf,
                                  const std::string & login) const
 {
 int FIREBIRD_STORE::SaveUserConf(const STG::UserConf & conf,
                                  const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -359,7 +359,7 @@ return 0;
 int FIREBIRD_STORE::RestoreUserStat(STG::UserStat * stat,
                                     const std::string & login) const
 {
 int FIREBIRD_STORE::RestoreUserStat(STG::UserStat * stat,
                                     const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -446,7 +446,7 @@ return 0;
 int FIREBIRD_STORE::RestoreUserConf(STG::UserConf * conf,
                                     const std::string & login) const
 {
 int FIREBIRD_STORE::RestoreUserConf(STG::UserConf * conf,
                                     const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -573,7 +573,7 @@ int FIREBIRD_STORE::WriteUserChgLog(const std::string & login,
                                     const std::string & newValue,
                                     const std::string & message = "") const
 {
                                     const std::string & newValue,
                                     const std::string & message = "") const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -633,7 +633,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -670,7 +670,7 @@ int FIREBIRD_STORE::WriteUserDisconnect(const std::string & login,
                     double /*freeMb*/,
                     const std::string & /*reason*/) const
 {
                     double /*freeMb*/,
                     const std::string & /*reason*/) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -718,7 +718,7 @@ int FIREBIRD_STORE::WriteDetailedStat(const STG::TraffStat & statTree,
                                       time_t lastStat,
                                       const std::string & login) const
 {
                                       time_t lastStat,
                                       const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
@@ -768,7 +768,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int FIREBIRD_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
 
 IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
 IBPP::Statement st = IBPP::StatementFactory(db, tr);
index ba47896694ec5f61c9a7d7930614a117661524ad..e57382867d6169e00106ac7e3cc1e25315f6a683 100644 (file)
@@ -66,7 +66,6 @@ POSTGRESQL_STORE::POSTGRESQL_STORE()
       connection(NULL),
       logger(STG::PluginLogger::get("store_postgresql"))
 {
       connection(NULL),
       logger(STG::PluginLogger::get("store_postgresql"))
 {
-pthread_mutex_init(&mutex, NULL);
 }
 //-----------------------------------------------------------------------------
 POSTGRESQL_STORE::~POSTGRESQL_STORE()
 }
 //-----------------------------------------------------------------------------
 POSTGRESQL_STORE::~POSTGRESQL_STORE()
@@ -75,7 +74,6 @@ if (connection)
     {
     PQfinish(connection);
     }
     {
     PQfinish(connection);
     }
-pthread_mutex_destroy(&mutex);
 }
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::ParseSettings()
 }
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::ParseSettings()
index b4a1c5e8718779f807710749f400fae3cb58c9fd..7b2e9604656e77ed5d54b996303af10aa7e45a01 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
+#include <mutex>
 
 #include <libpq-fe.h>
 
 
 #include <libpq-fe.h>
 
@@ -148,7 +149,7 @@ class POSTGRESQL_STORE : public STG::Store
         std::string password;
         std::string clientEncoding;
         STG::ModuleSettings settings;
         std::string password;
         std::string clientEncoding;
         STG::ModuleSettings settings;
-        mutable pthread_mutex_t mutex;
+        mutable std::mutex m_mutex;
         mutable int version;
         int retries;
 
         mutable int version;
         int retries;
 
index b1c1203e6fd52831733c53a3c1c0263a88cb244f..e313b4a099863fc5a8e2fde2d2c3a254af78af51 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "postgresql_store.h"
 
 
 #include "postgresql_store.h"
 
-#include "stg/locker.h"
 #include "stg/common.h"
 #include "stg/admin_conf.h"
 #include "stg/blowfish.h"
 #include "stg/common.h"
 #include "stg/admin_conf.h"
 #include "stg/blowfish.h"
@@ -44,7 +43,7 @@
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetAdminsList(std::vector<std::string> * adminsList) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetAdminsList(std::vector<std::string> * adminsList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -100,7 +99,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveAdmin(const STG::AdminConf & ac) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveAdmin(const STG::AdminConf & ac) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -199,7 +198,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -320,7 +319,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddAdmin(const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddAdmin(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -390,7 +389,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelAdmin(const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelAdmin(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
index 1387d4184e4e9074e2334b0f0c0ea8d456766034..6c6b9985273914bc23d41f74aad5dd513e0ff4f9 100644 (file)
@@ -29,7 +29,6 @@
 #include "postgresql_store.h"
 
 #include "stg/corp_conf.h"
 #include "postgresql_store.h"
 
 #include "stg/corp_conf.h"
-#include "stg/locker.h"
 #include "stg/common.h"
 
 #include <string>
 #include "stg/common.h"
 
 #include <string>
@@ -41,7 +40,7 @@
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetCorpsList(std::vector<std::string> * corpsList) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetCorpsList(std::vector<std::string> * corpsList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -97,7 +96,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveCorp(const STG::CorpConf & cc) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveCorp(const STG::CorpConf & cc) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -163,7 +162,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::RestoreCorp(STG::CorpConf * cc, const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -246,7 +245,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddCorp(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddCorp(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -313,7 +312,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelCorp(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelCorp(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
index 905b467c000111527f9440e8a22be0ccfb18b4e9..3bc9c749a8deb0ed15cdb1582b2784a27394515a 100644 (file)
@@ -30,7 +30,6 @@
 #include "postgresql_store.h"
 
 #include "stg/common.h"
 #include "postgresql_store.h"
 
 #include "stg/common.h"
-#include "stg/locker.h"
 #include "stg/message.h"
 
 #include <string>
 #include "stg/message.h"
 
 #include <string>
@@ -42,7 +41,7 @@
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddMessage(STG::Message * msg, const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddMessage(STG::Message * msg, const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -145,7 +144,7 @@ return 0;
 int POSTGRESQL_STORE::EditMessage(const STG::Message & msg,
                                   const std::string & login) const
 {
 int POSTGRESQL_STORE::EditMessage(const STG::Message & msg,
                                   const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -231,7 +230,7 @@ int POSTGRESQL_STORE::GetMessage(uint64_t id,
                                  STG::Message * msg,
                                  const std::string &) const
 {
                                  STG::Message * msg,
                                  const std::string &) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -309,7 +308,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelMessage(uint64_t id, const std::string &) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelMessage(uint64_t id, const std::string &) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -361,7 +360,7 @@ return 0;
 int POSTGRESQL_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList,
                                    const std::string & login) const
 {
 int POSTGRESQL_STORE::GetMessageHdrs(std::vector<STG::Message::Header> * hdrsList,
                                    const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
index 3d0981613524db7c9dd7ad9a0a137612b68452b8..2b99fcee71bb5857d46ff42bc5623ec802775c79 100644 (file)
@@ -31,7 +31,6 @@
 
 #include "stg/service_conf.h"
 #include "stg/common.h"
 
 #include "stg/service_conf.h"
 #include "stg/common.h"
-#include "stg/locker.h"
 
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
@@ -42,7 +41,7 @@
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetServicesList(std::vector<std::string> * servicesList) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetServicesList(std::vector<std::string> * servicesList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -98,7 +97,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -178,7 +177,7 @@ return 0;
 int POSTGRESQL_STORE::RestoreService(STG::ServiceConf * sc,
                                      const std::string & name) const
 {
 int POSTGRESQL_STORE::RestoreService(STG::ServiceConf * sc,
                                      const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -265,7 +264,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddService(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -332,7 +331,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelService(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
index 1b68da8026167b72bcf09eacbd31cd69ccb5a58e..085675c3dc0bb41f80a7b3bc56011aad60980a40 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "stg/tariff_conf.h"
 #include "stg/common.h"
 
 #include "stg/tariff_conf.h"
 #include "stg/common.h"
-#include "stg/locker.h"
 
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
@@ -49,7 +48,7 @@ const int pt_mega = 1024 * 1024;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetTariffsList(std::vector<std::string> * tariffsList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -105,7 +104,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddTariff(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddTariff(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -168,7 +167,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelTariff(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelTariff(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -232,7 +231,7 @@ return 0;
 int POSTGRESQL_STORE::SaveTariff(const STG::TariffData & td,
                                  const std::string & tariffName) const
 {
 int POSTGRESQL_STORE::SaveTariff(const STG::TariffData & td,
                                  const std::string & tariffName) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -417,7 +416,7 @@ return 0;
 int POSTGRESQL_STORE::RestoreTariff(STG::TariffData * td,
                                     const std::string & tariffName) const
 {
 int POSTGRESQL_STORE::RestoreTariff(STG::TariffData * td,
                                     const std::string & tariffName) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
index 6919ed0002f5fb1fae8bab26b938d1fa9d95ad7c..3e5643375ffbe9ef69de5fe20f1c2a9ab152d9c1 100644 (file)
@@ -34,7 +34,6 @@
 #include "stg/user_traff.h"
 #include "stg/common.h"
 #include "stg/const.h"
 #include "stg/user_traff.h"
 #include "stg/common.h"
 #include "stg/const.h"
-#include "stg/locker.h"
 #include "../../../stg_timer.h"
 
 #include <string>
 #include "../../../stg_timer.h"
 
 #include <string>
@@ -47,7 +46,7 @@
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetUsersList(std::vector<std::string> * usersList) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::GetUsersList(std::vector<std::string> * usersList) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -103,7 +102,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddUser(const std::string & name) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddUser(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -167,7 +166,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelUser(const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelUser(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -231,7 +230,7 @@ return 0;
 int POSTGRESQL_STORE::SaveUserStat(const STG::UserStat & stat,
                                    const std::string & login) const
 {
 int POSTGRESQL_STORE::SaveUserStat(const STG::UserStat & stat,
                                    const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 return SaveStat(stat, login);
 }
 
 return SaveStat(stat, login);
 }
@@ -342,7 +341,7 @@ return 0;
 int POSTGRESQL_STORE::SaveUserConf(const STG::UserConf & conf,
                                  const std::string & login) const
 {
 int POSTGRESQL_STORE::SaveUserConf(const STG::UserConf & conf,
                                  const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -613,7 +612,7 @@ return 0;
 int POSTGRESQL_STORE::RestoreUserStat(STG::UserStat * stat,
                                     const std::string & login) const
 {
 int POSTGRESQL_STORE::RestoreUserStat(STG::UserStat * stat,
                                     const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -753,7 +752,7 @@ return 0;
 int POSTGRESQL_STORE::RestoreUserConf(STG::UserConf * conf,
                                     const std::string & login) const
 {
 int POSTGRESQL_STORE::RestoreUserConf(STG::UserConf * conf,
                                     const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -996,7 +995,7 @@ int POSTGRESQL_STORE::WriteUserChgLog(const std::string & login,
                                     const std::string & newValue,
                                     const std::string & message = "") const
 {
                                     const std::string & newValue,
                                     const std::string & message = "") const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -1113,7 +1112,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -1199,7 +1198,7 @@ int POSTGRESQL_STORE::WriteUserDisconnect(const std::string & login,
                     double freeMb,
                     const std::string & reason) const
 {
                     double freeMb,
                     const std::string & reason) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -1358,7 +1357,7 @@ int POSTGRESQL_STORE::WriteDetailedStat(const STG::TraffStat & statTree,
                                       time_t lastStat,
                                       const std::string & login) const
 {
                                       time_t lastStat,
                                       const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
@@ -1437,7 +1436,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const
 {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveMonthStat(const STG::UserStat & stat, int month, int year, const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 return SaveStat(stat, login, year, month);
 }
 
 return SaveStat(stat, login, year, month);
 }
index d6b4d6b59f5b1731cfcd82f4a68997c3817db5b2..eea5e7f13094d35034924e3b302dc4881481ab39 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "stg/services.h"
 #include "stg/service_conf.h"
 
 #include "stg/services.h"
 #include "stg/service_conf.h"
-#include "stg/locker.h"
 #include "stg/noncopyable.h"
 #include "stg/logger.h"
 
 #include "stg/noncopyable.h"
 #include "stg/logger.h"
 
index 792e53daeee3b45cbd3d71c3cab5066d408d9381..9d9ed20839c5b364b76ac0d6095a355a4e1ce46a 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "tariffs_impl.h"
 
 
 #include "tariffs_impl.h"
 
-#include "stg/locker.h"
 #include "stg/logger.h"
 #include "stg/store.h"
 #include "stg/admin.h"
 #include "stg/logger.h"
 #include "stg/store.h"
 #include "stg/admin.h"
index 6a57342807c31fd44057e66b5fb58cc3bd347f27..70ade1ae91c2ee941a569a13244ba1dcd5fac0e6 100644 (file)
@@ -40,7 +40,6 @@
 #include <cstdlib> // strtol
 
 #include "stg/common.h"
 #include <cstdlib> // strtol
 
 #include "stg/common.h"
-#include "stg/locker.h"
 #include "stg/const.h" // MONITOR_TIME_DELAY_SEC
 #include "traffcounter_impl.h"
 #include "stg_timer.h"
 #include "stg/const.h" // MONITOR_TIME_DELAY_SEC
 #include "traffcounter_impl.h"
 #include "stg_timer.h"
index 7116a11e0a97cf1e68029c16c19244e095832c71..af94d47743132751ca44c8d21d9ba5077a69561c 100644 (file)
@@ -154,11 +154,6 @@ m_afterDisabledConn = properties.disabled.afterChange([this](auto oldVal, auto n
 m_beforeTariffConn = properties.tariffName.beforeChange([this](const auto& oldVal, const auto& newVal){ onTariffChange(oldVal, newVal); });
 m_beforeCashConn = properties.cash.beforeChange([this](auto oldVal, auto newVal){ onCashChange(oldVal, newVal); });
 m_afterIPConn = ips.afterChange([this](const auto& oldVal, const auto& newVal){ onIPChange(oldVal, newVal); });
 m_beforeTariffConn = properties.tariffName.beforeChange([this](const auto& oldVal, const auto& newVal){ onTariffChange(oldVal, newVal); });
 m_beforeCashConn = properties.cash.beforeChange([this](auto oldVal, auto newVal){ onCashChange(oldVal, newVal); });
 m_afterIPConn = ips.afterChange([this](const auto& oldVal, const auto& newVal){ onIPChange(oldVal, newVal); });
-
-pthread_mutexattr_t attr;
-pthread_mutexattr_init(&attr);
-pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-pthread_mutex_init(&mutex, &attr);
 }
 //-----------------------------------------------------------------------------
 UserImpl::UserImpl(const UserImpl & u)
 }
 //-----------------------------------------------------------------------------
 UserImpl::UserImpl(const UserImpl & u)
@@ -232,21 +227,11 @@ UserImpl::UserImpl(const UserImpl & u)
     m_afterIPConn = ips.afterChange([this](const auto& oldVal, const auto& newVal){ onIPChange(oldVal, newVal); });
 
     properties.SetProperties(u.properties);
     m_afterIPConn = ips.afterChange([this](const auto& oldVal, const auto& newVal){ onIPChange(oldVal, newVal); });
 
     properties.SetProperties(u.properties);
-
-    pthread_mutexattr_t attr;
-    pthread_mutexattr_init(&attr);
-    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-    pthread_mutex_init(&mutex, &attr);
-}
-//-----------------------------------------------------------------------------
-UserImpl::~UserImpl()
-{
-pthread_mutex_destroy(&mutex);
 }
 //-----------------------------------------------------------------------------
 void UserImpl::SetLogin(const std::string & l)
 {
 }
 //-----------------------------------------------------------------------------
 void UserImpl::SetLogin(const std::string & l)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 static int idGen = 0;
 assert(login.empty() && "Login is already set");
 login = l;
 static int idGen = 0;
 assert(login.empty() && "Login is already set");
 login = l;
@@ -255,7 +240,7 @@ id = idGen++;
 //-----------------------------------------------------------------------------
 int UserImpl::ReadConf()
 {
 //-----------------------------------------------------------------------------
 int UserImpl::ReadConf()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserConf conf;
 
 if (store->RestoreUserConf(&conf, login))
 UserConf conf;
 
 if (store->RestoreUserConf(&conf, login))
@@ -303,7 +288,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int UserImpl::ReadStat()
 {
 //-----------------------------------------------------------------------------
 int UserImpl::ReadStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserStat stat;
 
 if (store->RestoreUserStat(&stat, login))
 UserStat stat;
 
 if (store->RestoreUserStat(&stat, login))
@@ -322,7 +307,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int UserImpl::WriteConf()
 {
 //-----------------------------------------------------------------------------
 int UserImpl::WriteConf()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserConf conf(properties.GetConf());
 
 printfd(__FILE__, "UserImpl::WriteConf()\n");
 UserConf conf(properties.GetConf());
 
 printfd(__FILE__, "UserImpl::WriteConf()\n");
@@ -341,7 +326,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int UserImpl::WriteStat()
 {
 //-----------------------------------------------------------------------------
 int UserImpl::WriteStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserStat stat(properties.GetStat());
 
 if (store->SaveUserStat(stat, login))
 UserStat stat(properties.GetStat());
 
 if (store->SaveUserStat(stat, login))
@@ -360,7 +345,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int UserImpl::WriteMonthStat()
 {
 //-----------------------------------------------------------------------------
 int UserImpl::WriteMonthStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 time_t tt = stgTime - 3600;
 struct tm t1;
 localtime_r(&tt, &t1);
 time_t tt = stgTime - 3600;
 struct tm t1;
 localtime_r(&tt, &t1);
@@ -380,7 +365,7 @@ return 0;
 //-----------------------------------------------------------------------------
 int UserImpl::Authorize(uint32_t ip, uint32_t dirs, const Auth * auth)
 {
 //-----------------------------------------------------------------------------
 int UserImpl::Authorize(uint32_t ip, uint32_t dirs, const Auth * auth)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 /*
  *  Authorize user. It only means that user will be authorized. Nothing more.
  *  User can be connected or disconnected while authorized.
 /*
  *  Authorize user. It only means that user will be authorized. Nothing more.
  *  User can be connected or disconnected while authorized.
@@ -458,7 +443,7 @@ return 0;
 //-----------------------------------------------------------------------------
 void UserImpl::Unauthorize(const Auth * auth, const std::string & reason)
 {
 //-----------------------------------------------------------------------------
 void UserImpl::Unauthorize(const Auth * auth, const std::string & reason)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 /*
  *  Authorizer tries to unauthorize user, that was not authorized by it
  */
 /*
  *  Authorizer tries to unauthorize user, that was not authorized by it
  */
@@ -480,14 +465,14 @@ if (authorizedBy.empty())
 //-----------------------------------------------------------------------------
 bool UserImpl::IsAuthorizedBy(const Auth * auth) const
 {
 //-----------------------------------------------------------------------------
 bool UserImpl::IsAuthorizedBy(const Auth * auth) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 // Is this user authorized by specified authorizer?
 return authorizedBy.find(auth) != authorizedBy.end();
 }
 //-----------------------------------------------------------------------------
 std::vector<std::string> UserImpl::GetAuthorizers() const
 {
 // Is this user authorized by specified authorizer?
 return authorizedBy.find(auth) != authorizedBy.end();
 }
 //-----------------------------------------------------------------------------
 std::vector<std::string> UserImpl::GetAuthorizers() const
 {
-    STG_LOCKER lock(&mutex);
+    std::lock_guard lock(m_mutex);
     std::vector<std::string> list;
     std::transform(authorizedBy.begin(), authorizedBy.end(), std::back_inserter(list), [](const auto auth){ return auth->GetVersion(); });
     return list;
     std::vector<std::string> list;
     std::transform(authorizedBy.begin(), authorizedBy.end(), std::back_inserter(list), [](const auto auth){ return auth->GetVersion(); });
     return list;
@@ -499,8 +484,6 @@ void UserImpl::Connect(bool fakeConnect)
  * Connect user to Internet. This function is differ from Authorize() !!!
  */
 
  * Connect user to Internet. This function is differ from Authorize() !!!
  */
 
-STG_LOCKER lock(&mutex);
-
 if (!fakeConnect)
     {
     std::string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect";
 if (!fakeConnect)
     {
     std::string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect";
@@ -552,8 +535,6 @@ void UserImpl::Disconnect(bool fakeDisconnect, const std::string & reason)
  *  Disconnect user from Internet. This function is differ from UnAuthorize() !!!
  */
 
  *  Disconnect user from Internet. This function is differ from UnAuthorize() !!!
  */
 
-STG_LOCKER lock(&mutex);
-
 if (!lastIPForDisconnect)
     {
     printfd(__FILE__, "lastIPForDisconnect\n");
 if (!lastIPForDisconnect)
     {
     printfd(__FILE__, "lastIPForDisconnect\n");
@@ -618,7 +599,7 @@ sessionDownloadModTime = stgTime;
 //-----------------------------------------------------------------------------
 void UserImpl::Run()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::Run()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (stgTime > lastWriteStat + settings->GetStatWritePeriod())
     {
 
 if (stgTime > lastWriteStat + settings->GetStatWritePeriod())
     {
@@ -675,7 +656,7 @@ else
 //-----------------------------------------------------------------------------
 void UserImpl::UpdatePingTime(time_t t)
 {
 //-----------------------------------------------------------------------------
 void UserImpl::UpdatePingTime(time_t t)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 if (t)
     pingTime = t;
 else
 if (t)
     pingTime = t;
 else
@@ -710,7 +691,7 @@ void UserImpl::AddTraffStatU(int dir, uint32_t ip, uint16_t port, uint32_t len)
 void UserImpl::AddTraffStatU(int dir, uint32_t ip, uint32_t len)
 #endif
 {
 void UserImpl::AddTraffStatU(int dir, uint32_t ip, uint32_t len)
 #endif
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (!m_connected || tariff == NULL)
     return;
 
 if (!m_connected || tariff == NULL)
     return;
@@ -803,7 +784,7 @@ void UserImpl::AddTraffStatD(int dir, uint32_t ip, uint16_t port, uint32_t len)
 void UserImpl::AddTraffStatD(int dir, uint32_t ip, uint32_t len)
 #endif
 {
 void UserImpl::AddTraffStatD(int dir, uint32_t ip, uint32_t len)
 #endif
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (!m_connected || tariff == NULL)
     return;
 
 if (!m_connected || tariff == NULL)
     return;
@@ -891,7 +872,7 @@ else
 //-----------------------------------------------------------------------------
 void UserImpl::OnAdd()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::OnAdd()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 std::string scriptOnAdd = settings->GetScriptsDir() + "/OnUserAdd";
 
 
 std::string scriptOnAdd = settings->GetScriptsDir() + "/OnUserAdd";
 
@@ -909,7 +890,7 @@ else
 //-----------------------------------------------------------------------------
 void UserImpl::OnDelete()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::OnDelete()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 std::string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel";
 
 
 std::string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel";
 
@@ -946,7 +927,7 @@ if (!traffStatSaved.second.empty())
 TraffStat ts;
 
     {
 TraffStat ts;
 
     {
-    STG_LOCKER lock(&mutex);
+    std::lock_guard lock(m_mutex);
     ts.swap(traffStat);
     }
 
     ts.swap(traffStat);
     }
 
@@ -962,7 +943,7 @@ if (ts.size() && !disabledDetailStat)
         if (!hard)
             {
             printfd(__FILE__, "UserImpl::WriteDetailStat() - pushing detail stat to queue\n");
         if (!hard)
             {
             printfd(__FILE__, "UserImpl::WriteDetailStat() - pushing detail stat to queue\n");
-            STG_LOCKER lock(&mutex);
+            std::lock_guard lock(m_mutex);
             traffStatSaved.second.swap(ts);
             traffStatSaved.first = lastWriteDetailedStat;
             }
             traffStatSaved.second.swap(ts);
             traffStatSaved.first = lastWriteDetailedStat;
             }
@@ -975,8 +956,12 @@ return 0;
 //-----------------------------------------------------------------------------
 double UserImpl::GetPassiveTimePart() const
 {
 //-----------------------------------------------------------------------------
 double UserImpl::GetPassiveTimePart() const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
+return getPassiveTimePart();
+}
 
 
+double UserImpl::getPassiveTimePart() const
+{
 static const std::array<unsigned, 12> daysInMonth{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
 struct tm tms;
 static const std::array<unsigned, 12> daysInMonth{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
 struct tm tms;
@@ -1001,7 +986,7 @@ return static_cast<double>(dt) / secMonth;
 //-----------------------------------------------------------------------------
 void UserImpl::SetPassiveTimeAsNewUser()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::SetPassiveTimeAsNewUser()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 time_t t = stgTime;
 struct tm tm;
 
 time_t t = stgTime;
 struct tm tm;
@@ -1015,7 +1000,7 @@ passiveTime = static_cast<time_t>(pt * 24 * 3600 * daysCurrMon);
 //-----------------------------------------------------------------------------
 void UserImpl::MidnightResetSessionStat()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::MidnightResetSessionStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (m_connected)
     {
 
 if (m_connected)
     {
@@ -1026,7 +1011,7 @@ if (m_connected)
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessNewMonth()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessNewMonth()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 //  Reset traff
 if (m_connected)
     Disconnect(true, "fake");
 //  Reset traff
 if (m_connected)
     Disconnect(true, "fake");
@@ -1069,7 +1054,7 @@ if (nextTariff.ConstData() != "")
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDayFeeSpread()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDayFeeSpread()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (passive.ConstData() || tariff == NULL)
     return;
 
 if (passive.ConstData() || tariff == NULL)
     return;
@@ -1106,7 +1091,7 @@ ResetPassiveTime();
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDayFee()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDayFee()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (tariff == NULL)
     return;
 
 if (tariff == NULL)
     return;
@@ -1117,7 +1102,7 @@ if (tariff->GetPeriod() != Tariff::MONTH)
 double passiveTimePart = 1.0;
 if (!settings->GetFullFee())
     {
 double passiveTimePart = 1.0;
 if (!settings->GetFullFee())
     {
-    passiveTimePart = GetPassiveTimePart();
+    passiveTimePart = getPassiveTimePart();
     }
 else
     {
     }
 else
     {
@@ -1177,7 +1162,7 @@ switch (settings->GetFeeChargeType())
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDailyFee()
 {
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDailyFee()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (passive.ConstData() || tariff == NULL)
     return;
 
 if (passive.ConstData() || tariff == NULL)
     return;
@@ -1214,10 +1199,12 @@ struct tm tms;
 time_t t = stgTime;
 localtime_r(&t, &tms);
 
 time_t t = stgTime;
 localtime_r(&t, &tms);
 
+std::lock_guard lock(m_mutex);
+
 double passiveTimePart = 1.0;
 if (!settings->GetFullFee())
     {
 double passiveTimePart = 1.0;
 if (!settings->GetFullFee())
     {
-    passiveTimePart = GetPassiveTimePart();
+    passiveTimePart = getPassiveTimePart();
     }
 else
     {
     }
 else
     {
@@ -1285,7 +1272,7 @@ if (tariff != NULL)
 //-----------------------------------------------------------------------------
 int UserImpl::AddMessage(Message * msg)
 {
 //-----------------------------------------------------------------------------
 int UserImpl::AddMessage(Message * msg)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (SendMessage(*msg))
     {
 
 if (SendMessage(*msg))
     {
@@ -1425,6 +1412,7 @@ std::string UserImpl::GetParamValue(const std::string & name) const
 //-----------------------------------------------------------------------------
 void UserImpl::onPassiveChange(int oldVal, int newVal)
 {
 //-----------------------------------------------------------------------------
 void UserImpl::onPassiveChange(int oldVal, int newVal)
 {
+    std::lock_guard lock(m_mutex);
     if (newVal && !oldVal && tariff != NULL)
         properties.cash.Set(cash - tariff->GetPassiveCost(),
                             *sysAdmin,
     if (newVal && !oldVal && tariff != NULL)
         properties.cash.Set(cash - tariff->GetPassiveCost(),
                             *sysAdmin,
@@ -1435,6 +1423,7 @@ void UserImpl::onPassiveChange(int oldVal, int newVal)
 //-----------------------------------------------------------------------------
 void UserImpl::onDisabledChange(int oldVal, int newVal)
 {
 //-----------------------------------------------------------------------------
 void UserImpl::onDisabledChange(int oldVal, int newVal)
 {
+    std::lock_guard lock(m_mutex);
     if (oldVal && !newVal && GetConnected())
         Disconnect(false, "disabled");
     else if (!oldVal && newVal && IsInetable())
     if (oldVal && !newVal && GetConnected())
         Disconnect(false, "disabled");
     else if (!oldVal && newVal && IsInetable())
@@ -1443,7 +1432,7 @@ void UserImpl::onDisabledChange(int oldVal, int newVal)
 //-----------------------------------------------------------------------------
 void UserImpl::onTariffChange(const std::string& /*oldVal*/, const std::string& newVal)
 {
 //-----------------------------------------------------------------------------
 void UserImpl::onTariffChange(const std::string& /*oldVal*/, const std::string& newVal)
 {
-    STG_LOCKER lock(&mutex);
+    std::lock_guard lock(m_mutex);
     if (settings->GetReconnectOnTariffChange() && m_connected)
         Disconnect(false, "Change tariff");
     tariff = tariffs->FindByName(newVal);
     if (settings->GetReconnectOnTariffChange() && m_connected)
         Disconnect(false, "Change tariff");
     tariff = tariffs->FindByName(newVal);
@@ -1466,6 +1455,7 @@ void UserImpl::onCashChange(double oldVal, double newVal)
 //-----------------------------------------------------------------------------
 void UserImpl::onIPChange(const UserIPs& oldVal, const UserIPs& newVal)
 {
 //-----------------------------------------------------------------------------
 void UserImpl::onIPChange(const UserIPs& oldVal, const UserIPs& newVal)
 {
+    std::lock_guard lock(m_mutex);
     printfd(__FILE__, "Change IP from '%s' to '%s'\n", oldVal.toString().c_str(), newVal.toString().c_str());
     if (m_connected)
         Disconnect(false, "Change IP");
     printfd(__FILE__, "Change IP from '%s' to '%s'\n", oldVal.toString().c_str(), newVal.toString().c_str());
     if (m_connected)
         Disconnect(false, "Change IP");
index 7e14311ce6b09854b1cad7fcd5eee310d6cb4c59..c5b30a1d13ce373974ec53216f1157b3b280eb6f 100644 (file)
@@ -33,6 +33,7 @@
 #include <vector>
 #include <string>
 #include <set>
 #include <vector>
 #include <string>
 #include <set>
+#include <mutex>
 
 #include <ctime>
 #include <cstdint>
 
 #include <ctime>
 #include <cstdint>
@@ -66,7 +67,6 @@ class UserImpl : public User
                   const Users * u,
                   const Services & svcs);
         UserImpl(const UserImpl & u);
                   const Users * u,
                   const Services & svcs);
         UserImpl(const UserImpl & u);
-        virtual ~UserImpl();
 
         int             ReadConf();
         int             ReadStat();
 
         int             ReadConf();
         int             ReadStat();
@@ -253,9 +253,11 @@ class UserImpl : public User
         ScopedConnection m_afterIPConn;
         void onIPChange(const UserIPs& oldVal, const UserIPs& newVal);
 
         ScopedConnection m_afterIPConn;
         void onIPChange(const UserIPs& oldVal, const UserIPs& newVal);
 
-        mutable pthread_mutex_t  mutex;
+        mutable std::mutex  m_mutex;
 
         std::string              errorStr;
 
         std::string              errorStr;
+
+        double getPassiveTimePart() const;
 };
 //-----------------------------------------------------------------------------
 
 };
 //-----------------------------------------------------------------------------