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

ruby-changes:6763

From: nobu <ko1@a...>
Date: Thu, 31 Jul 2008 01:33:40 +0900 (JST)
Subject: [ruby-changes:6763] Ruby:r18279 (mvm): * include/ruby/mvm.h (rb_thread_lock_t): needed for inter-VM lock.

nobu	2008-07-31 01:33:19 +0900 (Thu, 31 Jul 2008)

  New Revision: 18279

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

  Log:
    * include/ruby/mvm.h (rb_thread_lock_t): needed for inter-VM lock.
    
    * io.c (max_file_descriptor_lock): should be initialized.
    
    * pack.c (pack_unpack): lock for MVM.

  Modified files:
    branches/mvm/ChangeLog
    branches/mvm/include/ruby/mvm.h
    branches/mvm/io.c
    branches/mvm/pack.c
    branches/mvm/thread_pthread.c
    branches/mvm/thread_pthread.h
    branches/mvm/thread_win32.c
    branches/mvm/thread_win32.h

Index: mvm/thread_win32.c
===================================================================
--- mvm/thread_win32.c	(revision 18278)
+++ mvm/thread_win32.c	(revision 18279)
@@ -44,6 +44,13 @@
     return TlsSetValue(ruby_native_thread_key, th);
 }
 
+int
+ruby_native_thread_yield(void)
+{
+    native_thread_yield();
+    return 0;
+}
+
 static void
 Init_native_thread(void)
 {
Index: mvm/thread_win32.h
===================================================================
--- mvm/thread_win32.h	(revision 18278)
+++ mvm/thread_win32.h	(revision 18279)
@@ -22,16 +22,11 @@
 TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
 
 typedef HANDLE rb_thread_id_t;
-typedef CRITICAL_SECTION rb_thread_lock_t;
 typedef struct rb_thread_cond_struct rb_thread_cond_t;
-#define RB_THREAD_LOCK_INITIALIZER {}
 
 typedef struct native_thread_data_struct {
     HANDLE interrupt_event;
 } native_thread_data_t;
 
-int ruby_native_thread_lock(rb_thread_lock_t*);
-int ruby_native_thread_unlock(rb_thread_lock_t*);
-
 #endif /* RUBY_THREAD_WIN32_H */
 
Index: mvm/include/ruby/mvm.h
===================================================================
--- mvm/include/ruby/mvm.h	(revision 18278)
+++ mvm/include/ruby/mvm.h	(revision 18279)
@@ -14,6 +14,25 @@
 
 #define HAVE_MVM 1
 
+#if defined(_WIN32)
+/* Win32 thread */
+typedef CRITICAL_SECTION rb_thread_lock_t;
+#define RB_THREAD_LOCK_INITIALIZER {}
+int ruby_native_thread_lock(rb_thread_lock_t*);
+int ruby_native_thread_unlock(rb_thread_lock_t*);
+int ruby_native_thread_yield(void);
+
+#elif defined(HAVE_PTHREAD_H)
+/* pthread */
+#include <pthread.h>
+typedef pthread_mutex_t rb_thread_lock_t;
+#define RB_THREAD_LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define ruby_native_thread_lock(lock) pthread_mutex_lock(lock)
+#define ruby_native_thread_unlock(lock) pthread_mutex_unlock(lock)
+#define ruby_native_thread_yield() sched_yield()
+
+#endif
+
 typedef struct rb_vm_struct rb_vm_t;
 typedef struct rb_thread_struct rb_thread_t;
 
Index: mvm/ChangeLog
===================================================================
--- mvm/ChangeLog	(revision 18278)
+++ mvm/ChangeLog	(revision 18279)
@@ -1,3 +1,11 @@
+Thu Jul 31 01:33:17 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* include/ruby/mvm.h (rb_thread_lock_t): needed for inter-VM lock.
+
+	* io.c (max_file_descriptor_lock): should be initialized.
+
+	* pack.c (pack_unpack): lock for MVM.
+
 Thu Jul 31 01:25:43 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* thread.c (rb_mutex_unlock_all): mutex is no longer a ruby object.
Index: mvm/thread_pthread.c
===================================================================
--- mvm/thread_pthread.c	(revision 18278)
+++ mvm/thread_pthread.c	(revision 18279)
@@ -128,7 +128,7 @@
 
 #define native_cleanup_push pthread_cleanup_push
 #define native_cleanup_pop  pthread_cleanup_pop
-#define native_thread_yield() sched_yield()
+#define native_thread_yield() ruby_native_thread_yield()
 
 #ifndef __CYGWIN__
 static void add_signal_thread_list(rb_thread_t *th);
Index: mvm/thread_pthread.h
===================================================================
--- mvm/thread_pthread.h	(revision 18278)
+++ mvm/thread_pthread.h	(revision 18279)
@@ -13,16 +13,11 @@
 
 #include <pthread.h>
 typedef pthread_t rb_thread_id_t;
-typedef pthread_mutex_t rb_thread_lock_t;
 typedef pthread_cond_t rb_thread_cond_t;
-#define RB_THREAD_LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
 
 typedef struct native_thread_data_struct {
     void *signal_thread_list;
     pthread_cond_t sleep_cond;
 } native_thread_data_t;
 
-#define ruby_native_thread_lock(lock) pthread_mutex_lock(lock)
-#define ruby_native_thread_unlock(lock) pthread_mutex_unlock(lock)
-
 #endif /* RUBY_THREAD_PTHREAD_H */
Index: mvm/io.c
===================================================================
--- mvm/io.c	(revision 18278)
+++ mvm/io.c	(revision 18279)
@@ -137,7 +137,7 @@
 };
 
 static int max_file_descriptor = NOFILE;
-static rb_thread_lock_t max_file_descriptor_lock;
+static rb_thread_lock_t max_file_descriptor_lock = RB_THREAD_LOCK_INITIALIZER;
 #define UPDATE_MAXFD(fd) \
     do { \
 	ruby_native_thread_lock(&max_file_descriptor_lock); \
Index: mvm/pack.c
===================================================================
--- mvm/pack.c	(revision 18278)
+++ mvm/pack.c	(revision 18279)
@@ -1149,6 +1149,18 @@
     return s;
 }
 
+static int
+b64_xtable_once(volatile signed char *init, rb_thread_lock_t *lock)
+{
+    signed char t;
+    while ((t = *init) < 0 && (ruby_native_thread_yield(), 1));
+    if (t > 0) return 0;
+    ruby_native_thread_lock(lock);
+    if (*init <= 0) return 1;
+    ruby_native_thread_unlock(lock);
+    return 0;
+}
+
 /*
  *  call-seq:
  *     str.unpack(format)   => anArray
@@ -1788,8 +1800,9 @@
 		char *ptr = RSTRING_PTR(buf);
 		int a = -1,b = -1,c = 0,d;
 		static signed char b64_xtable[256];
+		static rb_thread_lock_t b64_xtable_lock = RB_THREAD_LOCK_INITIALIZER;
 
-		if (b64_xtable['/'] <= 0) {
+		if (b64_xtable_once(&b64_xtable['/'], &b64_xtable_lock)) {
 		    int i;
 
 		    for (i = 0; i < 256; i++) {
@@ -1798,6 +1811,7 @@
 		    for (i = 0; i < 64; i++) {
 			b64_xtable[(unsigned char)b64_table[i]] = i;
 		    }
+		    ruby_native_thread_unlock(&b64_xtable_lock);
 		}
 		while (s < send) {
 		    a = b = c = d = -1;

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

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