Permalink
Browse files

* thread.c (is_ruby_native_thread): check properly. [ruby-dev:31166]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 2c5ae0e commit 6fc746d7e32243b4c46ac5ef9fee4806664fd7e6 @nobu nobu committed Aug 18, 2007
Showing with 45 additions and 4 deletions.
  1. +4 −0 ChangeLog
  2. +4 −1 thread.c
  3. +20 −2 thread_pthread.ci
  4. +17 −1 thread_win32.ci
View
@@ -1,3 +1,7 @@
+Sat Aug 18 17:40:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * thread.c (is_ruby_native_thread): check properly. [ruby-dev:31166]
+
Sat Aug 18 16:44:15 2007 Koichi Sasada <ko1@atdot.net>
* insnhelper.ci (vm_call_bmethod),
View
@@ -3002,5 +3002,8 @@ Init_Thread(void)
int
is_ruby_native_thread(void)
{
- return Qtrue;
+ rb_thread_t *rb_thread_check_ptr(rb_thread_t *ptr);
+ rb_thread_t *th = ruby_thread_from_native();
+
+ return th ? Qtrue : Qfalse;
}
View
@@ -72,16 +72,34 @@ static void remove_signal_thread_list(rb_thread_t *th);
static rb_thread_lock_t signal_thread_list_lock;
+static pthread_key_t ruby_native_thread_key;
+
static void
null_func()
{
/* null */
}
+static rb_thread_t *
+ruby_thread_from_native(void)
+{
+ return pthread_getspecific(ruby_native_thread_key);
+}
+
+static int
+ruby_thread_set_native(rb_thread_t *th)
+{
+ return pthread_setspecific(ruby_native_thread_key, th) == 0;
+}
+
static void
-Init_native_thread()
+Init_native_thread(void)
{
- GET_THREAD()->thread_id = pthread_self();
+ rb_thread_t *th = GET_THREAD();
+
+ pthread_key_create(&ruby_native_thread_key, NULL);
+ th->thread_id = pthread_self();
+ ruby_thread_set_native(th);
native_mutex_initialize(&signal_thread_list_lock);
posix_signal(SIGVTALRM, null_func);
}
View
@@ -20,10 +20,26 @@
#define native_thread_yield() Sleep(0)
#define remove_signal_thread_list(th)
+static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
+
+static rb_thread_t *
+ruby_thread_from_native(void)
+{
+ return TlsGetValue(ruby_native_thread_key);
+}
+
+static int
+ruby_thread_set_native(rb_thread_t *th)
+{
+ return TlsSetValue(ruby_native_thread_key, th);
+}
+
static void
-Init_native_thread()
+Init_native_thread(void)
{
rb_thread_t *th = GET_THREAD();
+
+ ruby_native_thread_key = TlsAlloc();
DuplicateHandle(GetCurrentProcess(),
GetCurrentThread(),
GetCurrentProcess(),

0 comments on commit 6fc746d

Please sign in to comment.