class SQLConnection;
class MySQLListener;
+
typedef std::map<std::string, SQLConnection*> ConnMap;
static MySQLListener *MessagePipe = NULL;
int QueueFD = -1;
Mutex* QueueMutex;
Mutex* ResultsMutex;
Mutex* LoggingMutex;
+ Mutex* ConnMutex;
ModuleSQL(InspIRCd* Me);
~ModuleSQL();
void LoadDatabases(ConfigReader* conf, InspIRCd* ServerInstance, ModuleSQL* Parent)
{
+ Parent->ConnMutex->Lock();
ClearOldConnections(conf);
for (int j =0; j < conf->Enumerate("database"); j++)
{
}
}
ConnectDatabases(ServerInstance, Parent);
+ Parent->ConnMutex->Unlock();
}
char FindCharId(const std::string &id)
* The function GetCharId translates a single character
* back into an iterator.
*/
+
if (Instance->SE->Recv(this, &data, 1, 0) > 0)
{
+ Parent->ConnMutex->Lock();
ConnMap::iterator iter = GetCharId(data);
if (iter != Connections.end())
{
delete (*n);
iter->second->rq.pop_front();
Parent->ResultsMutex->Unlock();
+ Parent->ConnMutex->Unlock();
return true;
}
/* No error, but unknown id */
+ Parent->ConnMutex->Unlock();
return true;
}
MessagePipe = new MySQLListener(this, ServerInstance, 0, "127.0.0.1");
#endif
+ LoggingMutex = ServerInstance->Mutexes->CreateMutex();
+ ConnMutex = ServerInstance->Mutexes->CreateMutex();
+
if (MessagePipe->GetFd() == -1)
+ {
+ delete ConnMutex;
+ ServerInstance->Modules->DoneWithInterface("SQLutils");
throw ModuleException("m_mysql: unable to create ITC pipe");
+ }
else
+ {
+ LoggingMutex->Lock();
ServerInstance->Logs->Log("m_mysql", DEBUG, "MySQL: Interthread comms port is %d", MessagePipe->GetPort());
+ LoggingMutex->Unlock();
+ }
Dispatcher = new DispatcherThread(ServerInstance, this);
ServerInstance->Threads->Create(Dispatcher);
- LoggingMutex = ServerInstance->Mutexes->CreateMutex();
ResultsMutex = ServerInstance->Mutexes->CreateMutex();
QueueMutex = ServerInstance->Mutexes->CreateMutex();
/* Tell worker thread to exit NOW,
* Automatically joins */
delete Dispatcher;
+ delete LoggingMutex;
+ delete ResultsMutex;
+ delete QueueMutex;
+ delete ConnMutex;
+ ServerInstance->Modules->DoneWithInterface("SQLutils");
throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
}
delete LoggingMutex;
delete ResultsMutex;
delete QueueMutex;
+ delete ConnMutex;
}
unsigned long ModuleSQL::NewID()
const char* returnval = NULL;
+ ConnMutex->Lock();
if((iter = Connections.find(req->dbid)) != Connections.end())
{
req->id = NewID();
req->error.Id(SQL_BAD_DBID);
}
+ ConnMutex->Unlock();
QueueMutex->Unlock();
- /* XXX: Unlock */
return returnval;
}
SQLConnection* conn = NULL;
/* XXX: Lock here for safety */
Parent->QueueMutex->Lock();
+ Parent->ConnMutex->Lock();
for (ConnMap::iterator i = Connections.begin(); i != Connections.end(); i++)
{
if (i->second->queue.totalsize())
break;
}
}
+ Parent->ConnMutex->Unlock();
Parent->QueueMutex->Unlock();
/* XXX: Unlock */