yarv-diff:392
From: ko1 atdot.net
Date: 7 Sep 2006 23:43:18 +0900
Subject: [yarv-diff:392] r559 - branches/parallel
Author: ko1
Date: 2006-09-07 23:43:17 +0900 (Thu, 07 Sep 2006)
New Revision: 559
Modified:
branches/parallel/ChangeLog
branches/parallel/thread.c
Log:
* thread.c : check that global lock is free when acquiring
global lock
Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog 2006-09-07 11:08:42 UTC (rev 558)
+++ branches/parallel/ChangeLog 2006-09-07 14:43:17 UTC (rev 559)
@@ -4,6 +4,12 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-09-07(Thu) 22:47:20 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * thread.c : check that global lock is free when acquiring
+ global lock
+
+
2006-09-07(Thu) 20:05:33 +0900 Koichi Sasada <ko1 atdot.net>
* configure.in : check pthread_setaffinity_np
Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c 2006-09-07 11:08:42 UTC (rev 558)
+++ branches/parallel/thread.c 2006-09-07 14:43:17 UTC (rev 559)
@@ -149,6 +149,8 @@
rb_thread_global_lock_acquire(yarv_thread_t *th)
{
yarv_vm_t *vm = th->vm;
+ int i;
+
if (vm->lock_owner_thread == th) {
thread_debug("rb_thread_global_lock_acquire: no need (already have)\n");
return 0;
@@ -161,50 +163,45 @@
thread_debug("rb_thread_global_lock_acquire: try acquire (%p) --> \n",
vm->lock_owner_thread);
- if (native_mutex_trylock(&vm->global_interpreter_lock) == EBUSY) {
- int i;
+ for (i=0; i<g_spinlock_count; i++) {
+ if (vm->lock_owner_thread == 0 &&
+ native_mutex_trylock(&vm->global_interpreter_lock) == 0) {
+ thread_debug("rb_thread_global_lock_acquire: <-- done (trylock)\n");
+ goto gotlock;
+ }
+ if (vm->interrupt_gc_flag) {
+ break;
+ }
th->profile_conflict++;
profile_conflict++;
- for (i=0; i<g_spinlock_count; i++) {
- th->profile_conflict++;
- profile_conflict++;
- if (native_mutex_trylock(&vm->global_interpreter_lock) == 0) {
- goto gotlock;
- }
- if (vm->interrupt_gc_flag) {
- break;
- }
- native_thread_yield();
- }
+ native_thread_yield();
+ }
- yarv_save_machine_context(th);
+ yarv_save_machine_context(th);
- native_mutex_lock(&vm->gc_lock);
- {
- INC_WAIT_THREAD(vm);
- if (vm->interrupt_gc_flag) {
- native_cond_signal(&vm->gc_barrier_owner_cond);
- }
+ native_mutex_lock(&vm->gc_lock);
+ {
+ INC_WAIT_THREAD(vm);
+ if (vm->interrupt_gc_flag) {
+ native_cond_signal(&vm->gc_barrier_owner_cond);
}
- native_mutex_unlock(&vm->gc_lock);
+ }
+ native_mutex_unlock(&vm->gc_lock);
- native_mutex_lock(&vm->global_interpreter_lock);
- thread_debug("rb_thread_global_lock_acquire: <-- done (lock)\n");
+ native_mutex_lock(&vm->global_interpreter_lock);
+ thread_debug("rb_thread_global_lock_acquire: <-- done (lock)\n");
- native_mutex_lock(&vm->gc_lock);
- {
- DEC_WAIT_THREAD(vm);
+ native_mutex_lock(&vm->gc_lock);
+ {
+ DEC_WAIT_THREAD(vm);
- if (vm->interrupt_gc_flag) {
- rb_bug("bug?");
- }
+ if (vm->interrupt_gc_flag) {
+ rb_bug("bug?");
}
- native_mutex_unlock(&vm->gc_lock);
}
- else {
- gotlock:
- thread_debug("rb_thread_global_lock_acquire: <-- done (trylock)\n");
- }
+ native_mutex_unlock(&vm->gc_lock);
+
+ gotlock:
vm->lock_owner_thread = th;
return 1;
}
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml