diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-17 22:04:17 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2011-03-17 22:04:17 +0200 |
commit | b170dc2b10df0e66acc5bc0bb89ba2c68a755f12 (patch) | |
tree | 775d3286f301bb2e220b8d1eb8456b34fef1f7ee | |
parent | c6ceb73febc0f5afcd01341a16dca768d5c627cd (diff) |
mutexes fix
-rw-r--r-- | core/events.cpp | 24 | ||||
-rw-r--r-- | core/globals.h | 1 | ||||
-rw-r--r-- | core/main.cpp | 2 | ||||
-rw-r--r-- | core/services.cpp | 6 |
4 files changed, 32 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) { diff --git a/core/globals.h b/core/globals.h index 2700403..a363bb8 100644 --- a/core/globals.h +++ b/core/globals.h @@ -26,4 +26,5 @@ extern std::list<evt_handler*> event_handlers; extern boost::mutex event_handlers_mutex; extern std::list<plugin*> plugins; +extern boost::mutex plugin_list_mutex; #endif
\ No newline at end of file diff --git a/core/main.cpp b/core/main.cpp index 03b314b..73e88f3 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -48,6 +48,8 @@ int on_exit() delete *i; plugins.clear(); } + plugin_list_mutex.unlock(); + service_list_mutex.unlock(); return 0; } diff --git a/core/services.cpp b/core/services.cpp index 42f8fb8..3344ca4 100644 --- a/core/services.cpp +++ b/core/services.cpp @@ -36,7 +36,10 @@ void* CallService(const char *name,void* data) for(std::list<service*>::iterator i = services.begin(); i != end; ++i) { if(!ACE_OS::strcmp((*i)->getName(), name)) + { + service_list_mutex.unlock(); return (*i)->getService()(data); + } } service_list_mutex.unlock(); } @@ -50,7 +53,10 @@ bool ServiceExists(const char *name) std::list<service*>::iterator end = services.end(); for(std::list<service*>::iterator i = services.begin(); i != end; ++i) if(!ACE_OS::strcmp((*i)->getName(), name)) + { + service_list_mutex.unlock(); return true; + } } service_list_mutex.unlock(); return false; |