@@ -33,16 +33,85 @@ extern "C" {
3333CAMLextern void caml_enter_blocking_section (void ); //raises
3434CAMLextern void caml_leave_blocking_section (void ); //raises
3535
36+ /* Asynchronous actions
37+
38+ We distinguish two kinds of asynchronous actions:
39+
40+ - unrestricted asynchronous callbacks: possibly-raising signal
41+ handlers, memprof callbacks and finalisers (including GC alarms).
42+
43+ - non-raising actions, such as non-raising signal handlers (e.g.
44+ systhread's yield).
45+
46+ Signal handlers in particular are defined as one of two kinds,
47+ non-raising and raising. Non-raising handlers must guarantee that
48+ they do not raise or fail, but also that they are brief (typically,
49+ systhread's yield()), because themselves cannot be interrupted.
50+
51+ In contrast, asynchronous callbacks of the second kind are allowed
52+ to raise an exception (typically, when handling SIGINT or SIGALRM),
53+ are not limited in what they can express (typically, finalisers and
54+ memprof callbacks), and can themselves be interrupted by
55+ asynchronous callbacks.
56+
57+ Masking temporarily delays the execution of asynchronous callbacks.
58+ There are two kinds of masking:
59+
60+ - _interruptible masks_ delay the execution of unrestricted
61+ asynchronous callbacks, whereas
62+
63+ - _uninterruptible masks_ delay execution of all asynchronous
64+ callbacks.
65+
66+ This gives three possible values for masking: CAML_MASK_NONE,
67+ CAML_MASK_INTERRUPTIBLE and CAML_MASK_UNINTERRUPTIBLE.
68+
69+ In particular:
70+
71+ - a program in an interruptible mask will not be interrupted by
72+ asynchronous exceptions;
73+
74+ - with systhreads, a program in an interruptible mask will yield to
75+ other threads, while one in an uninterruptible mask will not.
76+ */
77+
78+ CAMLextern caml_mask_kind caml_mask (caml_mask_kind new_mask );
79+ CAMLextern void caml_unmask (caml_mask_kind old_mask );
80+ /* The caml_mask functions set an interruptible or uninterruptible
81+ mask and return the previous mask. The caml_unmask function sets
82+ the previous mask back. Assumes that the runtime lock is held.
83+
84+ The caml_mask function never undoes a previous mask, that is,
85+ calling caml_mask(CAML_MASK_INTERRUPTIBLE) has no effect inside an
86+ uninterruptible mask. Similarly, caml_mask(CAML_MASK_NONE) has no
87+ effect at all, it thus can be used to query the current mask.
88+
89+ Calls to caml_mask and caml_unmask must be correctly bracketed and
90+ caml_unmask must be supplied value returned from the corresponding
91+ call to caml_mask (the previous mask). It is incorrect to call
92+ caml_unmask with a different mask, so as to undo a mask one does
93+ not own.
94+
95+ Example:
96+
97+ caml_mask_kind old_mask = caml_mask(CAML_MASK_INTERRUPTIBLE);
98+ ...(no raising of exception)...
99+ caml_unmask(old_mask);
100+ */
101+
36102CAMLextern void caml_process_pending_actions (void );
37- /* Checks for pending actions and executes them. This includes pending
38- minor and major collections, signal handlers, finalisers, and
39- Memprof callbacks. Assumes that the runtime lock is held. Can raise
40- exceptions asynchronously into OCaml code. */
103+ /* Checks for pending actions and executes them, depending on the
104+ current mask. Assumes that the runtime lock is held.
105+
106+ Can raise exceptions asynchronously into OCaml code if the current
107+ mask is CAML_MASK_NONE.
108+ */
41109
42110CAMLextern value caml_process_pending_actions_exn (void );
43111/* Same as [caml_process_pending_actions], but returns the encoded
44112 exception if any (otherwise returns [Val_unit]). */
45113
114+
46115#ifdef CAML_INTERNALS
47116CAMLextern intnat volatile caml_pending_signals [];
48117
@@ -58,9 +127,9 @@ CAMLextern int caml_convert_signal_number (int);
58127CAMLextern int caml_rev_convert_signal_number (int );
59128value caml_execute_signal_exn (int signal_number , int in_signal_handler );
60129void caml_record_signal (int signal_number );
61- value caml_process_pending_signals_exn ( void );
130+ void caml_handle_signal ( int signal_number );
62131
63- int caml_has_action_pending (void );
132+ int caml_has_action_to_do (void );
64133void caml_set_action_pending (void );
65134void caml_notify_action (void );
66135value caml_do_pending_actions_exn (void );
0 commit comments