- more thread guards for IRC Client
This commit is contained in:
parent
3fed09ab32
commit
9150701e70
|
@ -90,7 +90,8 @@ public:
|
||||||
std::vector<string> & getCachedNickList() { return eventData; }
|
std::vector<string> & getCachedNickList() { return eventData; }
|
||||||
void setCachedNickList(std::vector<string> &list) { eventData = list; }
|
void setCachedNickList(std::vector<string> &list) { eventData = list; }
|
||||||
|
|
||||||
IRCCallbackInterface * getCallbackObj();
|
Mutex * getMutexIRCCB() { return &mutexIRCCB; }
|
||||||
|
IRCCallbackInterface * getCallbackObj(bool lockObj=true);
|
||||||
void setCallbackObj(IRCCallbackInterface *cb);
|
void setCallbackObj(IRCCallbackInterface *cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -191,8 +191,10 @@ void event_channel(irc_session_t * session, const char * event, const char * ori
|
||||||
|
|
||||||
IRCThread *ctx = (IRCThread *)irc_get_ctx(session);
|
IRCThread *ctx = (IRCThread *)irc_get_ctx(session);
|
||||||
if(ctx != NULL) {
|
if(ctx != NULL) {
|
||||||
if(ctx->getCallbackObj() != NULL) {
|
MutexSafeWrapper safeMutex(ctx->getMutexIRCCB());
|
||||||
ctx->getCallbackObj()->IRC_CallbackEvent(IRC_evt_chatText, nickbuf, params, count);
|
IRCCallbackInterface *cb = ctx->getCallbackObj(false);
|
||||||
|
if(cb != NULL) {
|
||||||
|
cb->IRC_CallbackEvent(IRC_evt_chatText, nickbuf, params, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +349,7 @@ void IRCThread::signalQuit() {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC: signalQuit [%p]\n",ircSession);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC: signalQuit [%p]\n",ircSession);
|
||||||
|
|
||||||
if(ircSession != NULL) {
|
if(ircSession != NULL) {
|
||||||
callbackObj=NULL;
|
setCallbackObj(NULL);
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC: Quitting Channel\n");
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC: Quitting Channel\n");
|
||||||
irc_cmd_quit(ircSession, "MG Bot is closing!");
|
irc_cmd_quit(ircSession, "MG Bot is closing!");
|
||||||
BaseThread::signalQuit();
|
BaseThread::signalQuit();
|
||||||
|
@ -411,8 +413,11 @@ std::vector<string> IRCThread::getNickList() {
|
||||||
return nickList;
|
return nickList;
|
||||||
}
|
}
|
||||||
|
|
||||||
IRCCallbackInterface * IRCThread::getCallbackObj() {
|
IRCCallbackInterface * IRCThread::getCallbackObj(bool lockObj) {
|
||||||
MutexSafeWrapper safeMutex(&mutexIRCCB);
|
MutexSafeWrapper safeMutex(NULL);
|
||||||
|
if(lockObj == true) {
|
||||||
|
safeMutex.setMutex(&mutexIRCCB);
|
||||||
|
}
|
||||||
return callbackObj;
|
return callbackObj;
|
||||||
}
|
}
|
||||||
void IRCThread::setCallbackObj(IRCCallbackInterface *cb) {
|
void IRCThread::setCallbackObj(IRCCallbackInterface *cb) {
|
||||||
|
@ -518,9 +523,13 @@ void IRCThread::execute() {
|
||||||
|
|
||||||
// Delete ourself when the thread is done (no other actions can happen after this
|
// Delete ourself when the thread is done (no other actions can happen after this
|
||||||
// such as the mutex which modifies the running status of this method
|
// such as the mutex which modifies the running status of this method
|
||||||
if(getCallbackObj() != NULL) {
|
MutexSafeWrapper safeMutex(&mutexIRCCB);
|
||||||
getCallbackObj()->IRC_CallbackEvent(IRC_evt_exitThread, NULL, NULL, 0);
|
IRCCallbackInterface *cb = getCallbackObj(false);
|
||||||
|
if(cb != NULL) {
|
||||||
|
cb->IRC_CallbackEvent(IRC_evt_exitThread, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue