Permalink
Browse files

Added global the_main_context; caml_signal_handlers: cloned for non-m…

…ain contexts.
  • Loading branch information...
1 parent db5549c commit 84a08d377e729601164bfa7b7ba4bc466157d223 @lucasaiu committed Apr 3, 2013
Showing with 23 additions and 18 deletions.
  1. +1 −0 asmrun/startup.c
  2. BIN boot/ocamlrun
  3. +1 −1 byterun/alloc.c
  4. +3 −0 byterun/context.c
  5. +3 −0 byterun/context.h
  6. +8 −15 byterun/signals.c
  7. +2 −0 byterun/startup.c
  8. +5 −2 otherlibs/systhreads/st_stubs.c
View
@@ -191,6 +191,7 @@ caml_global_context* caml_main_rr(char **argv)
char tos;
caml_context_initialize_global_stuff();
CAML_R = caml_initialize_first_global_context();
+ the_main_context = ctx;
caml_init_ieee_floats();
caml_init_custom_operations();
View
Binary file not shown.
View
@@ -48,7 +48,7 @@ CAMLexport value caml_alloc_r (CAML_R, mlsize_t wosize, tag_t tag)
}else if (wosize <= Max_young_wosize){
Alloc_small (result, wosize, tag);
if (tag < No_scan_tag){
- for (i = 0; i < wosize; i++) Field (result, i) = 0;
+ for (i = 0; i < wosize; i++) Field (result, i) = Val_int(0);//0;
}
}else{
result = caml_alloc_shr_r (ctx, wosize, tag);
View
@@ -38,6 +38,9 @@
static __thread caml_global_context *the_thread_local_caml_context = NULL;
+/* The one and only main context: */
+caml_global_context *the_main_context = NULL;
+
caml_global_context *caml_get_thread_local_context(void)
{
return the_thread_local_caml_context;
View
@@ -1116,4 +1116,7 @@ void caml_set_caml_initialize_context_thread_support(CAML_R, void (*caml_initial
int caml_can_split_r(CAML_R);
void caml_set_caml_can_split_r(CAML_R, int (*caml_can_split_r)(CAML_R));
+/* The one and only main context: */
+CAMLextern caml_global_context *the_main_context;
+
#endif
View
@@ -42,21 +42,13 @@ void caml_process_pending_signals_r(CAML_R)
int i;
if (caml_signals_are_pending) {
-/* #ifdef NATIVE_CODE */
-/* DUMP("something to do"); */
-/* #endif // #ifdef NATIVE_CODE */
caml_signals_are_pending = 0;
for (i = 0; i < NSIG; i++) {
if (caml_pending_signals[i]) {
caml_pending_signals[i] = 0;
- /* DUMP("ABOUT TO process signal %i", i); */
caml_execute_signal_r(ctx, i, 0);
- /* DUMP("processED signal %i", i); */
}
}
-/* #ifdef NATIVE_CODE */
-/* DUMP("done"); */
-/* #endif // #ifdef NATIVE_CODE */
}
}
@@ -148,8 +140,7 @@ CAMLexport void caml_leave_blocking_section_r(CAML_R)
void caml_execute_signal_r(CAML_R, int signal_number, int in_signal_handler)
{
- DUMP("SIGPREEMPTION is %i", SIGVTALRM);
- DUMP("signal_number %i (converted into %i), in_signal_handler=%i", signal_number, (int)caml_rev_convert_signal_number(signal_number), in_signal_handler);
+ //DUMP("signal_number %i (converted into %i), in_signal_handler=%i", signal_number, (int)caml_rev_convert_signal_number(signal_number), in_signal_handler);
value res;
#ifdef POSIX_SIGNALS
sigset_t sigs;
@@ -159,9 +150,7 @@ void caml_execute_signal_r(CAML_R, int signal_number, int in_signal_handler)
sigaddset(&sigs, signal_number);
sigprocmask(SIG_BLOCK, &sigs, &sigs);
#endif
- //DUMP();
-//caml_gc_compaction_r(ctx, Val_unit); //!!!!
- DUMP("right before calling caml_callback_exn_r; caml_signal_handlers is %p", caml_signal_handlers);
+ //DUMP("right before calling caml_callback_exn_r; caml_signal_handlers is %p", (void*)caml_signal_handlers);
res = caml_callback_exn_r(ctx,
Field(caml_signal_handlers, signal_number),
Val_int(caml_rev_convert_signal_number(signal_number)));
@@ -177,7 +166,6 @@ void caml_execute_signal_r(CAML_R, int signal_number, int in_signal_handler)
}
#endif
if (Is_exception_result(res)) caml_raise_r(ctx, Extract_exception(res));
- //DUMP("end");
}
/* Arrange for a garbage collection to be performed as soon as possible */
@@ -288,7 +276,6 @@ CAMLexport int caml_rev_convert_signal_number(int signo)
CAMLprim value caml_install_signal_handler_r(CAML_R, value signal_number, value action)
{
- DUMP("signal_number %i", (int)Int_val(signal_number));
CAMLparam2 (signal_number, action);
CAMLlocal1 (res);
int sig, act, oldact;
@@ -325,9 +312,15 @@ CAMLprim value caml_install_signal_handler_r(CAML_R, value signal_number, value
if (Is_block(action)) {
if (caml_signal_handlers == 0) {
caml_signal_handlers = caml_alloc_r(ctx, NSIG, 0);
+ ////
+ /* int i, length = NSIG; */
+ /* for(i = 0; i < NSIG; i ++) */
+ /* caml_initialize_r(ctx, &Field(caml_signal_handlers, i), Val_int(0)); */
+ ////
caml_register_global_root_r(ctx, &caml_signal_handlers);
}
caml_modify_r(ctx, &Field(caml_signal_handlers, sig), Field(action, 0));
+ DUMP("Registering the handler %p (%p) for the signal %i", (void*)action, (void*)Field(action, 0), sig);
}
caml_process_pending_signals_r(ctx);
CAMLreturn (res);
View
@@ -390,6 +390,7 @@ CAMLexport caml_global_context* caml_main_rr(char **argv)
caml_context_initialize_global_stuff();
CAML_R = caml_initialize_first_global_context();
+ the_main_context = ctx;
/* Machine-dependent initialization of the floating-point hardware
so that it behaves as much as possible as specified in IEEE */
@@ -505,6 +506,7 @@ CAMLexport void caml_startup_code(
caml_context_initialize_global_stuff();
CAML_R = caml_initialize_first_global_context();
+ the_main_context = ctx;
caml_init_ieee_floats();
caml_init_custom_operations();
@@ -24,6 +24,7 @@
#define CAML_ST_POSIX_CODE
#include "mlvalues.h" // FIXME: remove after debugging unless needed
#include "context.h" // FIXME: remove after debugging unless needed
+#include "context_split.h" // FIXME: remove after debugging unless needed
#include "memory.h" // FIXME: remove after debugging unless needed
#include "alloc.h"
@@ -509,8 +510,10 @@ static void caml_thread_initialize_for_current_context_r(CAML_R){
/* If this is not the main context, then we have to copy its signal
handlers (a Caml array, which can be cloned via a blob): */
if(ctx->descriptor->kind != caml_global_context_main){
- fprintf(stderr, "UNIMPLEMENTED -- I'm fixing this on Monday :-) --Luca Saiu\n"); fflush(stderr);
- exit(EXIT_FAILURE);
+ char *blob = caml_serialize_into_blob_r(the_main_context, the_main_context->caml_signal_handlers);
+ ctx->caml_signal_handlers = caml_deserialize_blob_r(ctx, blob);
+ free(blob);
+ caml_register_global_root_r(ctx, &ctx->caml_signal_handlers);
}
/* The stack-related fields will be filled in at the next

0 comments on commit 84a08d3

Please sign in to comment.