[前][次][番号順一覧][スレッド一覧]

ruby-changes:19433

From: kosaki <ko1@a...>
Date: Sun, 8 May 2011 10:50:42 +0900 (JST)
Subject: [ruby-changes:19433] Ruby:r31473 (trunk): * thread_pthread.c: cleanup signal_thread_list related ifdef.

kosaki	2011-05-08 10:50:36 +0900 (Sun, 08 May 2011)

  New Revision: 31473

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31473

  Log:
    * thread_pthread.c: cleanup signal_thread_list related ifdef.
      1) we don't have to use #ifdef FOO-PLATFORM directly 2) About
      half #ifdef didn't care symbian properly.

  Modified files:
    trunk/ChangeLog
    trunk/thread_pthread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31472)
+++ ChangeLog	(revision 31473)
@@ -1,3 +1,9 @@
+Sun May  8 10:24:16 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* thread_pthread.c: cleanup signal_thread_list related ifdef.
+	  1) we don't have to use #ifdef FOO-PLATFORM directly 2) About
+	  half #ifdef didn't care symbian properly.
+
 Sun May  8 05:19:37 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* test/io/wait/test_io_wait.rb: Linux socketpair(2) only support
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 31472)
+++ thread_pthread.c	(revision 31473)
@@ -362,12 +362,14 @@
 #define native_thread_yield() ((void)0)
 #endif
 
-#ifndef __CYGWIN__
+#if defined(SIGVTALRM) && !defined(__CYGWIN__) && !defined(__SYMBIAN32__)
+#define USE_SIGNAL_THREAD_LIST 1
+#endif
+#ifdef USE_SIGNAL_THREAD_LIST
 static void add_signal_thread_list(rb_thread_t *th);
-#endif
 static void remove_signal_thread_list(rb_thread_t *th);
-
 static rb_thread_lock_t signal_thread_list_lock;
+#endif
 
 static pthread_key_t ruby_native_thread_key;
 
@@ -399,7 +401,9 @@
     pthread_key_create(&ruby_native_thread_key, NULL);
     th->thread_id = pthread_self();
     native_thread_init(th);
+#ifdef USE_SIGNAL_THREAD_LIST
     native_mutex_initialize(&signal_thread_list_lock);
+#endif
     posix_signal(SIGVTALRM, null_func);
 }
 
@@ -808,27 +812,6 @@
     native_cond_signal(&th->native_thread_data.sleep_cond);
 }
 
-#if !defined(__CYGWIN__) && !defined(__SYMBIAN32__)
-static void
-ubf_select_each(rb_thread_t *th)
-{
-    thread_debug("ubf_select_each (%p)\n", (void *)th->thread_id);
-    if (th) {
-	pthread_kill(th->thread_id, SIGVTALRM);
-    }
-}
-
-static void
-ubf_select(void *ptr)
-{
-    rb_thread_t *th = (rb_thread_t *)ptr;
-    add_signal_thread_list(th);
-    ubf_select_each(th);
-}
-#else
-#define ubf_select 0
-#endif
-
 #define PER_NANO 1000000000
 
 static void
@@ -874,17 +857,16 @@
     thread_debug("native_sleep done\n");
 }
 
+#ifdef USE_SIGNAL_THREAD_LIST
 struct signal_thread_list {
     rb_thread_t *th;
     struct signal_thread_list *prev;
     struct signal_thread_list *next;
 };
 
-#ifndef __CYGWIN__
 static struct signal_thread_list signal_thread_list_anchor = {
     0, 0, 0,
 };
-#endif
 
 #define FGLOCK(lock, body) do { \
     native_mutex_lock(lock); \
@@ -909,7 +891,6 @@
 }
 #endif
 
-#ifndef __CYGWIN__
 static void
 add_signal_thread_list(rb_thread_t *th)
 {
@@ -935,7 +916,6 @@
 	});
     }
 }
-#endif
 
 static void
 remove_signal_thread_list(rb_thread_t *th)
@@ -955,11 +935,46 @@
 	    free(list); /* ok */
 	});
     }
-    else {
-	/* */
+}
+
+static void
+ubf_select_each(rb_thread_t *th)
+{
+    thread_debug("ubf_select_each (%p)\n", (void *)th->thread_id);
+    if (th) {
+	pthread_kill(th->thread_id, SIGVTALRM);
     }
 }
 
+static void
+ubf_select(void *ptr)
+{
+    rb_thread_t *th = (rb_thread_t *)ptr;
+    add_signal_thread_list(th);
+    ubf_select_each(th);
+}
+
+static void
+ping_signal_thread_list(void) {
+    if (signal_thread_list_anchor.next) {
+	FGLOCK(&signal_thread_list_lock, {
+	    struct signal_thread_list *list;
+
+	    list = signal_thread_list_anchor.next;
+	    while (list) {
+		ubf_select_each(list->th);
+		list = list->next;
+	    }
+	});
+    }
+}
+#else /* USE_SIGNAL_THREAD_LIST */
+static void add_signal_thread_list(rb_thread_t *th) { }
+static void remove_signal_thread_list(rb_thread_t *th) { }
+#define ubf_select 0
+static void ping_signal_thread_list(void) { }
+#endif /* USE_SIGNAL_THREAD_LIST */
+
 static pthread_t timer_thread_id;
 static rb_thread_cond_t timer_thread_cond;
 static pthread_mutex_t timer_thread_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -987,18 +1002,7 @@
 	}
 	else rb_bug_errno("thread_timer/timedwait", err);
 
-#if !defined(__CYGWIN__) && !defined(__SYMBIAN32__)
-	if (signal_thread_list_anchor.next) {
-	    FGLOCK(&signal_thread_list_lock, {
-		struct signal_thread_list *list;
-		list = signal_thread_list_anchor.next;
-		while (list) {
-		    ubf_select_each(list->th);
-		    list = list->next;
-		}
-	    });
-	}
-#endif
+	ping_signal_thread_list();
 	timer_thread_function(dummy);
     }
     native_mutex_unlock(&timer_thread_lock);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]