Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make signals safe for multicore #630

Merged
10 changes: 0 additions & 10 deletions runtime/caml/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ void caml_handle_gc_interrupt(void);

void caml_handle_incoming_interrupts(void);

void caml_request_major_slice (void);

void caml_request_minor_gc (void);

void caml_interrupt_self(void);

void caml_print_stats(void);
Expand All @@ -57,12 +53,6 @@ CAMLexport void caml_bt_exit_ocaml(void);
CAMLexport void caml_acquire_domain_lock(void);
CAMLexport void caml_release_domain_lock(void);

CAMLextern void caml_enter_blocking_section(void);
CAMLextern void caml_leave_blocking_section(void);

CAMLextern void (*caml_enter_blocking_section_hook)(void);
CAMLextern void (*caml_leave_blocking_section_hook)(void);

CAMLextern void (*caml_atfork_hook)(void);

CAMLextern void (*caml_domain_start_hook)(void);
Expand Down
1 change: 1 addition & 0 deletions runtime/caml/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include "config.h"
#include "mlvalues.h"
#include "signals.h"
sadiqj marked this conversation as resolved.
Show resolved Hide resolved

#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
#define MAP_ANONYMOUS MAP_ANON
Expand Down
38 changes: 24 additions & 14 deletions runtime/caml/signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#ifndef CAML_SIGNALS_H
#define CAML_SIGNALS_H

#if defined(CAML_INTERNALS) && defined(POSIX_SIGNALS)
#include<signal.h>
#endif

#ifndef CAML_NAME_SPACE
#include "compatibility.h"
#endif
Expand All @@ -26,31 +30,37 @@
extern "C" {
#endif

#ifdef CAML_INTERNALS
CAMLextern intnat volatile caml_signals_are_pending;
CAMLextern intnat volatile caml_pending_signals[];
CAMLextern int volatile caml_something_to_do;
int caml_init_signal_stack(void);
void caml_free_signal_stack(void);
void caml_init_signal_handling(void);
/* </private> */

CAMLextern void caml_enter_blocking_section (void);
CAMLextern void caml_enter_blocking_section_no_pending (void);
CAMLextern void caml_leave_blocking_section (void);

#ifdef CAML_INTERNALS
CAMLextern atomic_intnat caml_pending_signals[];

/* Global variables moved to Caml_state in 4.10 */
#define caml_requested_major_slice (Caml_state_field(requested_major_slice))
#define caml_requested_minor_gc (Caml_state_field(requested_minor_gc))

void caml_update_young_limit(void);
void caml_request_major_slice (void);
void caml_request_minor_gc (void);
CAMLextern int caml_convert_signal_number (int);
CAMLextern int caml_rev_convert_signal_number (int);
value caml_execute_signal_exn(int signal_number, int in_signal_handler);
CAMLextern void caml_record_signal(int signal_number);
CAMLextern void caml_process_pending_signals(void);
CAMLextern value caml_process_pending_signals_exn(void);
void caml_set_action_pending (void);
int caml_set_signal_action(int signo, int action);

CAMLextern value caml_process_pending_signals_with_root_exn (value extra_root);
void caml_init_signal_handling(void);
int caml_init_signal_stack(void);
void caml_free_signal_stack(void);

CAMLextern void (* volatile caml_async_action_hook)(void);
CAMLextern void (*caml_enter_blocking_section_hook)(void);
CAMLextern void (*caml_leave_blocking_section_hook)(void);
#endif /* CAML_INTERNALS */

CAMLextern void caml_enter_blocking_section (void);
CAMLextern void caml_leave_blocking_section (void);

#ifdef __cplusplus
}
#endif
Expand Down
44 changes: 0 additions & 44 deletions runtime/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,22 +995,6 @@ void caml_interrupt_self() {
interrupt_domain(&domain_self->interruptor);
}

/* Arrange for a major GC slice to be performed on the current domain
as soon as possible */
void caml_request_major_slice (void)
sadiqj marked this conversation as resolved.
Show resolved Hide resolved
{
Caml_state->requested_major_slice = 1;
caml_interrupt_self();
}

/* Arrange for a minor GC to be performed on the current domain
as soon as possible */
void caml_request_minor_gc (void)
{
Caml_state->requested_minor_gc = 1;
caml_interrupt_self();
}

static void caml_poll_gc_work()
{
CAMLalloc_point_here;
Expand Down Expand Up @@ -1117,34 +1101,6 @@ CAMLexport void caml_bt_exit_ocaml(void)
}
}

static void caml_enter_blocking_section_default(void)
{
caml_bt_exit_ocaml();
caml_release_domain_lock();
}

static void caml_leave_blocking_section_default(void)
{
caml_bt_enter_ocaml();
caml_acquire_domain_lock();
}

CAMLexport void (*caml_enter_blocking_section_hook)(void) =
caml_enter_blocking_section_default;
CAMLexport void (*caml_leave_blocking_section_hook)(void) =
caml_leave_blocking_section_default;

CAMLexport void caml_leave_blocking_section() {
caml_leave_blocking_section_hook();
caml_process_pending_signals();
}

CAMLexport void caml_enter_blocking_section() {

caml_process_pending_signals();
caml_enter_blocking_section_hook();
}

/* default handler for unix_fork, will be called by unix_fork. */
static void caml_atfork_default(void) {
caml_reset_domain_lock();
Expand Down
1 change: 1 addition & 0 deletions runtime/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ value caml_interprete(code_t prog, asize_t prog_size)
process_signal:
Setup_for_event;
caml_handle_gc_interrupt();
caml_raise_if_exception(caml_process_pending_signals_exn());
Restore_after_event;
Next;

Expand Down
1 change: 1 addition & 0 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "caml/mlvalues.h"
#include "caml/platform.h"
#include "caml/roots.h"
#include "caml/signals.h"
#include "caml/shared_heap.h"
#include "caml/startup_aux.h"
#include "caml/weak.h"
Expand Down
1 change: 1 addition & 0 deletions runtime/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "caml/fail.h"
#include "caml/memory.h"
#include "caml/major_gc.h"
#include "caml/signals.h"
#include "caml/shared_heap.h"
#include "caml/domain.h"
#include "caml/roots.h"
Expand Down