Permalink
Browse files

Commit before destabilizing changes

  • Loading branch information...
1 parent bde87ad commit 478a1faf96b4576474212e4c363e471c6f6fd3df @lucasaiu committed Mar 29, 2013
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -845,4 +845,12 @@ int caml_can_split_r(CAML_R){
return ctx->can_split;
}
-__thread int caml_indentation_level = 0;
+/* CAMLprim int caml_multi_context_implemented(value unit){ */
+/* #if HAS_MULTI_CONTEXT */
+/* return Bool_val(1); */
+/* #else */
+/* return Bool_val(0); */
+/* #endif /\* #if HAS_MULTI_CONTEXT *\/ */
+/* } */
+
+__thread int caml_indentation_level = 0; // FIXME: remove this crap after debugging !!!!!!!!!!!!!!!!
View
@@ -1024,34 +1024,6 @@ void caml_finalize_mutex(pthread_mutex_t *mutex);
void caml_initialize_semaphore(sem_t *semaphore, int initial_value);
void caml_finalize_semaphore(sem_t *semaphore);
-struct caml_thread_struct {
- value descr; /* The heap-allocated descriptor (root) */
- struct caml_thread_struct * next; /* Double linking of running threads */
- struct caml_thread_struct * prev;
-#ifdef NATIVE_CODE
- char * top_of_stack; /* Top of stack for this thread (approx.) */
- char * bottom_of_stack; /* Saved value of caml_bottom_of_stack */
- uintnat last_retaddr; /* Saved value of caml_last_return_address */
- value * gc_regs; /* Saved value of caml_gc_regs */
- char * exception_pointer; /* Saved value of caml_exception_pointer */
- struct caml__roots_block * local_roots; /* Saved value of local_roots */
- struct longjmp_buffer * exit_buf; /* For thread exit */
-#else
- value * stack_low; /* The execution stack for this thread */
- value * stack_high;
- value * stack_threshold;
- value * sp; /* Saved value of extern_sp for this thread */
- value * trapsp; /* Saved value of trapsp for this thread */
- struct caml__roots_block * local_roots; /* Saved value of local_roots */
- struct longjmp_buffer * external_raise; /* Saved external_raise */
-#endif
- int backtrace_pos; /* Saved backtrace_pos */
- code_t * backtrace_buffer; /* Saved backtrace_buffer */
- value backtrace_last_exn; /* Saved backtrace_last_exn (root) */
- CAML_R; /* the context to which this thread belongs */
- void* posix_thread; // FIXME: for debugging. REMOVE
- int id; // FIXME: for debugging only
-};
#define NOATTR "\033[0m"
#define RED NOATTR "\033[31m"
@@ -1064,12 +1036,11 @@ struct caml_thread_struct {
#define DUMP(FORMAT, ...) \
do{ \
fprintf(stderr, \
- "%s:%i(" RED "%s" NOATTR ") C%p T%p "/* "AP" PURPLE"%p"NOATTR"/"PURPLE"%p" */NOATTR" "CYAN"[%i threads]: %i"NOATTR" "NOATTR, \
+ "%s:%i(" RED "%s" NOATTR ") C%p T%p "/* "AP" PURPLE"%p"NOATTR"/"PURPLE"%p" */NOATTR" "CYAN"[%i threads] "NOATTR" "NOATTR, \
__FILE__, __LINE__, __FUNCTION__, ctx, \
(void*)pthread_self(), \
/* ctx->caml_young_ptr, ctx->caml_young_limit, \ */ \
- caml_get_thread_no_r(ctx), \
- ctx->curr_thread ? (int)ctx->curr_thread->id : -1); \
+ caml_get_thread_no_r(ctx)); \
fflush(stderr); \
fprintf(stderr, " " GREEN FORMAT, ##__VA_ARGS__); \
fprintf(stderr, NOATTR "\n"); \
@@ -1124,8 +1095,16 @@ extern __thread int caml_indentation_level;
fflush(stderr); \
} while(0)
-/* #undef DUMP */
-/* #define DUMP(FORMAT, ...) /\* nothing *\/ */
+#undef DUMP
+#undef QDUMP
+#undef QB
+#undef QR
+#undef QBR
+#define DUMP(FORMAT, ...) /* nothing */
+#define QDUMP(FORMAT, ...) /* nothing */
+#define QB(FORMAT, ...) /* nothing */
+#define QR(FORMAT, ...) /* nothing */
+#define QBR(FORMAT, ...) /* nothing */
int caml_get_thread_no_r(CAML_R);
void caml_set_caml_get_thread_no_r(CAML_R, int (*f)(CAML_R));
View
@@ -502,6 +502,7 @@ CAMLprim value caml_context_join_r(CAML_R, value context_as_value){
}
CAMLprim value caml_context_send_r(CAML_R, value receiver_mailbox_as_value, value message){
+ fprintf(stderr, "SEND: OK-1\n"); fflush(stderr);
CAMLparam2(receiver_mailbox_as_value, message);
struct caml_mailbox *receiver_mailbox;
char *message_blob;
@@ -513,6 +514,7 @@ CAMLprim value caml_context_send_r(CAML_R, value receiver_mailbox_as_value, valu
it out of the critical section: */
message_blob = caml_serialize_into_blob_r(ctx, message);
+ fprintf(stderr, "SEND: OK-2\n"); fflush(stderr);
/* /\* Wait until there is a free slot: *\/ */
/* caml_enter_blocking_section_r(ctx); */
/* sem_wait(&receiver_mailbox->free_slot_no_semaphore); */
@@ -524,6 +526,7 @@ CAMLprim value caml_context_send_r(CAML_R, value receiver_mailbox_as_value, valu
//fprintf(stderr, "caml_context_send_r [%p, m %p]: OK-30 AFTER LOCK\n", ctx, receiver_mailbox); fflush(stderr);
int message_no = receiver_mailbox->message_no;
+ fprintf(stderr, "SEND: OK-3\n"); fflush(stderr);
/* Make sure there is enough space, enlarging the queue if needed: */
if(message_no == receiver_mailbox->allocated_message_no){
receiver_mailbox->allocated_message_no *= 2;
@@ -540,11 +543,13 @@ CAMLprim value caml_context_send_r(CAML_R, value receiver_mailbox_as_value, valu
//fprintf(stderr, "caml_context_send_r [%p, m %p]: OK-60 AFTER V\n", ctx, receiver_mailbox); fflush(stderr);
//fprintf(stderr, "caml_context_send_r [%p, m %p]: OK-100\n", ctx, receiver_mailbox); fflush(stderr);
//fprintf(stderr, "caml_context_send_r [%p, m %p]: OK-100 END, message_no is %i\n", ctx, receiver_mailbox, (int)receiver_mailbox->message_no); fflush(stderr);
+ fprintf(stderr, "SEND: OK-4\n"); fflush(stderr);
CAMLreturn(Val_unit);
}
CAMLprim value caml_context_receive_r(CAML_R, value receiver_mailbox_as_value){
+ fprintf(stderr, "RECEIVE: OK-1\n"); fflush(stderr);
CAMLparam1(receiver_mailbox_as_value);
CAMLlocal1(message);
struct caml_mailbox *receiver_mailbox = caml_mailbox_of_value(receiver_mailbox_as_value);
@@ -562,6 +567,7 @@ CAMLprim value caml_context_receive_r(CAML_R, value receiver_mailbox_as_value){
sem_wait(&receiver_mailbox->message_no_semaphore);
caml_leave_blocking_section_r(ctx);
+ fprintf(stderr, "RECEIVE: OK-2\n"); fflush(stderr);
//fprintf(stderr, "caml_context_receive_r [%p, m %p]: OK-20 AFTER P, BEFORE LOCK\n", ctx, receiver_mailbox); fflush(stderr);
/* Get what we need, and immediately unblock the next sender; we can
process our message after V'ing. */
@@ -580,6 +586,7 @@ CAMLprim value caml_context_receive_r(CAML_R, value receiver_mailbox_as_value){
//fprintf(stderr, "caml_context_receive_r [%p, m %p]: OK-40 BEFORE UNLOCK; message_no is now %i\n", ctx, receiver_mailbox, (int)receiver_mailbox->message_no); fflush(stderr);
pthread_mutex_unlock(&receiver_mailbox->mutex);
//fprintf(stderr, "caml_context_receive_r [%p, m %p]: OK-50 AFTER UNLOCK\n", ctx, receiver_mailbox); fflush(stderr);
+ fprintf(stderr, "RECEIVE: OK-3\n"); fflush(stderr);
/* /\* Signal the fact that there one slot has been freed: *\/ */
/* sem_post(&receiver_mailbox->free_slot_no_semaphore); */
@@ -588,6 +595,7 @@ CAMLprim value caml_context_receive_r(CAML_R, value receiver_mailbox_as_value){
free(message_blob);
//fprintf(stderr, "caml_context_receive_r [%p, m %p]: OK-100 END, message_no is %i\n", ctx, receiver_mailbox, (int)receiver_mailbox->message_no); fflush(stderr);
+ fprintf(stderr, "RECEIVE: OK-4\n"); fflush(stderr);
CAMLreturn(message);
}
View
@@ -47,5 +47,6 @@
#define HAS_GETHOSTBYNAME_R 6
#define HAS_GETHOSTBYADDR_R 8
#define HAS_STACK_OVERFLOW_DETECTION
+#define HAS_PTHREAD
#define HAS_SIGWAIT
#define HAS_LIBBFD
View
@@ -1179,6 +1179,16 @@ esac
echo "BNG_ARCH=$bng_arch" >> Makefile
echo "BNG_ASM_LEVEL=$bng_asm_level" >> Makefile
+# Determine if multi-context is support
+
+case "$arch,$system" in
+ amd64,linux)
+ echo "Multi-context is supported."
+ echo "#define HAS_MULTI_CONTEXT" >> s.h;;
+ *)
+ echo "Multi-context is not supported";;
+esac
+
# Determine if the POSIX threads library is supported
systhread_support=false
@@ -1200,6 +1210,7 @@ if test "$pthread_wanted" = "yes"; then
otherlibraries="$otherlibraries systhreads"
bytecccompopts="$bytecccompopts -D_REENTRANT"
nativecccompopts="$nativecccompopts -D_REENTRANT"
+ echo "#define HAS_PTHREAD" >> s.h
case "$host" in
*-*-freebsd*)
bytecccompopts="$bytecccompopts -D_THREAD_SAFE"
View
@@ -69,7 +69,7 @@ let natdynlink = true;;
let cmxs = "cmxs";;
let mkexe = bytecc;;
let mkexedebugflag = "-g";;
-let mkdll = "gcc -shared";;
+let mkdll = "gcc -shared -g";;
let mkmaindll = "gcc -shared -g";;
let runtimed = "noruntimed";;
let camlp4 = "camlp4";;
@@ -73,34 +73,34 @@ struct caml_thread_descr {
/* The infos on threads (allocated via malloc()) */
-/* struct caml_thread_struct { */
-/* value descr; /\* The heap-allocated descriptor (root) *\/ */
-/* struct caml_thread_struct * next; /\* Double linking of running threads *\/ */
-/* struct caml_thread_struct * prev; */
-/* #ifdef NATIVE_CODE */
-/* char * top_of_stack; /\* Top of stack for this thread (approx.) *\/ */
-/* char * bottom_of_stack; /\* Saved value of caml_bottom_of_stack *\/ */
-/* uintnat last_retaddr; /\* Saved value of caml_last_return_address *\/ */
-/* value * gc_regs; /\* Saved value of caml_gc_regs *\/ */
-/* char * exception_pointer; /\* Saved value of caml_exception_pointer *\/ */
-/* struct caml__roots_block * local_roots; /\* Saved value of local_roots *\/ */
-/* struct longjmp_buffer * exit_buf; /\* For thread exit *\/ */
-/* #else */
-/* value * stack_low; /\* The execution stack for this thread *\/ */
-/* value * stack_high; */
-/* value * stack_threshold; */
-/* value * sp; /\* Saved value of extern_sp for this thread *\/ */
-/* value * trapsp; /\* Saved value of trapsp for this thread *\/ */
-/* struct caml__roots_block * local_roots; /\* Saved value of local_roots *\/ */
-/* struct longjmp_buffer * external_raise; /\* Saved external_raise *\/ */
-/* #endif */
-/* int backtrace_pos; /\* Saved backtrace_pos *\/ */
-/* code_t * backtrace_buffer; /\* Saved backtrace_buffer *\/ */
-/* value backtrace_last_exn; /\* Saved backtrace_last_exn (root) *\/ */
-/* CAML_R; /\* the context to which this thread belongs *\/ */
-/* void* posix_thread; // FIXME: for debugging. REMOVE */
-/* int id; // FIXME: for debugging only */
-/* }; */
+struct caml_thread_struct {
+ value descr; /* The heap-allocated descriptor (root) */
+ struct caml_thread_struct * next; /* Double linking of running threads */
+ struct caml_thread_struct * prev;
+#ifdef NATIVE_CODE
+ char * top_of_stack; /* Top of stack for this thread (approx.) */
+ char * bottom_of_stack; /* Saved value of caml_bottom_of_stack */
+ uintnat last_retaddr; /* Saved value of caml_last_return_address */
+ value * gc_regs; /* Saved value of caml_gc_regs */
+ char * exception_pointer; /* Saved value of caml_exception_pointer */
+ struct caml__roots_block * local_roots; /* Saved value of local_roots */
+ struct longjmp_buffer * exit_buf; /* For thread exit */
+#else
+ value * stack_low; /* The execution stack for this thread */
+ value * stack_high;
+ value * stack_threshold;
+ value * sp; /* Saved value of extern_sp for this thread */
+ value * trapsp; /* Saved value of trapsp for this thread */
+ struct caml__roots_block * local_roots; /* Saved value of local_roots */
+ struct longjmp_buffer * external_raise; /* Saved external_raise */
+#endif
+ int backtrace_pos; /* Saved backtrace_pos */
+ code_t * backtrace_buffer; /* Saved backtrace_buffer */
+ value backtrace_last_exn; /* Saved backtrace_last_exn (root) */
+ CAML_R; /* the context to which this thread belongs */
+ //void* posix_thread; // FIXME: for debugging. REMOVE
+ //int id; // FIXME: for debugging only
+};
/* The key used for storing the thread descriptor in the specific data
of the corresponding system thread. */
@@ -138,7 +138,7 @@ static void caml_thread_scan_roots(scanning_action action)
th = curr_thread;
//DUMP("FIXME: ENSURE THAT ALL THREADS ARE REACHABLE FROM %p", th);
do {
- DUMP("caml_thread_t descriptor %p (pthread %p): begin", th, th->posix_thread);
+ //DUMP("caml_thread_t descriptor %p (pthread %p): begin", th, th->posix_thread);
//if(th->posix_thread == (void*)(pthread_t)(void*)(long)0){DUMP("@@@@@@@@@@@@@@@@@@@@@@@@@ SKIPPING");th = th->next; break;}; // !!!!!!!!!!!!!!!!!!
#ifdef NATIVE_CODE
//DUMP("th->bottom_of_stack=%p, th->last_retaddr=%lx, th->gc_regs=%p, th->local_roots=%p", th->bottom_of_stack, th->last_retaddr, th->gc_regs, th->local_roots);
@@ -394,8 +394,8 @@ static caml_thread_t caml_thread_new_info(void)
th->backtrace_buffer = NULL;
th->backtrace_last_exn = Val_unit;
th->ctx = (void*)(long)0xdead; /* an intentionally invalid value, to aid debugging */
- th->posix_thread = (pthread_t)(void*)0xbadbadbad; /* an intentionally invalid value, to aid debugging */
- th->id = (int)-2;
+ //th->posix_thread = (pthread_t)(void*)0xbadbadbad; /* an intentionally invalid value, to aid debugging */
+ //th->id = (int)-2;
QR();
return th;
}
@@ -531,8 +531,8 @@ static void caml_thread_initialize_for_current_context_r(CAML_R){
#endif
//// @@@@@@@@@
curr_thread->ctx = ctx;
- curr_thread->posix_thread = 0;
- curr_thread->id = (int)thread_next_ident;
+ //curr_thread->posix_thread = 0;
+ //curr_thread->id = (int)thread_next_ident;
//// @@@@@@@@@
/* The stack-related fields will be filled in at the next
enter_blocking_section */
@@ -544,7 +544,7 @@ static void caml_thread_initialize_for_current_context_r(CAML_R){
QR();
}
-static int caml_posix_get_thread_no_r(CAML_R);
+static int caml_systhreads_get_thread_no_r(CAML_R);
/* Initialize the global thread machinery */
@@ -558,7 +558,7 @@ CAMLprim value caml_thread_initialize_r(CAML_R, value unit) /* ML */
if(already_initialized) {QR(); return Val_unit;} else already_initialized = 1;
DUMP("");
- caml_set_caml_get_thread_no_r(ctx, caml_posix_get_thread_no_r);
+ caml_set_caml_get_thread_no_r(ctx, caml_systhreads_get_thread_no_r);
DUMP("");
caml_set_caml_initialize_context_thread_support(ctx, caml_thread_initialize_for_current_context_r);
DUMP("");
@@ -684,7 +684,7 @@ static void caml_thread_stop_r(CAML_R)
}
/* Return the number of threads associated to the given context: */
-static int caml_posix_get_thread_no_r(CAML_R){
+static int caml_systhreads_get_thread_no_r(CAML_R){
QB();
//QDUMP("!!!!!!!!!!![%p %p]", curr_thread, all_threads);
int result = 0;
@@ -735,7 +735,7 @@ static ST_THREAD_FUNCTION caml_thread_start(void * arg)
caml_thread_t th = (caml_thread_t) arg;
//??? does th point to something which is destroyed by the GC ??? !!!!!!!!!!!!!!!!!!!!
CAML_R = th->ctx;
- th->posix_thread = (void*)pthread_self();
+ //th->posix_thread = (void*)pthread_self();
DUMP("Now threads are %i, including this one", caml_get_thread_no_r(ctx));
value clos;
#ifdef NATIVE_CODE
Oops, something went wrong.

0 comments on commit 478a1fa

Please sign in to comment.