Project

General

Profile

Bug #4527 ยป 0001-IO-close-releases-GVL-if-possible.patch

[PATCH] IO#close releases GVL if possible - normalperson (Eric Wong), 03/26/2011 03:35 AM

View differences:

io.c
3489 3489
    return finish_writeconv(p->fptr, p->noalloc);
3490 3490
}
3491 3491

  
3492
static VALUE
3493
nogvl_close(void *ptr)
3494
{
3495
    int *fd = (int *)ptr;
3496

  
3497
    return (VALUE)close(*fd);
3498
}
3499

  
3500
static int
3501
maygvl_close(int fd, int keepgvl)
3502
{
3503
    if (keepgvl)
3504
	return close(fd);
3505

  
3506
    return (int)rb_thread_blocking_region(nogvl_close, &fd, RUBY_UBF_IO, 0);
3507
}
3508

  
3492 3509
static void
3493 3510
fptr_finalize(rb_io_t *fptr, int noraise)
3494 3511
{
......
3527 3544
        /* fptr->fd may be closed even if close fails.
3528 3545
         * POSIX doesn't specify it.
3529 3546
         * We assumes it is closed.  */
3530
        if (close(fptr->fd) < 0 && NIL_P(err))
3547
        if (maygvl_close(fptr->fd, noraise) < 0 && NIL_P(err))
3531 3548
            err = noraise ? Qtrue : INT2NUM(errno);
3532 3549
    }
3533 3550
  skip_fd_close:
......
5890 5907
#endif
5891 5908
    }
5892 5909
    else {
5893
        if (close(fptr->fd) < 0)
5910
        if (maygvl_close(fptr->fd, 0) < 0)
5894 5911
            rb_sys_fail_path(fptr->pathv);
5895 5912
        fptr->fd = -1;
5896 5913
        fptr->fd = rb_sysopen(fptr->pathv, oflags, 0666);