Project

General

Profile

Feature #4538 ยป 0001-avoid-unnecessary-select-calls-before-doing-I-O.patch

patch to remove unnecessary select() calls - normalperson (Eric Wong), 03/30/2011 03:22 AM

View differences:

ext/socket/basicsocket.c
558 558
    GetOpenFile(sock, fptr);
559 559
    arg.fd = fptr->fd;
560 560
    arg.flags = NUM2INT(flags);
561
    while (rb_thread_fd_writable(arg.fd),
562
	   (n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
561
    while ((n = (int)BLOCKING_REGION_FD(func, &arg)) < 0) {
563 562
	if (rb_io_wait_writable(arg.fd)) {
564 563
	    continue;
565 564
	}
ext/socket/init.c
128 128
    RBASIC(str)->klass = 0;
129 129

  
130 130
    while (rb_io_check_closed(fptr),
131
	   rb_thread_wait_fd(arg.fd),
132 131
	   (slen = BLOCKING_REGION_FD(recvfrom_blocking, &arg)) < 0) {
133 132
        if (!rb_io_wait_readable(fptr->fd)) {
134 133
            rb_sys_fail("recvfrom(2)");
......
514 513
    arg.sockaddr = sockaddr;
515 514
    arg.len = len;
516 515
  retry:
517
    rb_thread_wait_fd(fd);
518 516
    fd2 = (int)BLOCKING_REGION_FD(accept_blocking, &arg);
519 517
    if (fd2 < 0) {
520 518
	switch (errno) {
ext/socket/udpsocket.c
176 176
      retry:
177 177
	arg.to = res->ai_addr;
178 178
	arg.tolen = res->ai_addrlen;
179
	rb_thread_fd_writable(arg.fd);
180 179
	n = (int)BLOCKING_REGION_FD(rsock_sendto_blocking, &arg);
181 180
	if (n >= 0) {
182 181
	    freeaddrinfo(res0);
io.c
674 674
    rb_io_check_closed(fptr);
675 675
    if (fptr->wbuf.len == 0)
676 676
        return 0;
677
    if (!rb_thread_fd_writable(fptr->fd)) {
678
        rb_io_check_closed(fptr);
679
    }
680 677
    while (fptr->wbuf.len > 0 && io_flush_buffer(fptr) != 0) {
681 678
	if (!rb_io_wait_writable(fptr->fd))
682 679
	    return -1;
......
867 864
        (fptr->wbuf.ptr && fptr->wbuf.capa <= fptr->wbuf.len + len)) {
868 865
	struct binwrite_arg arg;
869 866

  
870
        /* xxx: use writev to avoid double write if available */
867
	/*
868
	 * xxx: use writev to avoid double write if available
869
	 * writev may help avoid context switch between "a" and "\n" in
870
	 * STDERR.puts "a" [ruby-dev:25080] (rebroken since native threads
871
	 * introduced in 1.9)
872
	 */
871 873
        if (fptr->wbuf.len && fptr->wbuf.len+len <= fptr->wbuf.capa) {
872 874
            if (fptr->wbuf.capa < fptr->wbuf.off+fptr->wbuf.len+len) {
873 875
                MEMMOVE(fptr->wbuf.ptr, fptr->wbuf.ptr+fptr->wbuf.off, char, fptr->wbuf.len);
......
881 883
            return -1L;
882 884
        if (n == 0)
883 885
            return len;
884
        /* avoid context switch between "a" and "\n" in STDERR.puts "a".
885
           [ruby-dev:25080] */
886
	if (fptr->stdio_file != stderr && !rb_thread_fd_writable(fptr->fd)) {
887
	    rb_io_check_closed(fptr);
888
	}
886
	rb_io_check_closed(fptr);
889 887
	arg.fptr = fptr;
890 888
	arg.str = str;
891 889
      retry:
......
1581 1579
	    }
1582 1580
	    offset += c;
1583 1581
	    if ((n -= c) <= 0) break;
1584
	    rb_thread_wait_fd(fptr->fd);
1585 1582
	}
1586 1583
	return len - n;
1587 1584
    }
......
1592 1589
	    offset += c;
1593 1590
	    if ((n -= c) <= 0) break;
1594 1591
	}
1595
	rb_thread_wait_fd(fptr->fd);
1596 1592
	rb_io_check_closed(fptr);
1597 1593
	if (io_fillbuf(fptr) < 0) {
1598 1594
	    break;
......
3914 3910
    if (fptr->wbuf.len) {
3915 3911
	rb_warn("syswrite for buffered IO");
3916 3912
    }
3917
    if (!rb_thread_fd_writable(fptr->fd)) {
3918
        rb_io_check_closed(fptr);
3919
    }
3920 3913

  
3921 3914
    n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
3922 3915

  
......
3962 3955
    }
3963 3956

  
3964 3957
    n = fptr->fd;
3965
    rb_thread_wait_fd(fptr->fd);
3966 3958
    rb_io_check_closed(fptr);
3967 3959

  
3968 3960
    rb_str_locktmp(str);
......
8777 8769
        }
8778 8770
        else {
8779 8771
            ssize_t ss;
8780
            rb_thread_wait_fd(stp->src_fd);
8781 8772
            rb_str_resize(buf, buflen);
8782 8773
            ss = maygvl_copy_stream_read(stp, RSTRING_PTR(buf), l, off);
8783 8774
            if (ss == -1)
8784
-