yarv-diff:385
From: ko1 atdot.net
Date: 4 Sep 2006 14:54:33 +0900
Subject: [yarv-diff:385] r552 - branches/parallel
Author: ko1
Date: 2006-09-04 14:54:33 +0900 (Mon, 04 Sep 2006)
New Revision: 552
Modified:
branches/parallel/ChangeLog
branches/parallel/thread.c
branches/parallel/thread_pthread.h
Log:
* thread_pthread.h : cleanup lock and condition variable at termination
* thread.c : ditto
* thread.c : fix gc barrier
Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog 2006-09-04 03:13:56 UTC (rev 551)
+++ branches/parallel/ChangeLog 2006-09-04 05:54:33 UTC (rev 552)
@@ -4,6 +4,15 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-09-04(Mon) 14:46:29 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * thread_pthread.h : cleanup lock and condition variable at termination
+
+ * thread.c : ditto
+
+ * thread.c : fix gc barrier
+
+
2006-09-04(Mon) 12:05:33 +0900 Koichi Sasada <ko1 atdot.net>
* common.mk : add "loop" rule and fix "run.gdb" rule
Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c 2006-09-04 03:13:56 UTC (rev 551)
+++ branches/parallel/thread.c 2006-09-04 05:54:33 UTC (rev 552)
@@ -154,9 +154,7 @@
else {
thread_debug("rb_thread_global_lock_acquire: try acquire (%p) --> \n",
vm->lock_owner_thread);
- if (native_mutex_lock(&vm->global_interpreter_lock) != 0) {
- rb_bug("native_mutex_lock return non-zero");
- }
+ native_mutex_lock(&vm->global_interpreter_lock);
vm->lock_owner_thread = th;
thread_debug("rb_thread_global_lock_acquire: <-- done\n");
return 1;
@@ -175,9 +173,7 @@
}
thread_debug("rb_thread_global_lock_release: release\n");
vm->lock_owner_thread = 0;
- if (native_mutex_unlock(&vm->global_interpreter_lock) != 0) {
- rb_bug("native_mutex_unlock return non-zero");
- }
+ native_mutex_unlock(&vm->global_interpreter_lock);
return 1;
}
@@ -251,7 +247,10 @@
rb_thread_gc_barrier_start(yarv_thread_t *th)
{
yarv_vm_t *vm = GET_VM();
+ yarv_thread_t *old_owner_th = vm->lock_owner_thread;
+
thread_debug("rb_thread_gc_barrier_start: start\n");
+
if (rb_thread_alone() || vm->living_threads == 0) {
/* skip */
}
@@ -263,6 +262,7 @@
}
vm->interrupt_gc_flag = 1;
+ old_owner_th = vm->lock_owner_thread;
vm->lock_owner_thread = 0;
while (vm->living_threads->num_entries != vm->num_wait_threads + 1) {
@@ -274,7 +274,7 @@
vm->living_threads->num_entries, vm->num_wait_threads);
}
}
- vm->lock_owner_thread = th;
+ vm->lock_owner_thread = old_owner_th;
thread_debug("rb_thread_gc_barrier_start: end\n");
}
Modified: branches/parallel/thread_pthread.h
===================================================================
--- branches/parallel/thread_pthread.h 2006-09-04 03:13:56 UTC (rev 551)
+++ branches/parallel/thread_pthread.h 2006-09-04 05:54:33 UTC (rev 552)
@@ -8,8 +8,8 @@
typedef pthread_mutex_t yarv_thread_lock_t;
typedef pthread_cond_t yarv_thread_cond_t;
-#define native_mutex_lock pthread_mutex_lock
-#define native_mutex_unlock pthread_mutex_unlock
+void native_mutex_lock(yarv_thread_lock_t *lock);
+void native_mutex_unlock(yarv_thread_lock_t *lock);
#define native_mutex_trylock pthread_mutex_trylock
#define native_mutex_destroy pthread_mutex_destroy
@@ -64,6 +64,34 @@
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
void
+native_mutex_lock(yarv_thread_lock_t *lock)
+{
+ int r;
+ switch (r = pthread_mutex_trylock(lock)) {
+ case EBUSY:
+ if ((r = pthread_mutex_lock(lock)) != 0) {
+ rb_bug("pthread_mutex_lock: %d", r);
+ }
+ break;
+ case 0:
+ break;
+ default:
+ rb_bug("pthread_mutex_trylock: %d", r);
+ }
+}
+
+void
+native_mutex_unlock(yarv_thread_lock_t *lock)
+{
+ int r;
+ if ((r = pthread_mutex_unlock(lock)) != 0) {
+ char *c=0; *c=0;
+ rb_bug("native_mutex_unlock return non-zero: %d", r);
+ }
+}
+
+
+void
native_mutex_initialize(pthread_mutex_t *lock)
{
pthread_mutex_init(lock, 0);
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml