* exceptions.cc (signal_exit): Reset all mutos owned by the main thread.

* fhandler.h: Define *_output_mutex macros for serializing tty output.
(fhandler_termios): Remove restart_output_event.  Define dummy output mutex
methods.
(fhandler_pty_master): Remove unneeded fixup_after_fork method.
* fhandler_termios.cc (fhandler_termios::line_edit): Acquire output_mutex when
CTRL-S is hit.  Release it on CTRL-Q.
* fhandler_tty.cc (fhandler_pty_master::process_slave_output): Remove
inappropriate OutputStopped test here.  Just use the output mutex.
(fhandler_pty_master::fhandler_pty_master): Remove obsolete reference to
restart_output_event.
(fhandler_tty_common::close): Ditto.
(fhandler_pty_master::set_close_on_exec): Ditto.
(fhandler_pty_master::fixup_after_fork): Delete.
* tty.cc (tty::common_init): Ditto.
* sync.cc (muto::reset): New method.
* sync.h: Declare above method.
This commit is contained in:
Christopher Faylor 2000-09-07 01:18:37 +00:00
parent 8dec7b0379
commit c1644acb23
8 changed files with 55 additions and 32 deletions

View File

@ -1,3 +1,24 @@
Wed Sep 6 21:11:13 2000 Christopher Faylor <cgf@cygnus.com>
* exceptions.cc (signal_exit): Reset all mutos owned by the main
thread.
* fhandler.h: Define *_output_mutex macros for serializing tty output.
(fhandler_termios): Remove restart_output_event. Define dummy output
mutex methods.
(fhandler_pty_master): Remove unneeded fixup_after_fork method.
* fhandler_termios.cc (fhandler_termios::line_edit): Acquire
output_mutex when CTRL-S is hit. Release it on CTRL-Q.
* fhandler_tty.cc (fhandler_pty_master::process_slave_output): Remove
inappropriate OutputStopped test here. Just use the output mutex.
(fhandler_pty_master::fhandler_pty_master): Remove obsolete reference
to restart_output_event.
(fhandler_tty_common::close): Ditto.
(fhandler_pty_master::set_close_on_exec): Ditto.
(fhandler_pty_master::fixup_after_fork): Delete.
* tty.cc (tty::common_init): Ditto.
* sync.cc (muto::reset): New method.
* sync.h: Declare above method.
Wed Sep 6 16:56:38 2000 Christopher Faylor <cgf@cygnus.com> Wed Sep 6 16:56:38 2000 Christopher Faylor <cgf@cygnus.com>
* sigproc.cc: Add include file for proper definitions. * sigproc.cc: Add include file for proper definitions.

View File

@ -1007,6 +1007,12 @@ signal_exit (int rc)
/* If the exception handler gets a trap, we could recurse awhile. /* If the exception handler gets a trap, we could recurse awhile.
If this is non-zero, skip the cleaning up and exit NOW. */ If this is non-zero, skip the cleaning up and exit NOW. */
muto *m;
/* FIXME: Make multi-thread aware */
for (m = muto_start.next; m != NULL; m = m->next)
if (m->unstable () || m->owner () == mainthread.id)
m->reset ();
rc = EXIT_SIGNAL | (rc << 8); rc = EXIT_SIGNAL | (rc << 8);
if (exit_already++) if (exit_already++)
{ {

View File

@ -505,6 +505,12 @@ public:
int ready_for_read (int fd, DWORD howlong, int ignra); int ready_for_read (int fd, DWORD howlong, int ignra);
}; };
#define acquire_output_mutex(ms) \
__acquire_output_mutex (__PRETTY_FUNCTION__, __LINE__, ms);
#define release_output_mutex() \
__release_output_mutex (__PRETTY_FUNCTION__, __LINE__);
class fhandler_termios: public fhandler_base class fhandler_termios: public fhandler_base
{ {
protected: protected:
@ -518,7 +524,6 @@ public:
{ {
// nothing to do // nothing to do
} }
HANDLE restart_output_event;
HANDLE get_output_handle () const { return output_handle; } HANDLE get_output_handle () const { return output_handle; }
int line_edit (const char *rptr, int nread, int always_accept = 0); int line_edit (const char *rptr, int nread, int always_accept = 0);
void set_output_handle (HANDLE h) { output_handle = h; } void set_output_handle (HANDLE h) { output_handle = h; }
@ -528,6 +533,8 @@ public:
int tcsetpgrp (int pid); int tcsetpgrp (int pid);
void set_ctty (int ttynum, int flags); void set_ctty (int ttynum, int flags);
int bg_check (int sig); int bg_check (int sig);
virtual DWORD __acquire_output_mutex (const char *fn, int ln, DWORD ms) {return 1;}
virtual void __release_output_mutex (const char *fn, int ln) {}
}; };
/* This is a input and output console handle */ /* This is a input and output console handle */
@ -692,7 +699,6 @@ public:
char *ptsname (); char *ptsname ();
void set_close_on_exec (int val); void set_close_on_exec (int val);
void fixup_after_fork (HANDLE parent);
BOOL hit_eof (); BOOL hit_eof ();
}; };

View File

