Project

General

Profile

Feature #10341 ยป 0004-cont_save_thread-Sparse-copying-of-thread-data.patch

nome (Knut Franke), 10/08/2014 11:59 AM

View differences:

cont.c
107 107
	int register_stack_size;
108 108
#endif
109 109
    } machine;
110
    rb_thread_t saved_thread;
110
    rb_thread_t saved_thread; /* selected properties of GET_THREAD() (see cont_save_thread) */
111 111
    rb_jmpbuf_t jmpbuf;
112 112
    rb_ensure_entry_t *ensure_array;
113 113
    rb_ensure_list_t *ensure_list;
......
412 412
static void
413 413
cont_save_thread(rb_context_t *cont, rb_thread_t *th)
414 414
{
415
    rb_thread_t *sth = &cont->saved_thread;
416

  
415 417
    /* save thread context */
416
    cont->saved_thread = *th;
418
    sth->stack = th->stack;
419
    sth->stack_size = th->stack_size;
420
    sth->local_storage = th->local_storage;
421
    sth->cfp = th->cfp;
422
    sth->safe_level = th->safe_level;
423
    sth->raised_flag = th->raised_flag;
424
    sth->state = th->state;
425
    sth->status = th->status;
426
    sth->tag = th->tag;
427
    sth->protect_tag = th->protect_tag;
428
    sth->errinfo = th->errinfo;
429
    sth->first_proc = th->first_proc;
430
    sth->root_lep = th->root_lep;
431
    sth->root_svar = th->root_svar;
432
    sth->ensure_list = th->ensure_list;
433

  
434
    sth->trace_arg = th->trace_arg;
435

  
417 436
    /* saved_thread->machine.stack_(start|end) should be NULL */
418 437
    /* because it may happen GC afterward */
419
    cont->saved_thread.machine.stack_start = 0;
420
    cont->saved_thread.machine.stack_end = 0;
438
    sth->machine.stack_start = 0;
439
    sth->machine.stack_end = 0;
421 440
#ifdef __ia64
422
    cont->saved_thread.machine.register_stack_start = 0;
423
    cont->saved_thread.machine.register_stack_end = 0;
441
    sth->machine.register_stack_start = 0;
442
    sth->machine.register_stack_end = 0;
424 443
#endif
425 444
}
426 445

  
......
429 448
{
430 449
    /* save thread context */
431 450
    cont_save_thread(cont, th);
451
    cont->saved_thread.self = th->self;
452
    cont->saved_thread.machine.stack_maxsize = th->machine.stack_maxsize;
453
    cont->saved_thread.fiber = th->fiber;
432 454
    cont->saved_thread.local_storage = 0;
433 455
}
434 456

  
......
1155 1177
    rb_fiber_t *fib = fiber_t_alloc(fibval);
1156 1178
    rb_context_t *cont = &fib->cont;
1157 1179
    rb_thread_t *th = &cont->saved_thread;
1180
    rb_thread_t *cth = GET_THREAD();
1158 1181

  
1159 1182
    /* initialize cont */
1160 1183
    cont->vm_stack = 0;
......
1162 1185
    th->stack = 0;
1163 1186
    th->stack_size = 0;
1164 1187

  
1165
    th->stack_size = th->vm->default_params.fiber_vm_stack_size / sizeof(VALUE);
1188
    th->stack_size = cth->vm->default_params.fiber_vm_stack_size / sizeof(VALUE);
1166 1189
    th->stack = ALLOC_N(VALUE, th->stack_size);
1167 1190

  
1168 1191
    th->cfp = (void *)(th->stack + th->stack_size);
......
1187 1210
    th->first_proc = proc;
1188 1211

  
1189 1212
#if !FIBER_USE_NATIVE
1190
    MEMCPY(&cont->jmpbuf, &th->root_jmpbuf, rb_jmpbuf_t, 1);
1213
    MEMCPY(&cont->jmpbuf, &cth->root_jmpbuf, rb_jmpbuf_t, 1);
1191 1214
#endif
1192 1215

  
1193 1216
    return fibval;
1194
-