summaryrefslogtreecommitdiff
path: root/core/events.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2011-03-17 22:04:17 +0200
committerGluzskiy Alexandr <sss123next@list.ru>2011-03-17 22:04:17 +0200
commitb170dc2b10df0e66acc5bc0bb89ba2c68a755f12 (patch)
tree775d3286f301bb2e220b8d1eb8456b34fef1f7ee /core/events.cpp
parentc6ceb73febc0f5afcd01341a16dca768d5c627cd (diff)
mutexes fix
Diffstat (limited to 'core/events.cpp')
-rw-r--r--core/events.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/core/events.cpp b/core/events.cpp
index 4d206c8..a177756 100644
--- a/core/events.cpp
+++ b/core/events.cpp
@@ -40,15 +40,21 @@ bool RegisterEventHandler(int type, EVENT_HANDLER func)
{
if(!event_handlers.empty())
{
+ event_handlers_mutex.lock();
std::list<evt_handler*>::iterator end = event_handlers.end();
for(std::list<evt_handler*>::iterator i = event_handlers.begin(); i != end; ++i)
{
if((*i)->getType() == type)
{
(*i)->AddHandler(func);
+ logger.log(LM_DEBUG, "succesfuly added handler for event %d.\n", type);
+ event_handlers_mutex.unlock();
+ return 0;
}
}
+ event_handlers_mutex.unlock();
}
+ logger.log(LM_DEBUG, "failed to add handler for event %d, event %d not registerd to any plugin or core", type,type);
return true;
}
int RegisterEventType(int type, int specialid)
@@ -56,26 +62,43 @@ int RegisterEventType(int type, int specialid)
plugin *p = NULL;
if(!plugins.empty())
{
+ plugin_list_mutex.lock();
std::list<plugin*>::iterator end = plugins.end();
for(std::list<plugin*>::iterator i = plugins.begin(); i!= end; ++i)
{
if((*i)->get_plugin_id() == specialid)
{
p = *i;
+ logger.log(LM_DEBUG, "special id is right, plugin is in plugin list.\n");
break;
}
}
+ plugin_list_mutex.unlock();
if(!p)
+ {
+ logger.log(LM_DEBUG, "event registration for plugin: %s failed, trying to register event with wrong special id %d, right special id for this plugin is %d.\n", p->get_plugininfo()->name, specialid, p->get_plugininfo()->pluginid);
return 1;
+ }
+ }
+ else
+ {
+ logger.log(LM_DEBUG, "event registration failed, something very bad happened, we have not plugin list\n");
+ return 1;
}
if(!event_handlers.empty())
{
+ event_handlers_mutex.lock();
std::list<evt_handler*>::iterator end = event_handlers.end();
for(std::list<evt_handler*>::iterator i = event_handlers.begin(); i != end; ++i)
{
if((*i)->getType() == type)
+ {
+ logger.log(LM_DEBUG, "event registration for plugin %s failed, event already registered", p->get_plugininfo()->name);
+ event_handlers_mutex.unlock();
return 1;
+ }
}
+ event_handlers_mutex.unlock();
}
event_handlers.push_back(new evt_handler(type));
p->register_event(type);
@@ -86,7 +109,6 @@ void* ExecuteEvent(int type,void* data)
{
if(!event_handlers.empty())
{
- event_handlers_mutex.lock();
std::list<evt_handler*>::iterator end = event_handlers.end();
for(std::list<evt_handler*>::iterator i = event_handlers.begin(); i != end; ++i)
{