new dbi API additions to support threading

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401101
This commit is contained in:
David Anderson
2007-07-13 19:19:30 +00:00
parent 41aa77314d
commit 93c9ffdf02
12 changed files with 202 additions and 20 deletions
+4
View File
@@ -39,10 +39,14 @@ bool DBI_MySQL::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
dbi->AddDriver(&g_MyDriver);
my_init();
return true;
}
void DBI_MySQL::SDK_OnUnload()
{
dbi->RemoveDriver(&g_MyDriver);
//:TODO: is this needed?
//mysql_library_end();
}
+4
View File
@@ -214,6 +214,10 @@
Name="SourceMod SDK"
UniqueIdentifier="{31958233-BB2D-4e41-A8F9-CE8A4684F436}"
>
<File
RelativePath="..\..\..\public\IDBDriver.h"
>
</File>
<File
RelativePath="..\sdk\smsdk_config.h"
>
+1 -1
View File
@@ -276,7 +276,7 @@ DBResult MyBasicResults::CopyBlob(unsigned int columnId, void *buffer, size_t ma
MyQuery::MyQuery(MyDatabase *db, MYSQL_RES *res)
: m_pParent(db), m_rs(res)
{
m_pParent->IncRefCount();
m_pParent->IncReferenceCount();
}
IResultSet *MyQuery::GetResultSet()
+31 -2
View File
@@ -56,7 +56,7 @@ DBType GetOurType(enum_field_types type)
}
MyDatabase::MyDatabase(MYSQL *mysql, const DatabaseInfo *info, bool persistent)
: m_mysql(mysql), m_refcount(1), m_bPersistent(persistent)
: m_mysql(mysql), m_refcount(1), m_pFullLock(NULL), m_bPersistent(persistent)
{
m_Host.assign(info->host);
m_Database.assign(info->database);
@@ -78,7 +78,7 @@ MyDatabase::~MyDatabase()
m_mysql = NULL;
}
void MyDatabase::IncRefCount()
void MyDatabase::IncReferenceCount()
{
m_refcount++;
}
@@ -212,3 +212,32 @@ IPreparedQuery *MyDatabase::PrepareQuery(const char *query, char *error, size_t
return new MyStatement(this, stmt);
}
bool MyDatabase::LockForFullAtomicOperation()
{
if (!m_pFullLock)
{
m_pFullLock = threader->MakeMutex();
if (!m_pFullLock)
{
return false;
}
}
m_pFullLock->Lock();
return true;
}
void MyDatabase::UnlockFromFullAtomicOperation()
{
if (m_pFullLock)
{
m_pFullLock->Unlock();
}
}
IDBDriver *MyDatabase::GetDriver()
{
return &g_MyDriver;
}
+6 -1
View File
@@ -2,6 +2,7 @@
#define _INCLUDE_SM_MYSQL_DATABASE_H_
#include "MyDriver.h"
#include <IThreader.h>
class MyQuery;
class MyStatement;
@@ -22,12 +23,16 @@ public: //IDatabase
bool QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newSize);
unsigned int GetAffectedRows();
unsigned int GetInsertID();
bool LockForFullAtomicOperation();
void UnlockFromFullAtomicOperation();
void IncReferenceCount();
IDBDriver *GetDriver();
public:
const DatabaseInfo &GetInfo();
void IncRefCount();
private:
MYSQL *m_mysql;
unsigned int m_refcount;
IMutex *m_pFullLock;
/* ---------- */
DatabaseInfo m_Info;
+16 -1
View File
@@ -121,7 +121,7 @@ IDatabase *MyDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
&& CompareField(info->database, other.database)
&& (info->port == other.port))
{
db->IncRefCount();
db->IncReferenceCount();
return db;
}
}
@@ -151,6 +151,21 @@ void MyDriver::RemoveFromList(MyDatabase *pdb, bool persistent)
}
}
bool MyDriver::IsThreadSafe()
{
return (mysql_thread_safe() != 0);
}
bool MyDriver::InitializeThreadSafety()
{
return (mysql_thread_init() == 0);
}
void MyDriver::ShutdownThreadSafety()
{
mysql_thread_end();
}
unsigned int strncopy(char *dest, const char *src, size_t count)
{
if (!count)
+3
View File
@@ -29,6 +29,9 @@ public: //IDBDriver
const char *GetProductName();
Handle_t GetHandle();
IdentityToken_t *GetIdentity();
bool IsThreadSafe();
bool InitializeThreadSafety();
void ShutdownThreadSafety();
public:
void Shutdown();
void RemoveFromList(MyDatabase *pdb, bool persistent);
+1 -1
View File
@@ -17,7 +17,7 @@ MyStatement::MyStatement(MyDatabase *db, MYSQL_STMT *stmt)
m_bind = NULL;
}
m_pParent->IncRefCount();
m_pParent->IncReferenceCount();
m_pRes = mysql_stmt_result_metadata(stmt);
m_Results = false;
+5
View File
@@ -52,5 +52,10 @@
//#define SMEXT_ENABLE_HANDLESYS
//#define SMEXT_ENABLE_PLAYERHELPERS
#define SMEXT_ENABLE_DBMANAGER
//#define SMEXT_ENABLE_GAMECONF
//#define SMEXT_ENABLE_MEMUTILS
//#define SMEXT_ENABLE_GAMEHELPERS
//#define SMEXT_ENABLE_TIMERSYS
#define SMEXT_ENABLE_THREADER
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
+38 -2
View File
@@ -13,7 +13,7 @@
*
* To view the latest information, see: http://www.sourcemod.net/license.php
*
* Version: $Id: smsdk_ext.cpp 763 2007-05-09 05:20:03Z damagedsoul $
* Version: $Id: smsdk_ext.cpp 1034 2007-06-30 16:43:11Z dvander $
*/
#include <stdio.h>
@@ -40,11 +40,29 @@ IHandleSys *g_pHandleSys = NULL; /**< Handle system */
IHandleSys *handlesys = NULL; /**< Handle system */
#endif
#if defined SMEXT_ENABLE_PLAYERHELPERS
IPlayerHelpers *playerhelpers = NULL; /**< Player helpers */
IPlayerManager *playerhelpers = NULL; /**< Player helpers */
#endif //SMEXT_ENABLE_PLAYERHELPERS
#if defined SMEXT_ENABLE_DBMANAGER
IDBManager *dbi = NULL; /**< DB Manager */
#endif //SMEXT_ENABLE_DBMANAGER
#if defined SMEXT_ENABLE_GAMECONF
IGameConfigManager *gameconfs = NULL; /**< Game config manager */
#endif //SMEXT_ENABLE_DBMANAGER
#if defined SMEXT_ENABLE_MEMUTILS
IMemoryUtils *memutils = NULL;
#endif //SMEXT_ENABLE_DBMANAGER
#if defined SMEXT_ENABLE_GAMEHELPERS
IGameHelpers *gamehelpers = NULL;
#endif
#if defined SMEXT_ENABLE_TIMERSYS
ITimerSystem *timersys = NULL;
#endif
#if defined SMEXT_ENABLE_ADTFACTORY
IADTFactory *adtfactory = NULL;
#endif
#if defined SMEXT_ENABLE_THREADER
IThreader *threader = NULL;
#endif
/** Exports the main interface */
PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
@@ -94,6 +112,24 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error,
#if defined SMEXT_ENABLE_DBMANAGER
SM_GET_IFACE(DBI, dbi);
#endif
#if defined SMEXT_ENABLE_GAMECONF
SM_GET_IFACE(GAMECONFIG, gameconfs);
#endif
#if defined SMEXT_ENABLE_MEMUTILS
SM_GET_IFACE(MEMORYUTILS, memutils);
#endif
#if defined SMEXT_ENABLE_GAMEHELPERS
SM_GET_IFACE(GAMEHELPERS, gamehelpers);
#endif
#if defined SMEXT_ENABLE_TIMERSYS
SM_GET_IFACE(TIMERSYS, timersys);
#endif
#if defined SMEXT_ENABLE_ADTFACTORY
SM_GET_IFACE(ADTFACTORY, adtfactory);
#endif
#if defined SMEXT_ENABLE_THREADER
SM_GET_IFACE(THREADER, threader);
#endif
if (SDK_OnLoad(error, maxlength, late))
{
+38 -2
View File
@@ -13,7 +13,7 @@
*
* To view the latest information, see: http://www.sourcemod.net/license.php
*
* Version: $Id: smsdk_ext.h 763 2007-05-09 05:20:03Z damagedsoul $
* Version: $Id: smsdk_ext.h 1034 2007-06-30 16:43:11Z dvander $
*/
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
@@ -39,6 +39,24 @@
#if defined SMEXT_ENABLE_DBMANAGER
#include <IDBDriver.h>
#endif //SMEXT_ENABLE_DBMANAGER
#if defined SMEXT_ENABLE_GAMECONF
#include <IGameConfigs.h>
#endif
#if defined SMEXT_ENABLE_MEMUTILS
#include <IMemoryUtils.h>
#endif
#if defined SMEXT_ENABLE_GAMEHELPERS
#include <IGameHelpers.h>
#endif
#if defined SMEXT_ENABLE_TIMERSYS
#include <ITimerSystem.h>
#endif
#if defined SMEXT_ENABLE_ADTFACTORY
#include <IADTFactory.h>
#endif
#if defined SMEXT_ENABLE_THREADER
#include <IThreader.h>
#endif
#if defined SMEXT_CONF_METAMOD
#include <ISmmPlugin.h>
@@ -196,11 +214,29 @@ extern IHandleSys *g_pHandleSys;
extern IHandleSys *handlesys; /* Note: Newer name */
#endif //SMEXT_ENABLE_HANDLESYS
#if defined SMEXT_ENABLE_PLAYERHELPERS
extern IPlayerHelpers *playerhelpers;
extern IPlayerManager *playerhelpers;
#endif //SMEXT_ENABLE_PLAYERHELPERS
#if defined SMEXT_ENABLE_DBMANAGER
extern IDBManager *dbi;
#endif //SMEXT_ENABLE_DBMANAGER
#if defined SMEXT_ENABLE_GAMECONF
extern IGameConfigManager *gameconfs;
#endif //SMEXT_ENABLE_DBMANAGER
#if defined SMEXT_ENABLE_MEMUTILS
extern IMemoryUtils *memutils;
#endif
#if defined SMEXT_ENABLE_GAMEHELPERS
extern IGameHelpers *gamehelpers;
#endif
#if defined SMEXT_ENABLE_TIMERSYS
extern ITimerSystem *timersys;
#endif
#if defined SMEXT_ENABLE_ADTFACTORY
extern IADTFactory *adtfactory;
#endif
#if defined SMEXT_ENABLE_THREADER
extern IThreader *threader;
#endif
#if defined SMEXT_CONF_METAMOD
PLUGIN_GLOBALVARS();