Lock channels before doing I/O
The debugger's use of channels doesn't support locking, but it doesn't work on threaded programs anyway.master
parent
ba2b98608a
commit
e678885007
|
@ -71,8 +71,10 @@ static void logToChannel(void *voidchannel, const char *fmt, va_list ap)
|
|||
if (text == NULL) return;
|
||||
if (vsnprintf(text, length, fmt, ap) != length) goto end;
|
||||
}
|
||||
Lock(channel);
|
||||
caml_putblock(channel, text, length);
|
||||
caml_flush(channel);
|
||||
Unlock(channel);
|
||||
end:
|
||||
free(text);
|
||||
}
|
||||
|
|
|
@ -386,6 +386,7 @@ static void read_main_debug_info(struct debug_info *di)
|
|||
if (caml_seek_optional_section(fd, &trail, "DBUG") != -1) {
|
||||
chan = caml_open_descriptor_in(fd);
|
||||
|
||||
Lock(chan);
|
||||
num_events = caml_getword(chan);
|
||||
events = caml_alloc(num_events, 0);
|
||||
|
||||
|
@ -401,6 +402,7 @@ static void read_main_debug_info(struct debug_info *di)
|
|||
/* Record event list */
|
||||
Store_field(events, i, evl);
|
||||
}
|
||||
Unlock(chan);
|
||||
|
||||
caml_close_channel(chan);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ enum {
|
|||
*/
|
||||
|
||||
/* Functions and macros that can be called from C. Take arguments of
|
||||
type struct channel *. No locking is performed. */
|
||||
type struct channel *. The channel must be locked before calling these. */
|
||||
|
||||
#define caml_putch(channel, ch) do{ \
|
||||
if ((channel)->curr >= (channel)->end) caml_flush_partial(channel); \
|
||||
|
|
|
@ -141,6 +141,12 @@ static void open_connection(void)
|
|||
#endif
|
||||
dbg_in = caml_open_descriptor_in(dbg_socket);
|
||||
dbg_out = caml_open_descriptor_out(dbg_socket);
|
||||
/* The code in this file does not bracket channel I/O operations with
|
||||
Lock and Unlock, so fail if those are not no-ops. */
|
||||
if (caml_channel_mutex_lock != NULL ||
|
||||
caml_channel_mutex_unlock != NULL ||
|
||||
caml_channel_mutex_unlock_exn != NULL)
|
||||
caml_fatal_error("debugger does not support channel locks");
|
||||
if (!caml_debugger_in_use) caml_putword(dbg_out, -1); /* first connection */
|
||||
#ifdef _WIN32
|
||||
caml_putword(dbg_out, _getpid());
|
||||
|
|
|
@ -444,7 +444,9 @@ CAMLexport void caml_main(char_os **argv)
|
|||
/* Load the globals */
|
||||
caml_seek_section(fd, &trail, "DATA");
|
||||
chan = caml_open_descriptor_in(fd);
|
||||
Lock(chan);
|
||||
caml_global_data = caml_input_val(chan);
|
||||
Unlock(chan);
|
||||
caml_close_channel(chan); /* this also closes fd */
|
||||
caml_stat_free(trail.section);
|
||||
/* Ensure that the globals are in the major heap. */
|
||||
|
|
Loading…
Reference in New Issue