From 150227638b46c8cac06515ef3660d221194fb77c Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Thu, 19 Jun 1997 05:55:51 +0000 Subject: [PATCH] Fix bug: microcode was forgetting about file being opened when it ran out of channel-table entries. This left the file locked until Scheme was exited. Additionally, the size of the channel table has been increased, and the number of allowable handles set to its maximum value. --- v7/src/microcode/ntfile.c | 20 +++++++------- v7/src/microcode/ntio.c | 57 ++++++++++++++++++++++++++++++++++----- v7/src/microcode/ntio.h | 20 ++++---------- 3 files changed, 66 insertions(+), 31 deletions(-) diff --git a/v7/src/microcode/ntfile.c b/v7/src/microcode/ntfile.c index 64f1d7caa..1e31fa812 100644 --- a/v7/src/microcode/ntfile.c +++ b/v7/src/microcode/ntfile.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntfile.c,v 1.8 1997/01/05 23:38:12 cph Exp $ +$Id: ntfile.c,v 1.9 1997/06/19 05:55:34 cph Exp $ Copyright (c) 1992-97 Massachusetts Institute of Technology @@ -62,24 +62,24 @@ DEFUN (OS_open_handle, (hFile), HANDLE hFile) Tchannel channel; // if (hFile == STDIN_HANDLE) { -// MAKE_CHANNEL (STDIN_HANDLE, channel_type_terminal, channel=); +// channel = (NT_make_channel (STDIN_HANDLE, channel_type_terminal)); // CHANNEL_COOKED(channel) = 1; // } // // else if (hFile == STDOUT_HANDLE) { -// MAKE_CHANNEL (STDOUT_HANDLE, channel_type_terminal, channel=); +// channel = (NT_make_channel (STDOUT_HANDLE, channel_type_terminal)); // CHANNEL_COOKED(channel) = 1; // } // // else if (hFile == STDERR_HANDLE) { -// MAKE_CHANNEL (STDERR_HANDLE, channel_type_terminal, channel=); +// channel = (NT_make_channel (STDERR_HANDLE, channel_type_terminal)); // CHANNEL_COOKED(channel) = 1; // } // else { type = handle_channel_type (hFile); - MAKE_CHANNEL (hFile, type, channel =); + channel = (NT_make_channel (hFile, type)); /* Like Unix, all terminals initialize to cooked mode. */ if (type == channel_type_terminal) @@ -152,11 +152,11 @@ static Tchannel DEFUN (make_load_channel, (handle), HANDLE handle) { enum channel_type type = handle_channel_type (handle); - if ((type == channel_type_terminal) - || (type == channel_type_directory) - ) - return (NO_CHANNEL); - MAKE_CHANNEL (handle, type, return); + return + (((type == channel_type_terminal) + || (type == channel_type_directory)) + ? NO_CHANNEL + : (NT_make_channel (handle, type))); } Tchannel diff --git a/v7/src/microcode/ntio.c b/v7/src/microcode/ntio.c index f596f05d4..43c2a67cb 100644 --- a/v7/src/microcode/ntio.c +++ b/v7/src/microcode/ntio.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntio.c,v 1.14 1997/01/02 05:21:38 cph Exp $ +$Id: ntio.c,v 1.15 1997/06/19 05:55:43 cph Exp $ Copyright (c) 1992-97 Massachusetts Institute of Technology @@ -46,7 +46,13 @@ MIT in each case. */ #ifndef fileno #define fileno(fp) ((fp)->_file) #endif + +static Tchannel channel_allocate (void); +#ifndef NT_DEFAULT_CHANNEL_TABLE_SIZE +#define NT_DEFAULT_CHANNEL_TABLE_SIZE 1024 +#endif + size_t OS_channel_table_size; struct channel * channel_table; @@ -54,6 +60,29 @@ struct channel * channel_table; HANDLE STDIN_HANDLE, STDOUT_HANDLE, STDERR_HANDLE; #endif +Tchannel +NT_make_channel (HANDLE handle, enum channel_type type) +{ + Tchannel channel; + transaction_begin (); + NT_handle_close_on_abort (handle); + channel = (channel_allocate ()); + NT_initialize_channel (channel, handle, type); + transaction_commit (); + return (channel); +} + +void +NT_initialize_channel (Tchannel channel, HANDLE handle, enum channel_type type) +{ + (CHANNEL_HANDLE (channel)) = handle; + (CHANNEL_TYPE (channel)) = type; + (CHANNEL_INTERNAL (channel)) = 0; + (CHANNEL_NONBLOCKING (channel)) = 0; + (CHANNEL_BUFFERED (channel)) = 1; + (CHANNEL_COOKED (channel)) = 0; +} + static void DEFUN_VOID (NT_channel_close_all) { @@ -78,8 +107,8 @@ NT_ctrl_handler (DWORD dwCtrlType) } #endif /* GUI */ -Tchannel -DEFUN_VOID (channel_allocate) +static Tchannel +channel_allocate (void) { Tchannel channel = 0; while (1) @@ -125,7 +154,6 @@ static void DEFUN (channel_close_on_abort_1, (cp), PTR cp) { OS_channel_close (* ((Tchannel *) cp)); - return; } void @@ -134,7 +162,20 @@ DEFUN (OS_channel_close_on_abort, (channel), Tchannel channel) Tchannel * cp = ((Tchannel *) (dstack_alloc (sizeof (Tchannel)))); (*cp) = (channel); transaction_record_action (tat_abort, channel_close_on_abort_1, cp); - return; +} + +static void +NT_handle_close_on_abort_1 (void * hp) +{ + (void) CloseHandle (* ((HANDLE *) hp)); +} + +void +NT_handle_close_on_abort (HANDLE h) +{ + HANDLE * hp = (dstack_alloc (sizeof (HANDLE))); + (*hp) = h; + transaction_record_action (tat_abort, NT_handle_close_on_abort_1, hp); } enum channel_type @@ -577,7 +618,11 @@ DEFUN_VOID (NT_initialize_channels) OS_have_select_p = 0; else OS_have_select_p = 1; - OS_channel_table_size = (NT_SC_OPEN_MAX ()); + /* The following API call boosts the number of available handles to + its maximum value. This has no effect under NT, which does not + place a limit on the number of handles. */ + (void) SetHandleCount (255); + OS_channel_table_size = NT_DEFAULT_CHANNEL_TABLE_SIZE; channel_table = (malloc (OS_channel_table_size * (sizeof (struct channel)))); if (channel_table == 0) { diff --git a/v7/src/microcode/ntio.h b/v7/src/microcode/ntio.h index 6a66fe34d..58d5b1e33 100644 --- a/v7/src/microcode/ntio.h +++ b/v7/src/microcode/ntio.h @@ -1,8 +1,8 @@ /* -*-C-*- -$Id: ntio.h,v 1.6 1994/11/14 00:54:27 cph Exp $ +$Id: ntio.h,v 1.7 1997/06/19 05:55:51 cph Exp $ -Copyright (c) 1992-94 Massachusetts Institute of Technology +Copyright (c) 1992-97 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -60,20 +60,10 @@ struct channel #define CHANNEL_BUFFERED(channel) ((channel_table [(channel)]) . buffered) #define CHANNEL_COOKED(channel) ((channel_table [(channel)]) . cooked) -#define MAKE_CHANNEL(descriptor, type, receiver) \ -{ \ - Tchannel MAKE_CHANNEL_temp = (channel_allocate ()); \ - (CHANNEL_HANDLE (MAKE_CHANNEL_temp)) = (descriptor); \ - (CHANNEL_TYPE (MAKE_CHANNEL_temp)) = (type); \ - (CHANNEL_INTERNAL (MAKE_CHANNEL_temp)) = 0; \ - (CHANNEL_NONBLOCKING (MAKE_CHANNEL_temp)) = 0; \ - (CHANNEL_BUFFERED (MAKE_CHANNEL_temp)) = 1; \ - (CHANNEL_COOKED (MAKE_CHANNEL_temp)) = 0; \ - receiver (MAKE_CHANNEL_temp); \ -} - extern struct channel * channel_table; -extern Tchannel EXFUN (channel_allocate, (void)); +extern Tchannel NT_make_channel (HANDLE, enum channel_type); +extern void NT_initialize_channel (Tchannel, HANDLE, enum channel_type); +extern void NT_handle_close_on_abort (HANDLE); #define BACKSPACE '\b' #define SPACE ' ' -- 2.25.1