Replace all uses of AMTL threads with STL threads.

This also rewrites the work loop for threaded queries. It has been
simplified significantly.
This commit is contained in:
David Anderson
2020-05-16 22:35:56 -07:00
parent 15023777f4
commit a253e175bb
16 changed files with 84 additions and 98 deletions
+4 -5
View File
@@ -297,7 +297,7 @@ void ClientPrefs::DatabaseConnect()
// Need a new scope because of the goto above.
{
AutoLock lock(&queryLock);
std::lock_guard<std::mutex> lock(queryLock);
this->ProcessQueryCache();
}
return;
@@ -310,7 +310,7 @@ fatal_fail:
bool ClientPrefs::AddQueryToQueue(TQueryOp *query)
{
{
AutoLock lock(&queryLock);
std::lock_guard<std::mutex> lock(queryLock);
if (!Database)
{
cachedQueries.append(query);
@@ -328,8 +328,6 @@ bool ClientPrefs::AddQueryToQueue(TQueryOp *query)
void ClientPrefs::ProcessQueryCache()
{
queryLock.AssertCurrentThreadOwns();
if (!Database)
return;
@@ -373,7 +371,8 @@ void ClientPrefs::CatchLateLoadClients()
void ClientPrefs::ClearQueryCache(int serial)
{
AutoLock lock(&queryLock);
std::lock_guard<std::mutex> lock(queryLock);
for (size_t iter = 0; iter < cachedQueries.length(); ++iter)
{
TQueryOp *op = cachedQueries[iter];
+2 -2
View File
@@ -37,8 +37,8 @@
#include "smsdk_ext.h"
#include "am-vector.h"
#include <am-thread-utils.h>
#include <am-refcounting.h>
#include <mutex>
char * UTIL_strncpy(char * destination, const char * source, size_t num);
@@ -159,7 +159,7 @@ public:
private:
ke::Vector<TQueryOp *> cachedQueries;
ke::Mutex queryLock;
std::mutex queryLock;
IdentityToken_t *identity;
};
+2 -6
View File
@@ -277,17 +277,13 @@ IPreparedQuery *MyDatabase::PrepareQuery(const char *query, char *error, size_t
bool MyDatabase::LockForFullAtomicOperation()
{
if (!m_FullLock)
m_FullLock = new ke::Mutex();
m_FullLock->Lock();
m_FullLock.lock();
return true;
}
void MyDatabase::UnlockFromFullAtomicOperation()
{
if (m_FullLock)
m_FullLock->Unlock();
m_FullLock.unlock();
}
IDBDriver *MyDatabase::GetDriver()
+2 -2
View File
@@ -32,8 +32,8 @@
#ifndef _INCLUDE_SM_MYSQL_DATABASE_H_
#define _INCLUDE_SM_MYSQL_DATABASE_H_
#include <am-thread-utils.h>
#include <am-refcounting-threadsafe.h>
#include <mutex>
#include "MyDriver.h"
class MyQuery;
@@ -70,7 +70,7 @@ public:
const DatabaseInfo &GetInfo();
private:
MYSQL *m_mysql;
ke::AutoPtr<ke::Mutex> m_FullLock;
std::mutex m_FullLock;
/* ---------- */
DatabaseInfo m_Info;
+2 -2
View File
@@ -160,7 +160,7 @@ bool CompareField(const char *str1, const char *str2)
IDatabase *MyDriver::Connect(const DatabaseInfo *info, bool persistent, char *error, size_t maxlength)
{
ke::AutoLock lock(&m_Lock);
std::lock_guard<std::mutex> lock(m_Lock);
if (persistent)
{
@@ -202,7 +202,7 @@ IDatabase *MyDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
void MyDriver::RemoveFromList(MyDatabase *pdb, bool persistent)
{
ke::AutoLock lock(&m_Lock);
std::lock_guard<std::mutex> lock(m_Lock);
if (persistent)
{
m_PermDbs.remove(pdb);
+3 -2
View File
@@ -45,7 +45,8 @@
#include <sh_string.h>
#include <sh_list.h>
#include <am-thread-utils.h>
#include <mutex>
using namespace SourceMod;
using namespace SourceHook;
@@ -71,7 +72,7 @@ public:
void Shutdown();
void RemoveFromList(MyDatabase *pdb, bool persistent);
private:
ke::Mutex m_Lock;
std::mutex m_Lock;
Handle_t m_MyHandle;
List<MyDatabase *> m_TempDbs;
List<MyDatabase *> m_PermDbs;
+2 -6
View File
@@ -64,17 +64,13 @@ const char *SqDatabase::GetError(int *errorCode/* =NULL */)
bool SqDatabase::LockForFullAtomicOperation()
{
if (!m_FullLock)
m_FullLock = new ke::Mutex();
m_FullLock->Lock();
m_FullLock.lock();
return true;
}
void SqDatabase::UnlockFromFullAtomicOperation()
{
if (m_FullLock)
m_FullLock->Unlock();
m_FullLock.unlock();
}
IDBDriver *SqDatabase::GetDriver()
+2 -2
View File
@@ -33,7 +33,7 @@
#define _INCLUDE_SQLITE_SOURCEMOD_DATABASE_H_
#include <am-refcounting-threadsafe.h>
#include <am-thread-utils.h>
#include <mutex>
#include "SqDriver.h"
class SqDatabase
@@ -70,7 +70,7 @@ public:
}
private:
sqlite3 *m_sq3;
ke::AutoPtr<ke::Mutex> m_FullLock;
std::mutex m_FullLock;
bool m_Persistent;
String m_LastError;
int m_LastErrorCode;
+3 -3
View File
@@ -75,7 +75,7 @@ SqDriver::SqDriver()
// of g_SqDriver in SqDatabase's destructor.
SqDriver::~SqDriver()
{
ke::AutoLock lock(&m_OpenLock);
std::lock_guard<std::mutex> lock(m_OpenLock);
List<SqDbInfo>::iterator iter;
SqDatabase *sqdb;
@@ -178,7 +178,7 @@ inline bool IsPathSepChar(char c)
IDatabase *SqDriver::Connect(const DatabaseInfo *info, bool persistent, char *error, size_t maxlength)
{
ke::AutoLock lock(&m_OpenLock);
std::lock_guard<std::mutex> lock(m_OpenLock);
/* Full path to the database file */
char fullpath[PLATFORM_MAX_PATH];
@@ -296,7 +296,7 @@ IDatabase *SqDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
void SqDriver::RemovePersistent(IDatabase *pdb)
{
ke::AutoLock lock(&m_OpenLock);
std::lock_guard<std::mutex> lock(m_OpenLock);
List<SqDbInfo>::iterator iter;
for (iter = m_Cache.begin(); iter != m_Cache.end(); iter++)
+2 -2
View File
@@ -36,7 +36,7 @@
#include <IDBDriver.h>
#include <sh_list.h>
#include <sh_string.h>
#include <am-thread-utils.h>
#include <mutex>
#include "sqlite-source/sqlite3.h"
using namespace SourceMod;
@@ -72,7 +72,7 @@ public:
void RemovePersistent(IDatabase *pdb);
private:
Handle_t m_Handle;
ke::Mutex m_OpenLock;
std::mutex m_OpenLock;
List<SqDbInfo> m_Cache;
bool m_bThreadSafe;
bool m_bShutdown;