1.1 --- a/extensions/mysql/extension.cpp Fri Jul 13 17:26:32 2007 +0000
1.2 +++ b/extensions/mysql/extension.cpp Fri Jul 13 19:19:30 2007 +0000
1.3 @@ -39,10 +39,14 @@
1.4 {
1.5 dbi->AddDriver(&g_MyDriver);
1.6
1.7 + my_init();
1.8 +
1.9 return true;
1.10 }
1.11
1.12 void DBI_MySQL::SDK_OnUnload()
1.13 {
1.14 dbi->RemoveDriver(&g_MyDriver);
1.15 + //:TODO: is this needed?
1.16 + //mysql_library_end();
1.17 }
2.1 --- a/extensions/mysql/msvc8/sm_mysql.vcproj Fri Jul 13 17:26:32 2007 +0000
2.2 +++ b/extensions/mysql/msvc8/sm_mysql.vcproj Fri Jul 13 19:19:30 2007 +0000
2.3 @@ -215,6 +215,10 @@
2.4 UniqueIdentifier="{31958233-BB2D-4e41-A8F9-CE8A4684F436}"
2.5 >
2.6 <File
2.7 + RelativePath="..\..\..\public\IDBDriver.h"
2.8 + >
2.9 + </File>
2.10 + <File
2.11 RelativePath="..\sdk\smsdk_config.h"
2.12 >
2.13 </File>
3.1 --- a/extensions/mysql/mysql/MyBasicResults.cpp Fri Jul 13 17:26:32 2007 +0000
3.2 +++ b/extensions/mysql/mysql/MyBasicResults.cpp Fri Jul 13 19:19:30 2007 +0000
3.3 @@ -276,7 +276,7 @@
3.4 MyQuery::MyQuery(MyDatabase *db, MYSQL_RES *res)
3.5 : m_pParent(db), m_rs(res)
3.6 {
3.7 - m_pParent->IncRefCount();
3.8 + m_pParent->IncReferenceCount();
3.9 }
3.10
3.11 IResultSet *MyQuery::GetResultSet()
4.1 --- a/extensions/mysql/mysql/MyDatabase.cpp Fri Jul 13 17:26:32 2007 +0000
4.2 +++ b/extensions/mysql/mysql/MyDatabase.cpp Fri Jul 13 19:19:30 2007 +0000
4.3 @@ -56,7 +56,7 @@
4.4 }
4.5
4.6 MyDatabase::MyDatabase(MYSQL *mysql, const DatabaseInfo *info, bool persistent)
4.7 -: m_mysql(mysql), m_refcount(1), m_bPersistent(persistent)
4.8 +: m_mysql(mysql), m_refcount(1), m_pFullLock(NULL), m_bPersistent(persistent)
4.9 {
4.10 m_Host.assign(info->host);
4.11 m_Database.assign(info->database);
4.12 @@ -78,7 +78,7 @@
4.13 m_mysql = NULL;
4.14 }
4.15
4.16 -void MyDatabase::IncRefCount()
4.17 +void MyDatabase::IncReferenceCount()
4.18 {
4.19 m_refcount++;
4.20 }
4.21 @@ -212,3 +212,32 @@
4.22
4.23 return new MyStatement(this, stmt);
4.24 }
4.25 +
4.26 +bool MyDatabase::LockForFullAtomicOperation()
4.27 +{
4.28 + if (!m_pFullLock)
4.29 + {
4.30 + m_pFullLock = threader->MakeMutex();
4.31 + if (!m_pFullLock)
4.32 + {
4.33 + return false;
4.34 + }
4.35 + }
4.36 +
4.37 + m_pFullLock->Lock();
4.38 +
4.39 + return true;
4.40 +}
4.41 +
4.42 +void MyDatabase::UnlockFromFullAtomicOperation()
4.43 +{
4.44 + if (m_pFullLock)
4.45 + {
4.46 + m_pFullLock->Unlock();
4.47 + }
4.48 +}
4.49 +
4.50 +IDBDriver *MyDatabase::GetDriver()
4.51 +{
4.52 + return &g_MyDriver;
4.53 +}
5.1 --- a/extensions/mysql/mysql/MyDatabase.h Fri Jul 13 17:26:32 2007 +0000
5.2 +++ b/extensions/mysql/mysql/MyDatabase.h Fri Jul 13 19:19:30 2007 +0000
5.3 @@ -2,6 +2,7 @@
5.4 #define _INCLUDE_SM_MYSQL_DATABASE_H_
5.5
5.6 #include "MyDriver.h"
5.7 +#include <IThreader.h>
5.8
5.9 class MyQuery;
5.10 class MyStatement;
5.11 @@ -22,12 +23,16 @@
5.12 bool QuoteString(const char *str, char buffer[], size_t maxlen, size_t *newSize);
5.13 unsigned int GetAffectedRows();
5.14 unsigned int GetInsertID();
5.15 + bool LockForFullAtomicOperation();
5.16 + void UnlockFromFullAtomicOperation();
5.17 + void IncReferenceCount();
5.18 + IDBDriver *GetDriver();
5.19 public:
5.20 const DatabaseInfo &GetInfo();
5.21 - void IncRefCount();
5.22 private:
5.23 MYSQL *m_mysql;
5.24 unsigned int m_refcount;
5.25 + IMutex *m_pFullLock;
5.26
5.27 /* ---------- */
5.28 DatabaseInfo m_Info;
6.1 --- a/extensions/mysql/mysql/MyDriver.cpp Fri Jul 13 17:26:32 2007 +0000
6.2 +++ b/extensions/mysql/mysql/MyDriver.cpp Fri Jul 13 19:19:30 2007 +0000
6.3 @@ -121,7 +121,7 @@
6.4 && CompareField(info->database, other.database)
6.5 && (info->port == other.port))
6.6 {
6.7 - db->IncRefCount();
6.8 + db->IncReferenceCount();
6.9 return db;
6.10 }
6.11 }
6.12 @@ -151,6 +151,21 @@
6.13 }
6.14 }
6.15
6.16 +bool MyDriver::IsThreadSafe()
6.17 +{
6.18 + return (mysql_thread_safe() != 0);
6.19 +}
6.20 +
6.21 +bool MyDriver::InitializeThreadSafety()
6.22 +{
6.23 + return (mysql_thread_init() == 0);
6.24 +}
6.25 +
6.26 +void MyDriver::ShutdownThreadSafety()
6.27 +{
6.28 + mysql_thread_end();
6.29 +}
6.30 +
6.31 unsigned int strncopy(char *dest, const char *src, size_t count)
6.32 {
6.33 if (!count)
7.1 --- a/extensions/mysql/mysql/MyDriver.h Fri Jul 13 17:26:32 2007 +0000
7.2 +++ b/extensions/mysql/mysql/MyDriver.h Fri Jul 13 19:19:30 2007 +0000
7.3 @@ -29,6 +29,9 @@
7.4 const char *GetProductName();
7.5 Handle_t GetHandle();
7.6 IdentityToken_t *GetIdentity();
7.7 + bool IsThreadSafe();
7.8 + bool InitializeThreadSafety();
7.9 + void ShutdownThreadSafety();
7.10 public:
7.11 void Shutdown();
7.12 void RemoveFromList(MyDatabase *pdb, bool persistent);
8.1 --- a/extensions/mysql/mysql/MyStatement.cpp Fri Jul 13 17:26:32 2007 +0000
8.2 +++ b/extensions/mysql/mysql/MyStatement.cpp Fri Jul 13 19:19:30 2007 +0000
8.3 @@ -17,7 +17,7 @@
8.4 m_bind = NULL;
8.5 }
8.6
8.7 - m_pParent->IncRefCount();
8.8 + m_pParent->IncReferenceCount();
8.9
8.10 m_pRes = mysql_stmt_result_metadata(stmt);
8.11 m_Results = false;
9.1 --- a/extensions/mysql/sdk/smsdk_config.h Fri Jul 13 17:26:32 2007 +0000
9.2 +++ b/extensions/mysql/sdk/smsdk_config.h Fri Jul 13 19:19:30 2007 +0000
9.3 @@ -52,5 +52,10 @@
9.4 //#define SMEXT_ENABLE_HANDLESYS
9.5 //#define SMEXT_ENABLE_PLAYERHELPERS
9.6 #define SMEXT_ENABLE_DBMANAGER
9.7 +//#define SMEXT_ENABLE_GAMECONF
9.8 +//#define SMEXT_ENABLE_MEMUTILS
9.9 +//#define SMEXT_ENABLE_GAMEHELPERS
9.10 +//#define SMEXT_ENABLE_TIMERSYS
9.11 +#define SMEXT_ENABLE_THREADER
9.12
9.13 #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
10.1 --- a/extensions/mysql/sdk/smsdk_ext.cpp Fri Jul 13 17:26:32 2007 +0000
10.2 +++ b/extensions/mysql/sdk/smsdk_ext.cpp Fri Jul 13 19:19:30 2007 +0000
10.3 @@ -13,7 +13,7 @@
10.4 *
10.5 * To view the latest information, see: http://www.sourcemod.net/license.php
10.6 *
10.7 - * Version: $Id: smsdk_ext.cpp 763 2007-05-09 05:20:03Z damagedsoul $
10.8 + * Version: $Id: smsdk_ext.cpp 1034 2007-06-30 16:43:11Z dvander $
10.9 */
10.10
10.11 #include <stdio.h>
10.12 @@ -40,11 +40,29 @@
10.13 IHandleSys *handlesys = NULL; /**< Handle system */
10.14 #endif
10.15 #if defined SMEXT_ENABLE_PLAYERHELPERS
10.16 -IPlayerHelpers *playerhelpers = NULL; /**< Player helpers */
10.17 +IPlayerManager *playerhelpers = NULL; /**< Player helpers */
10.18 #endif //SMEXT_ENABLE_PLAYERHELPERS
10.19 #if defined SMEXT_ENABLE_DBMANAGER
10.20 IDBManager *dbi = NULL; /**< DB Manager */
10.21 #endif //SMEXT_ENABLE_DBMANAGER
10.22 +#if defined SMEXT_ENABLE_GAMECONF
10.23 +IGameConfigManager *gameconfs = NULL; /**< Game config manager */
10.24 +#endif //SMEXT_ENABLE_DBMANAGER
10.25 +#if defined SMEXT_ENABLE_MEMUTILS
10.26 +IMemoryUtils *memutils = NULL;
10.27 +#endif //SMEXT_ENABLE_DBMANAGER
10.28 +#if defined SMEXT_ENABLE_GAMEHELPERS
10.29 +IGameHelpers *gamehelpers = NULL;
10.30 +#endif
10.31 +#if defined SMEXT_ENABLE_TIMERSYS
10.32 +ITimerSystem *timersys = NULL;
10.33 +#endif
10.34 +#if defined SMEXT_ENABLE_ADTFACTORY
10.35 +IADTFactory *adtfactory = NULL;
10.36 +#endif
10.37 +#if defined SMEXT_ENABLE_THREADER
10.38 +IThreader *threader = NULL;
10.39 +#endif
10.40
10.41 /** Exports the main interface */
10.42 PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
10.43 @@ -94,6 +112,24 @@
10.44 #if defined SMEXT_ENABLE_DBMANAGER
10.45 SM_GET_IFACE(DBI, dbi);
10.46 #endif
10.47 +#if defined SMEXT_ENABLE_GAMECONF
10.48 + SM_GET_IFACE(GAMECONFIG, gameconfs);
10.49 +#endif
10.50 +#if defined SMEXT_ENABLE_MEMUTILS
10.51 + SM_GET_IFACE(MEMORYUTILS, memutils);
10.52 +#endif
10.53 +#if defined SMEXT_ENABLE_GAMEHELPERS
10.54 + SM_GET_IFACE(GAMEHELPERS, gamehelpers);
10.55 +#endif
10.56 +#if defined SMEXT_ENABLE_TIMERSYS
10.57 + SM_GET_IFACE(TIMERSYS, timersys);
10.58 +#endif
10.59 +#if defined SMEXT_ENABLE_ADTFACTORY
10.60 + SM_GET_IFACE(ADTFACTORY, adtfactory);
10.61 +#endif
10.62 +#if defined SMEXT_ENABLE_THREADER
10.63 + SM_GET_IFACE(THREADER, threader);
10.64 +#endif
10.65
10.66 if (SDK_OnLoad(error, maxlength, late))
10.67 {
11.1 --- a/extensions/mysql/sdk/smsdk_ext.h Fri Jul 13 17:26:32 2007 +0000
11.2 +++ b/extensions/mysql/sdk/smsdk_ext.h Fri Jul 13 19:19:30 2007 +0000
11.3 @@ -13,7 +13,7 @@
11.4 *
11.5 * To view the latest information, see: http://www.sourcemod.net/license.php
11.6 *
11.7 - * Version: $Id: smsdk_ext.h 763 2007-05-09 05:20:03Z damagedsoul $
11.8 + * Version: $Id: smsdk_ext.h 1034 2007-06-30 16:43:11Z dvander $
11.9 */
11.10
11.11 #ifndef _INCLUDE_SOURCEMOD_EXTENSION_BASESDK_H_
11.12 @@ -39,6 +39,24 @@
11.13 #if defined SMEXT_ENABLE_DBMANAGER
11.14 #include <IDBDriver.h>
11.15 #endif //SMEXT_ENABLE_DBMANAGER
11.16 +#if defined SMEXT_ENABLE_GAMECONF
11.17 +#include <IGameConfigs.h>
11.18 +#endif
11.19 +#if defined SMEXT_ENABLE_MEMUTILS
11.20 +#include <IMemoryUtils.h>
11.21 +#endif
11.22 +#if defined SMEXT_ENABLE_GAMEHELPERS
11.23 +#include <IGameHelpers.h>
11.24 +#endif
11.25 +#if defined SMEXT_ENABLE_TIMERSYS
11.26 +#include <ITimerSystem.h>
11.27 +#endif
11.28 +#if defined SMEXT_ENABLE_ADTFACTORY
11.29 +#include <IADTFactory.h>
11.30 +#endif
11.31 +#if defined SMEXT_ENABLE_THREADER
11.32 +#include <IThreader.h>
11.33 +#endif
11.34
11.35 #if defined SMEXT_CONF_METAMOD
11.36 #include <ISmmPlugin.h>
11.37 @@ -196,11 +214,29 @@
11.38 extern IHandleSys *handlesys; /* Note: Newer name */
11.39 #endif //SMEXT_ENABLE_HANDLESYS
11.40 #if defined SMEXT_ENABLE_PLAYERHELPERS
11.41 -extern IPlayerHelpers *playerhelpers;
11.42 +extern IPlayerManager *playerhelpers;
11.43 #endif //SMEXT_ENABLE_PLAYERHELPERS
11.44 #if defined SMEXT_ENABLE_DBMANAGER
11.45 extern IDBManager *dbi;
11.46 #endif //SMEXT_ENABLE_DBMANAGER
11.47 +#if defined SMEXT_ENABLE_GAMECONF
11.48 +extern IGameConfigManager *gameconfs;
11.49 +#endif //SMEXT_ENABLE_DBMANAGER
11.50 +#if defined SMEXT_ENABLE_MEMUTILS
11.51 +extern IMemoryUtils *memutils;
11.52 +#endif
11.53 +#if defined SMEXT_ENABLE_GAMEHELPERS
11.54 +extern IGameHelpers *gamehelpers;
11.55 +#endif
11.56 +#if defined SMEXT_ENABLE_TIMERSYS
11.57 +extern ITimerSystem *timersys;
11.58 +#endif
11.59 +#if defined SMEXT_ENABLE_ADTFACTORY
11.60 +extern IADTFactory *adtfactory;
11.61 +#endif
11.62 +#if defined SMEXT_ENABLE_THREADER
11.63 +extern IThreader *threader;
11.64 +#endif
11.65
11.66 #if defined SMEXT_CONF_METAMOD
11.67 PLUGIN_GLOBALVARS();
12.1 --- a/public/IDBDriver.h Fri Jul 13 17:26:32 2007 +0000
12.2 +++ b/public/IDBDriver.h Fri Jul 13 19:19:30 2007 +0000
12.3 @@ -24,7 +24,7 @@
12.4 #include <string.h>
12.5
12.6 #define SMINTERFACE_DBI_NAME "IDBI"
12.7 -#define SMINTERFACE_DBI_VERSION 3
12.8 +#define SMINTERFACE_DBI_VERSION 4
12.9
12.10 namespace SourceMod
12.11 {
12.12 @@ -396,6 +396,8 @@
12.13 virtual unsigned int GetInsertID() =0;
12.14 };
12.15
12.16 + class IDBDriver;
12.17 +
12.18 /**
12.19 * @brief Encapsulates a database connection.
12.20 */
12.21 @@ -484,6 +486,28 @@
12.22 * @return Row insertion ID of the last execute, if any.
12.23 */
12.24 virtual unsigned int GetInsertID() =0;
12.25 +
12.26 + /**
12.27 + * @brief Locks the database for an atomic query+retrieval operation.
12.28 + *
12.29 + * @return True on success, false if not supported.
12.30 + */
12.31 + virtual bool LockForFullAtomicOperation() =0;
12.32 +
12.33 + /**
12.34 + * @brief Unlocks a locked atomic fetch.
12.35 + */
12.36 + virtual void UnlockFromFullAtomicOperation() =0;
12.37 +
12.38 + /**
12.39 + * @brief Increases the reference count on the database.
12.40 + */
12.41 + virtual void IncReferenceCount() =0;
12.42 +
12.43 + /**
12.44 + * @brief Returns the parent driver.
12.45 + */
12.46 + virtual IDBDriver *GetDriver() =0;
12.47 };
12.48
12.49 /**
12.50 @@ -558,6 +582,25 @@
12.51 * @return An IdentityToken_t identity.
12.52 */
12.53 virtual IdentityToken_t *GetIdentity() =0;
12.54 +
12.55 + /**
12.56 + * @brief Returns whether the driver is thread safe.
12.57 + *
12.58 + * @return True if thread safe, false otherwise.
12.59 + */
12.60 + virtual bool IsThreadSafe() =0;
12.61 +
12.62 + /**
12.63 + * @brief Initializes thread safety for the calling thread.
12.64 + *
12.65 + * @return True on success, false otherwise.
12.66 + */
12.67 + virtual bool InitializeThreadSafety() =0;
12.68 +
12.69 + /**
12.70 + * @brief Shuts down thread safety for the calling thread.
12.71 + */
12.72 + virtual void ShutdownThreadSafety() =0;
12.73 };
12.74
12.75 /**
12.76 @@ -579,14 +622,14 @@
12.77 virtual unsigned int GetInterfaceVersion() =0;
12.78 public:
12.79 /**
12.80 - * @brief Adds a driver to the DBI system.
12.81 + * @brief Adds a driver to the DBI system. Not thread safe.
12.82 *
12.83 * @param pDriver Database driver.
12.84 */
12.85 virtual void AddDriver(IDBDriver *pDriver) =0;
12.86
12.87 /**
12.88 - * @brief Removes a driver from the DBI system.
12.89 + * @brief Removes a driver from the DBI system. Not thread safe.
12.90 *
12.91 * @param pDriver Database driver.
12.92 */
12.93 @@ -602,7 +645,7 @@
12.94 virtual const DatabaseInfo *FindDatabaseConf(const char *name) =0;
12.95
12.96 /**
12.97 - * @brief Tries to connect to a named database.
12.98 + * @brief Tries to connect to a named database. Not thread safe.
12.99 *
12.100 * @param name Named database info.
12.101 * @param pdr Pointer to store the IDBDriver pointer in.
12.102 @@ -623,14 +666,14 @@
12.103 size_t maxlength) =0;
12.104
12.105 /**
12.106 - * @brief Returns the number of drivers loaded.
12.107 + * @brief Returns the number of drivers loaded. Not thread safe.
12.108 *
12.109 * @return Number of drivers loaded.
12.110 */
12.111 virtual unsigned int GetDriverCount() =0;
12.112
12.113 /**
12.114 - * @brief Returns a driver by index.
12.115 + * @brief Returns a driver by index. Not thread safe.
12.116 *
12.117 * @param index Driver index, starting from 0.
12.118 * @return IDBDriver pointer for the given index.
12.119 @@ -638,7 +681,7 @@
12.120 virtual IDBDriver *GetDriver(unsigned int index) =0;
12.121
12.122 /**
12.123 - * @brief Creates a Handle_t of the IDBDriver type.
12.124 + * @brief Creates a Handle_t of the IDBDriver type. Not thread safe.
12.125 *
12.126 * @param type A DBHandleType value.
12.127 * @param ptr A pointer corrresponding to a DBHandleType
12.128 @@ -649,7 +692,8 @@
12.129 virtual Handle_t CreateHandle(DBHandleType type, void *ptr, IdentityToken_t *pToken) =0;
12.130
12.131 /**
12.132 - * @brief Reads an IDBDriver pointer from an IDBDriver handle.
12.133 + * @brief Reads an IDBDriver pointer from an IDBDriver handle. Not
12.134 + * thread safe.
12.135 *
12.136 * @param hndl Handle_t handle to read.
12.137 * @param type A DBHandleType value.
12.138 @@ -670,7 +714,7 @@
12.139
12.140 /**
12.141 * @brief Given a driver name, attempts to find it. If it is not found, SourceMod
12.142 - * will attempt to load it.
12.143 + * will attempt to load it. This function is not thread safe.
12.144 *
12.145 * @param name Driver identifier name.
12.146 * @return IDBDriver pointer on success, NULL otherwise.
12.147 @@ -678,7 +722,8 @@
12.148 virtual IDBDriver *FindOrLoadDriver(const char *driver) =0;
12.149
12.150 /**
12.151 - * @brief Returns the default driver, or NULL if none is set.
12.152 + * @brief Returns the default driver, or NULL if none is set. This
12.153 + * function is not thread safe.
12.154 *
12.155 * @return IDBDriver pointer on success, NULL otherwise.
12.156 */