[icinga-checkins] icinga.org: icinga-core/master: Implemented eventloop mutex.

git at icinga.org git at icinga.org
Wed Nov 9 16:44:45 CET 2011


Module: icinga-core
Branch: master
Commit: 124eb0df0b17dd8177c69ff45341ba098eb79eb5
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=124eb0df0b17dd8177c69ff45341ba098eb79eb5

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Oct 25 13:39:38 2011 +0200

Implemented eventloop mutex.

This will be used by IcingaMQ to make sure that no other thread
is running any Icinga code while executing API commands.

Refs #2040

---

 base/events.c    |   10 ++++++++++
 include/icinga.h |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/base/events.c b/base/events.c
index d40898c..d567a89 100644
--- a/base/events.c
+++ b/base/events.c
@@ -105,6 +105,8 @@ extern service  *service_list;
 
 sched_info scheduling_info;
 
+pthread_mutex_t icinga_eventloop_lock = PTHREAD_MUTEX_INITIALIZER;
+
 
 
 /******************************************************************/
@@ -1093,6 +1095,8 @@ int event_execution_loop(void) {
 
 	time(&last_time);
 
+	pthread_mutex_lock(&icinga_eventloop_lock);
+
 	/* initialize fake "sleep" event */
 	sleep_event.event_type = EVENT_SLEEP;
 	sleep_event.run_time = last_time;
@@ -1361,12 +1365,16 @@ int event_execution_loop(void) {
 			broker_timed_event(NEBTYPE_TIMEDEVENT_SLEEP, NEBFLAG_NONE, NEBATTR_NONE, &sleep_event, NULL);
 #endif
 
+			pthread_mutex_unlock(&icinga_eventloop_lock);
+
 			/* wait a while so we don't hog the CPU... */
 #ifdef USE_NANOSLEEP
 			nanosleep(&delay, NULL);
 #else
 			sleep((unsigned int)delay.tv_sec);
 #endif
+
+			pthread_mutex_lock(&icinga_eventloop_lock);
 		}
 
 		/* update status information occassionally - NagVis watches the NDOUtils DB to see if Icinga is alive */
@@ -1385,6 +1393,8 @@ int event_execution_loop(void) {
 
 	log_debug_info(DEBUGL_FUNCTIONS, 0, "event_execution_loop() end\n");
 
+	pthread_mutex_unlock(&icinga_eventloop_lock);
+
 	return OK;
 }
 
diff --git a/include/icinga.h b/include/icinga.h
index 0d2ce8d..eef80ad 100644
--- a/include/icinga.h
+++ b/include/icinga.h
@@ -733,6 +733,8 @@ char *get_program_version(void);
 char *get_program_modification_date(void);
 int has_shell_metachars(const char *);
 
+extern pthread_mutex_t icinga_eventloop_lock;
+
 
 #ifdef __cplusplus
 }





More information about the icinga-checkins mailing list