Преглед изворни кода

Rework of the timer system to allow timers to be added in dispatch handlers.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1099 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake пре 19 година
родитељ
комит
ba70bff546
2 измењених фајлова са 8 додато и 11 уклоњено
  1. 6 11
      exec/timer.c
  2. 2 0
      exec/totempg.c

+ 6 - 11
exec/timer.c

@@ -87,8 +87,6 @@ static pthread_attr_t thread_attr;
 
 
 static struct timerlist timers_timerlist;
 static struct timerlist timers_timerlist;
 
 
-static int in_expiry = 0;
-
 static void (*timer_serialize_lock_fn) (void);
 static void (*timer_serialize_lock_fn) (void);
 
 
 static void (*timer_serialize_unlock_fn) (void);
 static void (*timer_serialize_unlock_fn) (void);
@@ -111,7 +109,9 @@ static void *prioritized_timer_thread (void *data)
 	pthread_mutex_unlock (&timer_mutex);
 	pthread_mutex_unlock (&timer_mutex);
 	for (;;) {
 	for (;;) {
 retry_poll:
 retry_poll:
+		timer_serialize_lock_fn ();
 		timeout = timerlist_timeout_msec (&timers_timerlist);
 		timeout = timerlist_timeout_msec (&timers_timerlist);
+		timer_serialize_unlock_fn ();
 		fds = poll (NULL, 0, timeout);
 		fds = poll (NULL, 0, timeout);
 		if (fds == -1) {
 		if (fds == -1) {
 			goto retry_poll;
 			goto retry_poll;
@@ -119,9 +119,7 @@ retry_poll:
 		pthread_mutex_lock (&timer_mutex);
 		pthread_mutex_lock (&timer_mutex);
 		timer_serialize_lock_fn ();
 		timer_serialize_lock_fn ();
 
 
-		in_expiry = 1;
 		timerlist_expire (&timers_timerlist);
 		timerlist_expire (&timers_timerlist);
-		in_expiry = 0;
 		
 		
 		timer_serialize_unlock_fn ();
 		timer_serialize_unlock_fn ();
 		pthread_mutex_unlock (&timer_mutex);
 		pthread_mutex_unlock (&timer_mutex);
@@ -149,7 +147,7 @@ int openais_timer_init (
 
 
 	pthread_mutex_lock (&timer_mutex);
 	pthread_mutex_lock (&timer_mutex);
         pthread_attr_init (&thread_attr);
         pthread_attr_init (&thread_attr);
-        pthread_attr_setstacksize (&thread_attr, 8192);
+        pthread_attr_setstacksize (&thread_attr, 100000);
         pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
         pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
         res = pthread_create (&expiry_thread, &thread_attr,
         res = pthread_create (&expiry_thread, &thread_attr,
 		prioritized_timer_thread, NULL);
 		prioritized_timer_thread, NULL);
@@ -166,8 +164,7 @@ int openais_timer_add (
 	int res;
 	int res;
 	int unlock;
 	int unlock;
 
 
-	if (in_expiry == 1 &&
-		pthread_equal (pthread_self(), expiry_thread) == 0) {
+	if (pthread_equal (pthread_self(), expiry_thread) == 0) {
 		unlock = 0;
 		unlock = 0;
 	} else {
 	} else {
 		unlock = 1;
 		unlock = 1;
@@ -199,8 +196,7 @@ void openais_timer_delete (
 		return;
 		return;
 	}
 	}
 
 
-	if (in_expiry == 1 &&
-		pthread_equal (pthread_self(), expiry_thread) == 0) {
+	if (pthread_equal (pthread_self(), expiry_thread) == 0) {
 		unlock = 0;
 		unlock = 0;
 	} else {
 	} else {
 		unlock = 1;
 		unlock = 1;
@@ -222,8 +218,7 @@ void openais_timer_delete_data (
 	if (timer_handle == 0) {
 	if (timer_handle == 0) {
 		return;
 		return;
 	}
 	}
-	if (in_expiry == 1 &&
-		pthread_equal (pthread_self(), expiry_thread) == 0) {
+	if (pthread_equal (pthread_self(), expiry_thread) == 0) {
 		unlock = 0;
 		unlock = 0;
 	} else {
 	} else {
 		unlock = 1;
 		unlock = 1;

+ 2 - 0
exec/totempg.c

@@ -1029,6 +1029,7 @@ int totempg_groups_send_ok_joined (
 	unsigned int res;
 	unsigned int res;
 
 
 	pthread_mutex_lock (&totempg_mutex);
 	pthread_mutex_lock (&totempg_mutex);
+	pthread_mutex_lock (&mcast_msg_mutex);
 	res = hdb_handle_get (&totempg_groups_instance_database, handle,
 	res = hdb_handle_get (&totempg_groups_instance_database, handle,
 		(void *)&instance);
 		(void *)&instance);
 	if (res != 0) {
 	if (res != 0) {
@@ -1047,6 +1048,7 @@ int totempg_groups_send_ok_joined (
 	hdb_handle_put (&totempg_groups_instance_database, handle);
 	hdb_handle_put (&totempg_groups_instance_database, handle);
 
 
 error_exit:
 error_exit:
+	pthread_mutex_unlock (&mcast_msg_mutex);
 	pthread_mutex_unlock (&totempg_mutex);
 	pthread_mutex_unlock (&totempg_mutex);
 	return (res);
 	return (res);
 }
 }