e$B$J$+$@$G$9!#e(B
At Mon, 23 Jul 2007 12:54:43 +0900,
Hidetoshi NAGAI wrote in [ruby-dev:31276]:
e$B0l$D$O!$30It%i%$%V%i%j$,$=$NFbIt%k!<%A%s$Ge(B native thread e$B$re(B
e$B@8@.$9$k2DG=@-$,$"$k%1!<%9$G$9!%e(B
ruby e$B$X$Ne(B call e$B$,0l@ZL5$$$3$H$,J]>Z$5$l$k$J$i$$$$$N$G$9$,!$e(B
e$B$=$&$G$J$$>l9g$K$OKh2s$N%A%’%C%/$rI,MW$H$9$k2DG=@-$,$"$j$^$9!%e(B
native threade$B$+$ie(Bruby
threade$B$K7k$S$D$1$kJ}K!$,$"$C$?$[$&$,$$$$e(B
e$B$G$9$+e(B?
e$B!!$"$H!“e(Bis_* e$B$H$$$&L>A0$O$”$l$J$N$G!"=PMh$l$Pe(B rb_ e$B$,$D$$$?%J%$e(B
e$B%9$JL>A0$K$J$k$H$$$$$J$!!"$H$O;W$$$^$9!#8_49@-$NE@$+$iFq$7$$$+$J!#e(B
e$B$3$l$OJQ99$7$A$c$C$F$b$$$$$H;W$$$^$9!%e(B
is_ruby_native_thread() e$B$G$N%A%’%C%/$rI,MW$H$9$k$h$&$J%i%$%V%i%j$O!$e(B
1.9 e$BBP1~$N$?$a$K$O!$B?J,!$$=$l$J$j$NNL$N=q$-D>$7$rI,MW$H$9$k$G$7$g$&$+$i!%e(B
e$B$J$K$,$$$$$G$9$+$M$’!#e(B
Index: thread.c
— thread.c (revision 12839)
+++ thread.c (working copy)
@@ -2966,4 +2966,4 @@ int
is_ruby_native_thread(void)
{
- return ruby_thread_from_native() ? Qtrue : Qfalse;
}
Index: thread_pthread.ci
===================================================================
— thread_pthread.ci (revision 12839)
+++ thread_pthread.ci (working copy)
@@ -73,4 +73,6 @@ static void remove_signal_thread_list(rb
static rb_thread_lock_t signal_thread_list_lock;
+static pthread_key_t ruby_native_thread_key;
+
static void
null_func()
@@ -80,11 +82,28 @@ null_func()
static void
-Init_native_thread()
+init_ruby_nathive_thread_key(void)
+{
- pthread_key_create(&ruby_native_thread_key, NULL);
+}
-
+static void
+Init_native_thread(void)
{
- GET_THREAD()->thread_id = pthread_self();
- pthread_once_t key_once = PTHREAD_ONCE_INIT;
- rb_thread_t *th = GET_THREAD();
-
- pthread_once(&key_once, init_ruby_nathive_thread_key);
- th->thread_id = pthread_self();
- pthread_setspecific(ruby_native_thread_key, th);
native_mutex_initialize(&signal_thread_list_lock);
posix_signal(SIGVTALRM, null_func);
}
+static rb_thread_t *
+ruby_thread_from_native(void)
+{
- return pthread_getspecific(ruby_native_thread_key);
+}
-
static void
native_thread_destroy(rb_thread_t *th)
Index: thread_win32.ci
— thread_win32.ci (revision 12839)
+++ thread_win32.ci (working copy)
@@ -21,8 +21,24 @@
#define remove_signal_thread_list(th)
+static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
+
static void
Init_native_thread()
{
- static LONG wait_flag = -1;
rb_thread_t *th = GET_THREAD();
-
- while (ruby_native_thread_key == TLS_OUT_OF_INDEXES) {
- if (InterlockedIncrement(&wait_flag) > 0) {
-
InterlockedDecrement(&wait_flag);
-
Sleep(1);
- }
- else {
-
ruby_native_thread_key = TlsAlloc();
-
InterlockedDecrement(&wait_flag);
-
break;
- }
- }
- TlsSetValue(ruby_native_thread_key, th);
DuplicateHandle(GetCurrentProcess(),
GetCurrentThread(),
@@ -37,4 +53,10 @@ Init_native_thread()
}
+static rb_thread_t *
+ruby_thread_from_native(void)
+{
- return TlsGetValue(ruby_native_thread_key);
+}
-
static void
w32_error(void)