Project

General

Profile

Feature #9632 ยป 0002-speedup-IO-close-with-many-living-threads.patch

normalperson (Eric Wong), 03/13/2014 03:25 AM

View differences:

thread.c
1341 1341
    int state;
1342 1342

  
1343 1343
    th->waiting_fd = fd;
1344
    list_add(&th->vm->waitfd_threads, &th->waitfd_node);
1344 1345

  
1345 1346
    TH_PUSH_TAG(th);
1346 1347
    if ((state = EXEC_TAG()) == 0) {
......
1353 1354

  
1354 1355
    /* clear waiting_fd anytime */
1355 1356
    th->waiting_fd = -1;
1357
    list_del(&th->waitfd_node);
1356 1358

  
1357 1359
    if (state) {
1358 1360
	JUMP_TAG(state);
......
2059 2061
    return 1;
2060 2062
}
2061 2063

  
2062
static int
2063
thread_fd_close_i(rb_thread_t *th, void *fdp)
2064
{
2065
    int *fd = fdp;
2066
    if (th->waiting_fd == *fd) {
2067
	VALUE err = th->vm->special_exceptions[ruby_error_closed_stream];
2068
	rb_threadptr_pending_interrupt_enque(th, err);
2069
	rb_threadptr_interrupt(th);
2070
    }
2071
    return ST_CONTINUE;
2072
}
2073

  
2074 2064
void
2075 2065
rb_thread_fd_close(int fd)
2076 2066
{
2077
    rb_vm_living_threads_foreach(GET_THREAD()->vm, thread_fd_close_i, &fd);
2067
    rb_thread_t *th;
2068
    rb_vm_t *vm = GET_THREAD()->vm;
2069

  
2070
    list_for_each(&vm->waitfd_threads, th, waitfd_node) {
2071
	if (th->waiting_fd == fd) {
2072
	    VALUE err = vm->special_exceptions[ruby_error_closed_stream];
2073
	    rb_threadptr_pending_interrupt_enque(th, err);
2074
	    rb_threadptr_interrupt(th);
2075
	}
2076
    }
2078 2077
}
2079 2078

  
2080 2079
/*
vm_core.h
333 333
    struct rb_thread_struct *main_thread;
334 334
    struct rb_thread_struct *running_thread;
335 335

  
336
    struct list_head waitfd_threads;
336 337
    struct list_head living_threads;
337 338
    size_t living_thread_num;
338 339
    VALUE thgroup_default;
......
519 520
    int state;
520 521

  
521 522
    int waiting_fd;
523
    struct list_node waitfd_node;
522 524

  
523 525
    /* for rb_iterate */
524 526
    const rb_block_t *passed_block;
......
860 862
static inline void
861 863
rb_vm_living_threads_init(rb_vm_t *vm)
862 864
{
865
    list_head_init(&vm->waitfd_threads);
863 866
    list_head_init(&vm->living_threads);
864 867
    vm->living_thread_num = 0;
865 868
}
866
-