@ -213,14 +213,18 @@ fhandler_termios::line_edit (const char *rptr, int nread, int always_accept)
{ {
if (c == tc->ti.c_cc[VSTOP]) if (c == tc->ti.c_cc[VSTOP])
{ {
tc->OutputStopped++; if (!tc->OutputStopped)
{
tc->OutputStopped = 1;
acquire_output_mutex (INFINITE);
}
continue; continue;
} }
else if (c == tc->ti.c_cc[VSTART]) else if (c == tc->ti.c_cc[VSTART])
{ {
restart_output: restart_output:
tc->OutputStopped = 0; tc->OutputStopped = 0;
SetEvent (restart_output_event); release_output_mutex ();
continue; continue;
} }
else if ((tc->ti.c_iflag & IXANY) && tc->OutputStopped) else if ((tc->ti.c_iflag & IXANY) && tc->OutputStopped)

View File

@ -149,12 +149,6 @@ fhandler_tty_common::__release_output_mutex (const char *fn, int ln)
} }
} }
#define acquire_output_mutex(ms) \
__acquire_output_mutex (__PRETTY_FUNCTION__, __LINE__, ms);
#define release_output_mutex() \
__release_output_mutex (__PRETTY_FUNCTION__, __LINE__);
/* Process tty input. */ /* Process tty input. */
void void
@ -300,13 +294,6 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on
continue; continue;
} }
if (get_ttyp ()->OutputStopped)
{
termios_printf ("waiting for restart_output_event");
WaitForSingleObject (restart_output_event, INFINITE);
termios_printf ("done waiting for restart_output_event");
}
char *optr; char *optr;
optr = buf; optr = buf;
if (pktmode_on) if (pktmode_on)
@ -866,7 +853,6 @@ fhandler_pty_master::fhandler_pty_master (const char *name, DWORD devtype, int u
set_cb (sizeof *this); set_cb (sizeof *this);
ioctl_request_event = NULL; ioctl_request_event = NULL;
ioctl_done_event = NULL; ioctl_done_event = NULL;
restart_output_event = NULL;
pktmode = need_nl = 0; pktmode = need_nl = 0;
inuse = NULL; inuse = NULL;
} }
@ -895,8 +881,6 @@ fhandler_tty_common::close ()
termios_printf ("CloseHandle (ioctl_done_event), %E"); termios_printf ("CloseHandle (ioctl_done_event), %E");
if (ioctl_request_event && !CloseHandle (ioctl_request_event)) if (ioctl_request_event && !CloseHandle (ioctl_request_event))
termios_printf ("CloseHandle (ioctl_request_event), %E"); termios_printf ("CloseHandle (ioctl_request_event), %E");
if (restart_output_event && !CloseHandle (restart_output_event))
termios_printf ("CloseHandle (restart_output_event), %E");
if (inuse && !CloseHandle (inuse)) if (inuse && !CloseHandle (inuse))
termios_printf ("CloseHandle (inuse), %E"); termios_printf ("CloseHandle (inuse), %E");
if (!ForceCloseHandle (output_mutex)) if (!ForceCloseHandle (output_mutex))
@ -1051,7 +1035,6 @@ void
fhandler_pty_master::set_close_on_exec (int val) fhandler_pty_master::set_close_on_exec (int val)
{ {
this->fhandler_tty_common::set_close_on_exec (val); this->fhandler_tty_common::set_close_on_exec (val);
set_inheritance (restart_output_event, val);
/* FIXME: There is a console handle leak here. */ /* FIXME: There is a console handle leak here. */
if (get_ttyp ()->master_pid == GetCurrentProcessId ()) if (get_ttyp ()->master_pid == GetCurrentProcessId ())
@ -1061,14 +1044,6 @@ fhandler_pty_master::set_close_on_exec (int val)
} }
} }
void
fhandler_pty_master::fixup_after_fork (HANDLE child)
{
this->fhandler_tty_common::fixup_after_fork (child);
if (restart_output_event)
fork_fixup (child, restart_output_event, "restart_output_event");
}
void void
fhandler_tty_master::fixup_after_fork (HANDLE child) fhandler_tty_master::fixup_after_fork (HANDLE child)
{ {

View File

@ -125,3 +125,16 @@ muto::release ()
return 1; /* success. */ return 1; /* success. */
} }
/* Call only when we're exiting. This is not thread safe. */
void
muto::reset ()
{
visits = sync = tid = 0;
InterlockedExchange (&waiters, -1);
if (bruteforce)
{
CloseHandle (bruteforce);
bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, name);
}
}

View File

@ -40,6 +40,7 @@ public:
int ismine () {return tid == GetCurrentThreadId ();} int ismine () {return tid == GetCurrentThreadId ();}
DWORD owner () {return tid;} DWORD owner () {return tid;}
int unstable () {return !tid && (sync || waiters >= 0);} int unstable () {return !tid && (sync || waiters >= 0);}
void reset ();
}; };
extern muto muto_start; extern muto muto_start;

View File

@ -388,9 +388,6 @@ tty::common_init (fhandler_pty_master *ptym)
/* Create synchronisation events */ /* Create synchronisation events */
if (!(ptym->restart_output_event = get_event (RESTART_OUTPUT_EVENT, TRUE)))
return FALSE;
if (ptym->get_device () != FH_TTYM) if (ptym->get_device () != FH_TTYM)
{ {
ptym->output_done_event = ptym->ioctl_done_event = ptym->output_done_event = ptym->ioctl_done_event =