summaryrefslogtreecommitdiff
path: root/modules/extra/m_mysql.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-01-07 15:57:13 -0500
committerAdam <Adam@anope.org>2011-01-07 15:57:13 -0500
commit44038491264a350a8849e1d7e8547bbdec134d74 (patch)
tree08b3b18d0ff4a4d814e638a882916c07882e16de /modules/extra/m_mysql.cpp
parent9efebe5461fd5985190380d11fd8c3c7a5fba9d6 (diff)
Added db_mysql_live which allows Anope to pull data
from the four main SQL tables in realtime, which effectively gives us "live" SQL. Changed eventfd pipe engine to not use buffered write. Added TryLock to threading engines. Made blocking SQL queries in our SQL API thread-safe.
Diffstat (limited to 'modules/extra/m_mysql.cpp')
-rw-r--r--modules/extra/m_mysql.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
index eba2c0382..12b4dbcc5 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/m_mysql.cpp
@@ -10,7 +10,7 @@
* This module spawns a single thread that is used to execute blocking MySQL queries.
* When a module requests a query to be executed it is added to a list for the thread
* (which never stops looping and sleeing) to pick up and execute, the result of which
- * is inserted in to another queue to be picked up my the main thread. The main thread
+ * is inserted in to another queue to be picked up by the main thread. The main thread
* uses Pipe to become notified through the socket engine when there are results waiting
* to be sent back to the modules requesting the query
*/
@@ -309,15 +309,19 @@ void MySQLService::Run(SQLInterface *i, const Anope::string &query)
SQLResult MySQLService::RunQuery(const Anope::string &query)
{
+ this->Lock.Lock();
if (this->CheckConnection() && !mysql_real_query(this->sql, query.c_str(), query.length()))
{
MYSQL_RES *res = mysql_use_result(this->sql);
+ this->Lock.Unlock();
return MySQLResult(query, res);
}
else
{
- return MySQLResult(query, mysql_error(this->sql));
+ Anope::string error = mysql_error(this->sql);
+ this->Lock.Unlock();
+ return MySQLResult(query, error);
}
}
@@ -370,9 +374,7 @@ void DispatcherThread::Run()
QueryRequest &r = me->QueryRequests.front();
this->Unlock();
- r.service->Lock.Lock();
SQLResult sresult = r.service->RunQuery(r.query);
- r.service->Lock.Unlock();
this->Lock();
if (!me->QueryRequests.empty() && me->QueryRequests.front().query == r.query)
@@ -402,7 +404,7 @@ void MySQLPipe::OnNotify()
const QueryResult &qr = *it;
if (!qr.sqlinterface)
- throw SQLException("NULL qr.interface in MySQLPipe::OnNotify() ?");
+ throw SQLException("NULL qr.sqlinterface in MySQLPipe::OnNotify() ?");
if (qr.result.GetError().empty())
qr.sqlinterface->OnResult(qr.result);