Changeset 72

Show
Ignore:
Timestamp:
09/06/2006 12:06:55 (2 years ago)
Author:
why
Message:
  • ext/sand_table/sand_table.c: sandbox swapping across threads happens a bit more efficiently -- only when threads are in separate sandboxes. also, i'm now handling swapping back to the main thread better. sandbox_save and sandbox_restore are now run by all threads branching off of the main thread where the libary is loaded. the prelude is rb_load'd now, to keep $LOADED_FEATURES untouched.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/sand_table/sand_table.c

    r71 r72  
    119119  rb_thread_t thread; 
    120120{ 
     121  /* printf("SAVE: %lu, %lu -> %lu\n", thread, thread->sandbox, ruby_sandbox); */ 
    121122  return Qnil; 
    122123} 
     
    126127  rb_thread_t thread; 
    127128{ 
    128   if (!NIL_P(thread->sandbox)) 
     129  /* printf("RESTORE: %lu, %lu -> %lu\n", thread, thread->sandbox, ruby_sandbox); */ 
     130  if (ruby_sandbox != thread->sandbox) 
    129131  { 
    130132    sandkit *kit; 
    131     Data_Get_Struct( thread->sandbox, sandkit, kit ); 
    132     sandbox_swap_in(kit); 
     133    if (NIL_P(thread->sandbox) && !NIL_P(ruby_sandbox)) 
     134    { 
     135      sandbox_swap_in(&real); 
     136    } 
     137    else if (!NIL_P(thread->sandbox)) 
     138    { 
     139      Data_Get_Struct( thread->sandbox, sandkit, kit ); 
     140      sandbox_swap_in(kit); 
     141    } 
    133142  } 
    134143  return Qnil; 
     
    437446  sandbox_swap_out(go->kit); 
    438447  curr_thread->sandbox = Qnil; 
    439   curr_thread->sandbox_restore = NULL; 
    440   curr_thread->sandbox_save = NULL; 
    441448 
    442449  go->kit->active = 0; 
     
    461468  kit->active = 1; 
    462469 
    463   curr_thread->sandbox_save = sandbox_save; 
    464   curr_thread->sandbox_restore = sandbox_restore; 
    465470  curr_thread->sandbox = kit->self; 
    466471 
     
    26702675  StringValue(prelude); 
    26712676  go_cart *go = sandbox_begin(kit); 
    2672   rb_require(RSTRING(prelude)->ptr); 
     2677  rb_load(prelude, 0); 
    26732678  sandbox_whoa_whoa_whoa(go); 
    26742679} 
     
    27652770  real.active = 1; 
    27662771 
     2772  /* FIXME: all threads should run through sandbox_save. */ 
     2773  curr_thread->sandbox_save = sandbox_save; 
     2774  curr_thread->sandbox_restore = sandbox_restore; 
     2775 
    27672776  rb_cSandbox = rb_define_class("Sandbox", rb_cObject); 
    27682777  rb_define_const( rb_cSandbox, "VERSION", rb_str_new2( SAND_VERSION ) );