ソースを参照

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 14 年 前
コミット
fa61ac0071
1 ファイル変更10 行追加0 行削除
  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_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 
+static pthread_cond_t timer_mutex_cond = PTHREAD_COND_INITIALIZER;
+
 static pthread_t expiry_thread;
 static pthread_t expiry_thread;
 
 
 static pthread_attr_t thread_attr;
 static pthread_attr_t thread_attr;
@@ -116,6 +118,8 @@ static void *prioritized_timer_thread (void *data)
 	}
 	}
 #endif
 #endif
 
 
+	pthread_mutex_lock (&timer_mutex);
+	pthread_cond_signal (&timer_mutex_cond);
 	pthread_mutex_unlock (&timer_mutex);
 	pthread_mutex_unlock (&timer_mutex);
 	for (;;) {
 	for (;;) {
 		timer_serialize_lock_fn ();
 		timer_serialize_lock_fn ();
@@ -170,6 +174,12 @@ int corosync_timer_init (
 	res = pthread_create (&expiry_thread, &thread_attr,
 	res = pthread_create (&expiry_thread, &thread_attr,
 		prioritized_timer_thread, NULL);
 		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);
 	return (res);
 }
 }