Sauver et restaurer gc_entry_regs et gc_entry_float_regs dans le contexte de chaque thread

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1796 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1997-11-20 15:34:38 +00:00
parent 45638e8f80
commit b252cfa686
2 changed files with 41 additions and 14 deletions

View File

@ -27,7 +27,11 @@
#include "mlvalues.h"
#include "roots.h"
#include "signals.h"
#ifdef NATIVE_CODE
#include "stack.h"
#else
#include "stacks.h"
#endif
#include "sys.h"
/* Initial size of stack when a thread is created (4 Ko) */
@ -60,6 +64,9 @@ struct caml_thread_struct {
unsigned long last_return_address; /* Saved value of caml_last_return_a */
char * exception_pointer; /* Saved value of caml_exception_pointer */
struct caml__roots_block * local_roots; /* Saved value of local_roots */
value gc_entry_regs[MAX_NUM_GC_REGS]; /* Saved gc_entry_regs */
double gc_entry_float_regs[MAX_NUM_GC_FLOAT_REGS];
/* Saved gc_entry_float_regs */
#else
value * stack_low; /* The execution stack for this thread */
value * stack_high;
@ -91,14 +98,6 @@ static pthread_key_t last_channel_locked_key;
/* Identifier for next thread creation */
static long thread_next_ident = 0;
/* These declarations should go in some include file */
#ifdef NATIVE_CODE
extern char * caml_bottom_of_stack;
extern unsigned long caml_last_return_address;
extern char * caml_exception_pointer;
#endif
/* Forward declarations */
value caml_mutex_new (value);
@ -121,8 +120,8 @@ static void caml_thread_scan_roots(scanning_action action)
if (th != curr_thread) {
#ifdef NATIVE_CODE
if (th->bottom_of_stack != NULL)
do_local_roots(action, th->last_return_address,
th->bottom_of_stack, th->local_roots);
do_local_roots(action, th->last_return_address, th->bottom_of_stack,
th->local_roots, th->gc_entry_regs);
#else
do_local_roots(action, th->sp, th->stack_high, th->local_roots);
#endif
@ -149,6 +148,9 @@ static void caml_thread_enter_blocking_section(void)
curr_thread->last_return_address = caml_last_return_address;
curr_thread->exception_pointer = caml_exception_pointer;
curr_thread->local_roots = local_roots;
bcopy(gc_entry_regs, curr_thread->gc_entry_regs, sizeof(gc_entry_regs));
bcopy(gc_entry_float_regs, curr_thread->gc_entry_float_regs,
sizeof(gc_entry_float_regs));
#else
curr_thread->stack_low = stack_low;
curr_thread->stack_high = stack_high;
@ -175,6 +177,9 @@ static void caml_thread_leave_blocking_section(void)
caml_last_return_address = curr_thread->last_return_address;
caml_exception_pointer = curr_thread->exception_pointer;
local_roots = curr_thread->local_roots;
bcopy(curr_thread->gc_entry_regs, gc_entry_regs, sizeof(gc_entry_regs));
bcopy(curr_thread->gc_entry_float_regs, gc_entry_float_regs,
sizeof(gc_entry_float_regs));
#else
stack_low = curr_thread->stack_low;
stack_high = curr_thread->stack_high;

View File

@ -23,7 +23,11 @@
#include "mlvalues.h"
#include "roots.h"
#include "signals.h"
#ifdef NATIVE_CODE
#include "stack.h"
#else
#include "stacks.h"
#endif
#include "sys.h"
/* Initial size of stack when a thread is created (4 Ko) */
@ -64,6 +68,9 @@ struct caml_thread_struct {
unsigned long last_return_address; /* Saved value of caml_last_return_a */
char * exception_pointer; /* Saved value of caml_exception_pointer */
struct caml__roots_block * local_roots; /* Saved value of local_roots */
value gc_entry_regs[MAX_NUM_GC_REGS]; /* Saved gc_entry_regs */
double gc_entry_float_regs[MAX_NUM_GC_FLOAT_REGS];
/* Saved gc_entry_float_regs */
#else
value * stack_low; /* The execution stack for this thread */
value * stack_high;
@ -118,9 +125,9 @@ static void caml_thread_scan_roots(scanning_action action)
/* Don't rescan the stack of the current thread, it was done already */
if (th != curr_thread) {
#ifdef NATIVE_CODE
if (th->bottom_of_stack == NULL) continue;
do_local_roots(action, th->last_return_address,
th->bottom_of_stack, th->local_roots);
if (th->bottom_of_stack != NULL)
do_local_roots(action, th->last_return_address, th->bottom_of_stack,
th->local_roots, th->gc_entry_regs);
#else
do_local_roots(action, th->sp, th->stack_high, th->local_roots);
#endif
@ -147,6 +154,9 @@ static void caml_thread_enter_blocking_section(void)
curr_thread->last_return_address = caml_last_return_address;
curr_thread->exception_pointer = caml_exception_pointer;
curr_thread->local_roots = local_roots;
bcopy(gc_entry_regs, curr_thread->gc_entry_regs, sizeof(gc_entry_regs));
bcopy(gc_entry_float_regs, curr_thread->gc_entry_float_regs,
sizeof(gc_entry_float_regs));
#else
curr_thread->stack_low = stack_low;
curr_thread->stack_high = stack_high;
@ -170,6 +180,9 @@ static void caml_thread_leave_blocking_section(void)
caml_last_return_address = curr_thread->last_return_address;
caml_exception_pointer = curr_thread->exception_pointer;
local_roots = curr_thread->local_roots;
bcopy(curr_thread->gc_entry_regs, gc_entry_regs, sizeof(gc_entry_regs));
bcopy(curr_thread->gc_entry_float_regs, gc_entry_float_regs,
sizeof(gc_entry_float_regs));
#else
stack_low = curr_thread->stack_low;
stack_high = curr_thread->stack_high;
@ -374,7 +387,16 @@ value caml_thread_new(value clos) /* ML */
th->wthread =
CreateThread(NULL,0, (LPTHREAD_START_ROUTINE) caml_thread_start,
(void *) th, 0, &th_id);
if (th->wthread == NULL) caml_wthread_error("Thread.create");
if (th->wthread == NULL) {
/* Fork failed, remove thread info block from list of threads */
th->next->prev = curr_thread;
curr_thread->next = th->next;
#ifndef NATIVE_CODE
stat_free(th->stack_low);
#endif
stat_free(th);
caml_wthread_error("Thread.create");
}
((struct caml_thread_handle *)vthread)->handle = th->wthread;
End_roots();
return descr;