+++ /dev/null
-/*
- *    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
 
 #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 "listener.h"
 
 #include "stg/scriptexecuter.h"
-#include "stg/locker.h"
 #include "stg/common.h"
 #include "stg/const.h"
 
 
 
 #include "stg/corporations.h"
 #include "stg/corp_conf.h"
-#include "stg/locker.h"
 #include "stg/logger.h"
 
 #include <vector>
 
 #include "inetaccess.h"
 
 #include "stg/common.h"
-#include "stg/locker.h"
 #include "stg/tariff.h"
 #include "stg/settings.h"
 
 
 #include "ping.h"
 
 #include "stg/user.h"
-#include "stg/locker.h"
 #include "stg/user_property.h"
 
 #include <algorithm>
 
 #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/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"
     : 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 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;
 
 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;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 userList->swap(files);
 
 
 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;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 adminList->swap(files);
 
 
 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;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 tariffList->swap(files);
 
 
 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;
     }
 
-STG_LOCKER lock(&m_mutex);
+std::lock_guard lock(m_mutex);
 
 list->swap(files);
 
         {
         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 += "'";
 
 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 += "'";
 
 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;
 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;
 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;
     {
     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;
     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;
 
 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;
 
 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())
     {
-    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;
 
 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())
     {
-    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;
     }
 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;
 
 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;
 
 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;
 
 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;
 
 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;
 
 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;
     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;
     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;
 
 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;
 
 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;
 
 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;
 
 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;
 
 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;
 
 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;
 
 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;
 
 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));
     }
 
 
     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;
 
 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));
     }
 
     }
 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;
 
 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));
     }
 
     }
 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;
 
 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));
     }
 
 
 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;
 
 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;
 
 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;
 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 += "'";
 
     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;
 
 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;
 
 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;
     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;
     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;
     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;
     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;
     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;
     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;
     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;
 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;
 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 += "'";
 
 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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
     strprintf(¶m, "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;
 
 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;
 
 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;
 
 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;
 
 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;
 
     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;
 
 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;
 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 += "'";
 
     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;
 
 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;
 
 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;
 
 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;
 
 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;
 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;
     {
     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;
 
 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));
     }
 
     {
     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;
 
 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));
     }
 
     {
     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;
 
 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));
     }
 
 
 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;
 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);
                 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 += "'";
                 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 += "'";
 
 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));
     }
 
     {
     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.";
 
 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.";
 
 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.";
 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;
 
 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);
 
 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;
         {
         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;
         {
         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;
 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.";
 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.";
 
     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.";
 
     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. \'";
 
 #include "stg/logger.h"
 
 #include <string>
+#include <mutex>
 
 #include <sys/types.h>
-#include <pthread.h>
 
 //-----------------------------------------------------------------------------
 class FILES_STORE_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;
 };
 
       schemaVersion(0),
       logger(STG::PluginLogger::get("store_firebird"))
 {
-pthread_mutex_init(&mutex, NULL);
 }
 //-----------------------------------------------------------------------------
 FIREBIRD_STORE::~FIREBIRD_STORE()
 
 #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"
 #include <ctime>
 #include <string>
 #include <vector>
+#include <mutex>
 
 class FIREBIRD_STORE : public STG::Store
 {
         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;
 
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 
 //-----------------------------------------------------------------------------
 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);
 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);
                                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);
 //-----------------------------------------------------------------------------
 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);
 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);
 
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 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);
 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);
 
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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);
 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);
 }
 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);
 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);
 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);
                                     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);
 //-----------------------------------------------------------------------------
 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);
                     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);
                                       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);
 //-----------------------------------------------------------------------------
 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);
 
       connection(NULL),
       logger(STG::PluginLogger::get("store_postgresql"))
 {
-pthread_mutex_init(&mutex, NULL);
 }
 //-----------------------------------------------------------------------------
 POSTGRESQL_STORE::~POSTGRESQL_STORE()
     {
     PQfinish(connection);
     }
-pthread_mutex_destroy(&mutex);
 }
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::ParseSettings()
 
 
 #include <string>
 #include <vector>
+#include <mutex>
 
 #include <libpq-fe.h>
 
         std::string password;
         std::string clientEncoding;
         STG::ModuleSettings settings;
-        mutable pthread_mutex_t mutex;
+        mutable std::mutex m_mutex;
         mutable int version;
         int retries;
 
 
 
 #include "postgresql_store.h"
 
-#include "stg/locker.h"
 #include "stg/common.h"
 #include "stg/admin_conf.h"
 #include "stg/blowfish.h"
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveAdmin(const STG::AdminConf & ac) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddAdmin(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelAdmin(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 #include "postgresql_store.h"
 
 #include "stg/corp_conf.h"
-#include "stg/locker.h"
 #include "stg/common.h"
 
 #include <string>
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveCorp(const STG::CorpConf & cc) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddCorp(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelCorp(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 #include "postgresql_store.h"
 
 #include "stg/common.h"
-#include "stg/locker.h"
 #include "stg/message.h"
 
 #include <string>
 //-----------------------------------------------------------------------------
 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)
     {
 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)
     {
                                  STG::Message * msg,
                                  const std::string &) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 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)
     {
 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)
     {
 
 
 #include "stg/service_conf.h"
 #include "stg/common.h"
-#include "stg/locker.h"
 
 #include <string>
 #include <vector>
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::SaveService(const STG::ServiceConf & sc) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelService(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 
 
 #include "stg/tariff_conf.h"
 #include "stg/common.h"
-#include "stg/locker.h"
 
 #include <string>
 #include <vector>
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddTariff(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelTariff(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 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)
     {
 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)
     {
 
 #include "stg/user_traff.h"
 #include "stg/common.h"
 #include "stg/const.h"
-#include "stg/locker.h"
 #include "../../../stg_timer.h"
 
 #include <string>
 //-----------------------------------------------------------------------------
 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)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::AddUser(const std::string & name) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 int POSTGRESQL_STORE::DelUser(const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 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);
 }
 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)
     {
 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)
     {
 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)
     {
                                     const std::string & newValue,
                                     const std::string & message = "") const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 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)
     {
                     double freeMb,
                     const std::string & reason) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
                                       time_t lastStat,
                                       const std::string & login) const
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (PQstatus(connection) != CONNECTION_OK)
     {
 //-----------------------------------------------------------------------------
 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);
 }
 
 
 #include "stg/services.h"
 #include "stg/service_conf.h"
-#include "stg/locker.h"
 #include "stg/noncopyable.h"
 #include "stg/logger.h"
 
 
 
 #include "tariffs_impl.h"
 
-#include "stg/locker.h"
 #include "stg/logger.h"
 #include "stg/store.h"
 #include "stg/admin.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"
 
 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)
     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)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 static int idGen = 0;
 assert(login.empty() && "Login is already set");
 login = l;
 //-----------------------------------------------------------------------------
 int UserImpl::ReadConf()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserConf conf;
 
 if (store->RestoreUserConf(&conf, login))
 //-----------------------------------------------------------------------------
 int UserImpl::ReadStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserStat stat;
 
 if (store->RestoreUserStat(&stat, login))
 //-----------------------------------------------------------------------------
 int UserImpl::WriteConf()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserConf conf(properties.GetConf());
 
 printfd(__FILE__, "UserImpl::WriteConf()\n");
 //-----------------------------------------------------------------------------
 int UserImpl::WriteStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 UserStat stat(properties.GetStat());
 
 if (store->SaveUserStat(stat, login))
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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.
 //-----------------------------------------------------------------------------
 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
  */
 //-----------------------------------------------------------------------------
 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
 {
-    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;
  * Connect user to Internet. This function is differ from Authorize() !!!
  */
 
-STG_LOCKER lock(&mutex);
-
 if (!fakeConnect)
     {
     std::string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect";
  *  Disconnect user from Internet. This function is differ from UnAuthorize() !!!
  */
 
-STG_LOCKER lock(&mutex);
-
 if (!lastIPForDisconnect)
     {
     printfd(__FILE__, "lastIPForDisconnect\n");
 //-----------------------------------------------------------------------------
 void UserImpl::Run()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (stgTime > lastWriteStat + settings->GetStatWritePeriod())
     {
 //-----------------------------------------------------------------------------
 void UserImpl::UpdatePingTime(time_t t)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 if (t)
     pingTime = t;
 else
 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;
 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;
 //-----------------------------------------------------------------------------
 void UserImpl::OnAdd()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 std::string scriptOnAdd = settings->GetScriptsDir() + "/OnUserAdd";
 
 //-----------------------------------------------------------------------------
 void UserImpl::OnDelete()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 std::string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel";
 
 TraffStat ts;
 
     {
-    STG_LOCKER lock(&mutex);
+    std::lock_guard lock(m_mutex);
     ts.swap(traffStat);
     }
 
         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;
             }
 //-----------------------------------------------------------------------------
 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;
 //-----------------------------------------------------------------------------
 void UserImpl::SetPassiveTimeAsNewUser()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 time_t t = stgTime;
 struct tm tm;
 //-----------------------------------------------------------------------------
 void UserImpl::MidnightResetSessionStat()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (m_connected)
     {
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessNewMonth()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 //  Reset traff
 if (m_connected)
     Disconnect(true, "fake");
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDayFeeSpread()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (passive.ConstData() || tariff == NULL)
     return;
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDayFee()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (tariff == NULL)
     return;
 double passiveTimePart = 1.0;
 if (!settings->GetFullFee())
     {
-    passiveTimePart = GetPassiveTimePart();
+    passiveTimePart = getPassiveTimePart();
     }
 else
     {
 //-----------------------------------------------------------------------------
 void UserImpl::ProcessDailyFee()
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (passive.ConstData() || tariff == NULL)
     return;
 time_t t = stgTime;
 localtime_r(&t, &tms);
 
+std::lock_guard lock(m_mutex);
+
 double passiveTimePart = 1.0;
 if (!settings->GetFullFee())
     {
-    passiveTimePart = GetPassiveTimePart();
+    passiveTimePart = getPassiveTimePart();
     }
 else
     {
 //-----------------------------------------------------------------------------
 int UserImpl::AddMessage(Message * msg)
 {
-STG_LOCKER lock(&mutex);
+std::lock_guard lock(m_mutex);
 
 if (SendMessage(*msg))
     {
 //-----------------------------------------------------------------------------
 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,
 //-----------------------------------------------------------------------------
 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())
 //-----------------------------------------------------------------------------
 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);
 //-----------------------------------------------------------------------------
 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");
 
 #include <vector>
 #include <string>
 #include <set>
+#include <mutex>
 
 #include <ctime>
 #include <cstdint>
                   const Users * u,
                   const Services & svcs);
         UserImpl(const UserImpl & u);
-        virtual ~UserImpl();
 
         int             ReadConf();
         int             ReadStat();
         ScopedConnection m_afterIPConn;
         void onIPChange(const UserIPs& oldVal, const UserIPs& newVal);
 
-        mutable pthread_mutex_t  mutex;
+        mutable std::mutex  m_mutex;
 
         std::string              errorStr;
+
+        double getPassiveTimePart() const;
 };
 //-----------------------------------------------------------------------------