Project

General

Profile

Bug #4723 » 0001-remove-transition_for_lock.patch

kosaki (Motohiro KOSAKI), 05/17/2011 10:48 PM

View differences:

thread.c
3426 3426
{
3427 3427
    int interrupted = 0;
3428 3428
    int err = 0;
3429
    native_mutex_lock(&mutex->lock);
3430
    th->transition_for_lock = 0;
3429

  
3431 3430
    mutex->cond_waiting++;
3432 3431

  
3433 3432
    for (;;) {
......
3459 3458
	}
3460 3459
    }
3461 3460
    mutex->cond_waiting--;
3462
    th->transition_for_lock = 1;
3463
    native_mutex_unlock(&mutex->lock);
3464

  
3465 3461
    return interrupted;
3466 3462
}
3467 3463

  
......
3503 3499

  
3504 3500
	    set_unblock_function(th, lock_interrupt, mutex, &oldubf);
3505 3501
	    th->status = THREAD_STOPPED_FOREVER;
3506
	    th->vm->sleeper++;
3507 3502
	    th->locking_mutex = self;
3508 3503

  
3504
	    native_mutex_lock(&mutex->lock);
3505
	    th->vm->sleeper++;
3509 3506
	    /*
3510
	     * Carefully! while some contended threads are in lock_fun(),
3507
	     * Carefully! while some contended threads are in lock_func(),
3511 3508
	     * vm->sleepr is unstable value. we have to avoid both deadlock
3512 3509
	     * and busy loop.
3513 3510
	     */
3514 3511
	    if (vm_living_thread_num(th->vm) == th->vm->sleeper) {
3515 3512
		timeout_ms = 100;
3516 3513
	    }
3514
	    GVL_UNLOCK_BEGIN();
3515
	    interrupted = lock_func(th, mutex, timeout_ms);
3516
	    native_mutex_unlock(&mutex->lock);
3517
	    GVL_UNLOCK_END();
3517 3518

  
3518
	    th->transition_for_lock = 1;
3519
	    BLOCKING_REGION_CORE({
3520
		interrupted = lock_func(th, mutex, timeout_ms);
3521
	    });
3522
	    th->transition_for_lock = 0;
3523
	    remove_signal_thread_list(th);
3524 3519
	    reset_unblock_function(th, &oldubf);
3525 3520

  
3526 3521
	    th->locking_mutex = Qfalse;
......
4694 4689
    rb_thread_t *th;
4695 4690
    GetThreadPtr(thval, th);
4696 4691

  
4697
    if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th) || th->transition_for_lock) {
4692
    if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th)) {
4698 4693
	*found = 1;
4699 4694
    }
4700 4695
    else if (th->locking_mutex) {
......
4719 4714
    rb_thread_t *th;
4720 4715
    GetThreadPtr(thval, th);
4721 4716

  
4722
    printf("th:%p %d %d %d", th, th->status, th->interrupt_flag, th->transition_for_lock);
4717
    printf("th:%p %d %d", th, th->status, th->interrupt_flag);
4723 4718
    if (th->locking_mutex) {
4724 4719
	mutex_t *mutex;
4725 4720
	GetMutexPtr(th->locking_mutex, mutex);
vm_core.h
435 435
    struct rb_unblock_callback unblock;
436 436
    VALUE locking_mutex;
437 437
    struct rb_mutex_struct *keeping_mutexes;
438
    int transition_for_lock;
439 438

  
440 439
    struct rb_vm_tag *tag;
441 440
    struct rb_vm_protect_tag *protect_tag;
442
-