ruby-changes:6719
From: mame <ko1@a...>
Date: Mon, 28 Jul 2008 00:24:34 +0900 (JST)
Subject: [ruby-changes:6719] Ruby:r18235 (trunk): * vm_core.h, thread.c: It is now prohibited to use Data_Get_Struct in
mame 2008-07-28 00:20:01 +0900 (Mon, 28 Jul 2008) New Revision: 18235 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18235 Log: * vm_core.h, thread.c: It is now prohibited to use Data_Get_Struct in *_free against an object that is going to be free'ed. So, change type of thread_t#keeping_mutexes from VALUE to mutex_t. * vm.c: remove mark to keeping_mutexes. Modified files: trunk/ChangeLog trunk/thread.c trunk/vm.c trunk/vm_core.h Index: ChangeLog =================================================================== --- ChangeLog (revision 18234) +++ ChangeLog (revision 18235) @@ -1,3 +1,11 @@ +Mon Jul 28 00:18:47 2008 Yusuke Endoh <mame@t...> + + * vm_core.h, thread.c: It is now prohibited to use Data_Get_Struct in + *_free against an object that is going to be free'ed. So, change type + of thread_t#keeping_mutexes from VALUE to mutex_t. + + * vm.c: remove mark to keeping_mutexes. + Sun Jul 27 23:32:42 2008 Yusuke Endoh <mame@t...> * test/openssl/test_ssl.rb (server_loop): rescue Errno::EINVAL and Index: vm_core.h =================================================================== --- vm_core.h (revision 18234) +++ vm_core.h (revision 18235) @@ -396,6 +396,8 @@ void *arg; }; +struct rb_mutex_struct; + struct rb_thread_struct { VALUE self; @@ -443,7 +445,7 @@ rb_thread_lock_t interrupt_lock; struct rb_unblock_callback unblock; VALUE locking_mutex; - VALUE keeping_mutexes; + struct rb_mutex_struct *keeping_mutexes; int transition_for_lock; struct rb_vm_tag *tag; @@ -496,6 +498,15 @@ int abort_on_exception; }; +struct rb_mutex_struct +{ + rb_thread_lock_t lock; + rb_thread_cond_t cond; + struct rb_thread_struct volatile *th; + volatile int cond_waiting, cond_notified; + struct rb_mutex_struct *next_mutex; +}; + /* iseq.c */ VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE); VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE); Index: thread.c =================================================================== --- thread.c (revision 18234) +++ thread.c (revision 18235) @@ -62,7 +62,9 @@ struct timeval rb_time_interval(VALUE); static int rb_thread_dead(rb_thread_t *th); -static void rb_mutex_unlock_all(VALUE); +typedef struct rb_mutex_struct mutex_t; + +static void rb_mutex_unlock_all(mutex_t *mutex); static void rb_check_deadlock(rb_vm_t *vm); void rb_signal_exec(rb_thread_t *th, int sig); @@ -402,7 +404,7 @@ /* unlock all locking mutexes */ if (th->keeping_mutexes) { rb_mutex_unlock_all(th->keeping_mutexes); - th->keeping_mutexes = Qfalse; + th->keeping_mutexes = NULL; } /* delete self from living_threads */ @@ -2485,32 +2487,12 @@ * */ -typedef struct mutex_struct { - rb_thread_lock_t lock; - rb_thread_cond_t cond; - rb_thread_t volatile *th; - volatile int cond_waiting, cond_notified; - VALUE next_mutex; -} mutex_t; - #define GetMutexPtr(obj, tobj) \ Data_Get_Struct(obj, mutex_t, tobj) static const char *mutex_unlock(mutex_t *mutex); static void -mutex_mark(void *ptr) -{ - if (ptr) { - mutex_t *mutex = ptr; - rb_gc_mark(mutex->next_mutex); - if (mutex->th) { - rb_gc_mark(mutex->th->self); - } - } -} - -static void mutex_free(void *ptr) { if (ptr) { @@ -2531,7 +2513,7 @@ VALUE volatile obj; mutex_t *mutex; - obj = Data_Make_Struct(klass, mutex_t, mutex_mark, mutex_free, mutex); + obj = Data_Make_Struct(klass, mutex_t, NULL, mutex_free, mutex); native_mutex_initialize(&mutex->lock); native_cond_initialize(&mutex->cond); return obj; @@ -2572,12 +2554,13 @@ static void mutex_locked(rb_thread_t *th, VALUE self) { + mutex_t *mutex; + GetMutexPtr(self, mutex); + if (th->keeping_mutexes) { - mutex_t *mutex; - GetMutexPtr(self, mutex); mutex->next_mutex = th->keeping_mutexes; } - th->keeping_mutexes = self; + th->keeping_mutexes = mutex; } /* @@ -2743,14 +2726,14 @@ native_mutex_unlock(&mutex->lock); if (!err) { - GetMutexPtr(th->keeping_mutexes, th_mutex); + th_mutex = th->keeping_mutexes; if (th_mutex == mutex) { th->keeping_mutexes = mutex->next_mutex; } else { while (1) { mutex_t *tmp_mutex; - GetMutexPtr(th_mutex->next_mutex, tmp_mutex); + tmp_mutex = th_mutex->next_mutex; if (tmp_mutex == mutex) { th_mutex->next_mutex = tmp_mutex->next_mutex; break; @@ -2785,13 +2768,13 @@ } static void -rb_mutex_unlock_all(VALUE mutexes) +rb_mutex_unlock_all(mutex_t *mutexes) { const char *err; mutex_t *mutex; while (mutexes) { - GetMutexPtr(mutexes, mutex); + mutex = mutexes; /* rb_warn("mutex #<%s:%p> remains to be locked by terminated thread", rb_obj_classname(mutexes), (void*)mutexes); */ mutexes = mutex->next_mutex; Index: vm.c =================================================================== --- vm.c (revision 18234) +++ vm.c (revision 18235) @@ -1478,7 +1478,7 @@ if (th->locking_mutex != Qfalse) { rb_bug("thread_free: locking_mutex must be NULL (%p:%ld)", th, th->locking_mutex); } - if (th->keeping_mutexes != Qfalse) { + if (th->keeping_mutexes != NULL) { rb_bug("thread_free: keeping_mutexes must be NULL (%p:%ld)", th, th->locking_mutex); } @@ -1551,7 +1551,6 @@ RUBY_MARK_UNLESS_NULL(th->last_status); RUBY_MARK_UNLESS_NULL(th->locking_mutex); - RUBY_MARK_UNLESS_NULL(th->keeping_mutexes); rb_mark_tbl(th->local_storage); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/