Explorar el Código

Don't unlock mutex in different threads

corosync_timer_init used to lock timer lock and unlock was made in
prioritized_timer_thread. Even this behavior works on Linux, NetBSD is
more strict. Mutex can be unlocked only by thread which locked it.

Solution is to use condition and synchronize start of timer thread and
main thread.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Jan Friesse hace 14 años
padre
commit
fa61ac0071
Se han modificado 1 ficheros con 10 adiciones y 0 borrados
  1. 10 0
      exec/timer.c

+ 10 - 0
exec/timer.c

@@ -83,6 +83,8 @@
 
 static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
 
+static pthread_cond_t timer_mutex_cond = PTHREAD_COND_INITIALIZER;
+
 static pthread_t expiry_thread;
 
 static pthread_attr_t thread_attr;
@@ -116,6 +118,8 @@ static void *prioritized_timer_thread (void *data)
 	}
 #endif
 
+	pthread_mutex_lock (&timer_mutex);
+	pthread_cond_signal (&timer_mutex_cond);
 	pthread_mutex_unlock (&timer_mutex);
 	for (;;) {
 		timer_serialize_lock_fn ();
@@ -170,6 +174,12 @@ int corosync_timer_init (
 	res = pthread_create (&expiry_thread, &thread_attr,
 		prioritized_timer_thread, NULL);
 
+	/*
+	 * Wait for thread to really exec
+	 */
+	pthread_cond_wait (&timer_mutex_cond, &timer_mutex);
+	pthread_mutex_unlock (&timer_mutex);
+
 	return (res);
 }