Fix final round of gcc warnings relating to unused parameters.

* debug.cc (iscygthread): New function.
* debug.h: Declare it.
* exceptions.cc (set_process_mask): Flush pending signals.
(handle_sigsuspend): No need to flush pending signals.
(call_handler): Refine previous tests of muto ownership.  Only clear wait()'s
when we have definitely responded to a signal.
* fhandler_console.cc (fhandler_console::read): Don't set EINTR if executing in
a "cygwin" thread.
* sigproc.cc (proc_subproc): Use second argument to control whether CLEARWAIT
actually sets "signalled" flag.
* sync.h (muto): Add 'unstable' method.
This commit is contained in:
Christopher Faylor 2000-02-24 06:45:32 +00:00
parent fb87c246a7
commit 9aa07a8f60
9 changed files with 65 additions and 26 deletions

View File

@ -1,6 +1,17 @@
Wed Feb 23 22:51:27 2000 Christopher Faylor <cgf@cygnus.com> Thu Feb 24 00:59:15 2000 Christopher Faylor <cgf@cygnus.com>
Fix final round of gcc warnings relating to unused parameters. Fix final round of gcc warnings relating to unused parameters.
* debug.cc (iscygthread): New function.
* debug.h: Declare it.
* exceptions.cc (set_process_mask): Flush pending signals.
(handle_sigsuspend): No need to flush pending signals.
(call_handler): Refine previous tests of muto ownership. Only clear
wait()'s when we have definitely responded to a signal.
* fhandler_console.cc (fhandler_console::read): Don't set EINTR if
executing in a "cygwin" thread.
* sigproc.cc (proc_subproc): Use second argument to control whether
CLEARWAIT actually sets "signalled" flag.
* sync.h (muto): Add 'unstable' method.
Wed Feb 23 21:59:44 2000 Christopher Faylor <cgf@cygnus.com> Wed Feb 23 21:59:44 2000 Christopher Faylor <cgf@cygnus.com>
@ -10,7 +21,7 @@ Wed Feb 23 21:34:58 2000 Christopher Faylor <cgf@cygnus.com>
* exceptions.cc (interruptible): Change method for determining if * exceptions.cc (interruptible): Change method for determining if
something is interruptible. something is interruptible.
(call_handler): Avoid suspending a thread if it owns a mutex. Only set (call_handler): Avoid suspending a thread if it owns a muto. Only set
signal_arrived if the thread was actually interrupted. signal_arrived if the thread was actually interrupted.
(events_init): Initialize module information needed by interruptible(). (events_init): Initialize module information needed by interruptible().
(sigdelayed): Don't call sig_dispatch_pending since it could screw up (sigdelayed): Don't call sig_dispatch_pending since it could screw up
@ -20,8 +31,6 @@ Wed Feb 23 21:34:58 2000 Christopher Faylor <cgf@cygnus.com>
bulk of the processing comes from the signal thread. bulk of the processing comes from the signal thread.
(wait_sig): Force processing of waiting threads if SIGCHLD is not (wait_sig): Force processing of waiting threads if SIGCHLD is not
processed. processed.
* sync.cc (muto::release): Set tid == 0 after lock is released or
signal processor will be confused.
Tue Feb 22 23:06:01 2000 Christopher Faylor <cgf@cygnus.com> Tue Feb 22 23:06:01 2000 Christopher Faylor <cgf@cygnus.com>

View File

@ -47,6 +47,17 @@ regthread (const char *name, DWORD tid)
unlock_threadname (); unlock_threadname ();
} }
int __stdcall
iscygthread()
{
DWORD tid = GetCurrentThreadId ();
if (tid != maintid)
for (DWORD i = 0; i < NTHREADS && threads[i].name != NULL; i++)
if (threads[i].id == tid)
return 1;
return 0;
}
struct thread_start struct thread_start
{ {
LONG notavail; LONG notavail;

View File

@ -30,6 +30,7 @@ void threadname_init ();
HANDLE __stdcall makethread (LPTHREAD_START_ROUTINE, LPVOID, DWORD, const char *); HANDLE __stdcall makethread (LPTHREAD_START_ROUTINE, LPVOID, DWORD, const char *);
const char * __stdcall threadname (DWORD, int lockit = TRUE); const char * __stdcall threadname (DWORD, int lockit = TRUE);
void __stdcall regthread (const char *, DWORD); void __stdcall regthread (const char *, DWORD);
int __stdcall iscygthread ();
#ifndef DEBUGGING #ifndef DEBUGGING
# define ForceCloseHandle CloseHandle # define ForceCloseHandle CloseHandle

View File

@ -598,7 +598,6 @@ handle_sigsuspend (sigset_t tempmask)
// interested in through. // interested in through.
sigproc_printf ("old mask %x, new mask %x", oldmask, tempmask); sigproc_printf ("old mask %x, new mask %x", oldmask, tempmask);
sig_dispatch_pending (0);
WaitForSingleObject (signal_arrived, INFINITE); WaitForSingleObject (signal_arrived, INFINITE);
set_sig_errno (EINTR); // Per POSIX set_sig_errno (EINTR); // Per POSIX
@ -705,6 +704,7 @@ set_sig_errno (int e)
{ {
set_errno (e); set_errno (e);
sigsave.saved_errno = e; sigsave.saved_errno = e;
debug_printf ("errno %d", e);
} }
static int static int
@ -738,21 +738,21 @@ call_handler (int sig, struct sigaction& siga, void *handler)
for (;;) for (;;)
{ {
res = SuspendThread (hth); res = SuspendThread (hth);
/* FIXME: Make multi-thread aware */
if (sync_proc_subproc->owner () != maintid && mask_sync->owner () != maintid)
break;
if (res) if (res)
goto set_pending; goto set_pending;
/* FIXME: Make multi-thread aware */
if (!sync_proc_subproc->unstable () && sync_proc_subproc->owner () != maintid &&
!mask_sync->unstable () && mask_sync->owner () != maintid)
break;
ResumeThread (hth); ResumeThread (hth);
Sleep (0); Sleep (0);
} }
sigproc_printf ("suspend said %d, %E", res); sigproc_printf ("suspend said %d, %E", res);
/* Clear any waiting threads prior to dispatching to handler function */
proc_subproc(PROC_CLEARWAIT, 0);
if (sigsave.cx) if (sigsave.cx)
{ {
cx = sigsave.cx; cx = sigsave.cx;
@ -782,8 +782,15 @@ call_handler (int sig, struct sigaction& siga, void *handler)
} }
(void) ResumeThread (hth); (void) ResumeThread (hth);
if (interrupted) if (interrupted)
{
/* Clear any waiting threads prior to dispatching to handler function */
proc_subproc(PROC_CLEARWAIT, 1);
/* Apparently we have to set signal_arrived after resuming the thread or it
is possible that the event will be ignored. */
(void) SetEvent (signal_arrived); // For an EINTR case (void) SetEvent (signal_arrived); // For an EINTR case
}
sigproc_printf ("armed signal_arrived %p, res %d", signal_arrived, res); sigproc_printf ("armed signal_arrived %p, res %d", signal_arrived, res);
out: out:
@ -840,11 +847,16 @@ ctrl_c_handler (DWORD type)
extern "C" void __stdcall extern "C" void __stdcall
set_process_mask (sigset_t newmask) set_process_mask (sigset_t newmask)
{ {
extern DWORD sigtid;
mask_sync->acquire (INFINITE); mask_sync->acquire (INFINITE);
sigset_t oldmask = myself->getsigmask ();
newmask &= ~SIG_NONMASKABLE; newmask &= ~SIG_NONMASKABLE;
sigproc_printf ("old mask = %x, new mask = %x", myself->getsigmask (), newmask); sigproc_printf ("old mask = %x, new mask = %x", myself->getsigmask (), newmask);
myself->setsigmask (newmask); // Set a new mask myself->setsigmask (newmask); // Set a new mask
mask_sync->release (); mask_sync->release ();
if (oldmask != newmask && GetCurrentThreadId () != sigtid)
sig_dispatch_pending ();
return; return;
} }
@ -1076,7 +1088,7 @@ _sigreturn:
addl $4,%%esp addl $4,%%esp
call _set_process_mask@4 call _set_process_mask@4
popl %%eax # saved errno popl %%eax # saved errno
testl %%eax,%%eax # lt 0 testl %%eax,%%eax # Is it < 0
jl 1f # yup. ignore it jl 1f # yup. ignore it
movl %1,%%ebx movl %1,%%ebx
movl %%eax,(%%ebx) movl %%eax,(%%ebx)

View File

@ -151,6 +151,7 @@ fhandler_console::read (void *pv, size_t buflen)
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
break; break;
case WAIT_OBJECT_0 + 1: case WAIT_OBJECT_0 + 1:
if (!iscygthread ())
set_sig_errno (EINTR); set_sig_errno (EINTR);
return -1; return -1;
default: default:

View File

@ -102,7 +102,7 @@ muto NO_COPY *sync_proc_subproc = NULL; // Control access to
// subproc stuff // subproc stuff
DWORD NO_COPY maintid = 0; // ID of the main thread DWORD NO_COPY maintid = 0; // ID of the main thread
Static DWORD sigtid = 0; // ID of the signal thread DWORD NO_COPY sigtid = 0; // ID of the signal thread
int NO_COPY pending_signals = 0; // TRUE if signals pending int NO_COPY pending_signals = 0; // TRUE if signals pending
@ -245,7 +245,7 @@ proc_subproc (DWORD what, DWORD val)
int potential_match; int potential_match;
DWORD exitcode; DWORD exitcode;
pinfo *child; pinfo *child;
int clearing = 0; int clearing;
waitq *w; waitq *w;
#define wval ((waitq *) val) #define wval ((waitq *) val)
@ -316,7 +316,7 @@ proc_subproc (DWORD what, DWORD val)
/* Send a SIGCHLD to myself. */ /* Send a SIGCHLD to myself. */
rc = sig_send (myself_nowait, SIGCHLD); // Send a SIGCHLD rc = sig_send (myself_nowait, SIGCHLD); // Send a SIGCHLD
break; // Don't try to unlock. We don't have a lock. break;
/* A child is in the stopped state. Scan wait() queue to see if anyone /* A child is in the stopped state. Scan wait() queue to see if anyone
* should be notified. (Called from wait_sig thread) * should be notified. (Called from wait_sig thread)
@ -324,6 +324,7 @@ proc_subproc (DWORD what, DWORD val)
case PROC_CHILDSTOPPED: case PROC_CHILDSTOPPED:
child = myself; // Just to avoid accidental NULL dereference child = myself; // Just to avoid accidental NULL dereference
sip_printf ("Received stopped notification"); sip_printf ("Received stopped notification");
clearing = 0;
goto scan_wait; goto scan_wait;
/* Clear all waiting threads. Called from exceptions.cc prior to /* Clear all waiting threads. Called from exceptions.cc prior to
@ -333,9 +334,8 @@ proc_subproc (DWORD what, DWORD val)
case PROC_CLEARWAIT: case PROC_CLEARWAIT:
/* Clear all "wait"ing threads. */ /* Clear all "wait"ing threads. */
sip_printf ("clear waiting threads"); sip_printf ("clear waiting threads");
clearing = 1; clearing = val;
case PROC_SIGCHLD:
scan_wait: scan_wait:
/* Scan the linked list of wait()ing threads. If a wait's parameters /* Scan the linked list of wait()ing threads. If a wait's parameters
* match this pid, then activate it. * match this pid, then activate it.
@ -476,7 +476,7 @@ proc_terminate (void)
ForceCloseHandle1 (h, hwait_subproc); ForceCloseHandle1 (h, hwait_subproc);
sync_proc_subproc->acquire(WPSP); sync_proc_subproc->acquire(WPSP);
(void) proc_subproc (PROC_CLEARWAIT, 0); (void) proc_subproc (PROC_CLEARWAIT, 1);
lock_pinfo_for_update (INFINITE); lock_pinfo_for_update (INFINITE);
/* Clean out zombie processes from the pid list. */ /* Clean out zombie processes from the pid list. */
@ -1205,6 +1205,8 @@ wait_sig (VOID *)
* array looking for any unprocessed signals. * array looking for any unprocessed signals.
*/ */
pending_signals = 0; pending_signals = 0;
int saw_sigchld = 0;
int dispatched_sigchld = 0;
for (int sig = -__SIGOFFSET; sig < NSIG; sig++) for (int sig = -__SIGOFFSET; sig < NSIG; sig++)
{ {
#ifdef NOSIGQUEUE #ifdef NOSIGQUEUE
@ -1213,6 +1215,8 @@ wait_sig (VOID *)
while (InterlockedDecrement (myself->getsigtodo(sig)) >= 0) while (InterlockedDecrement (myself->getsigtodo(sig)) >= 0)
#endif #endif
{ {
if (sig == SIGCHLD)
saw_sigchld = 1;
if (sig > 0 && sig != SIGCONT && sig != SIGKILL && sig != SIGSTOP && if (sig > 0 && sig != SIGCONT && sig != SIGKILL && sig != SIGSTOP &&
(sigismember (& myself->getsigmask (), sig) || (sigismember (& myself->getsigmask (), sig) ||
myself->process_state & PID_STOPPED)) myself->process_state & PID_STOPPED))
@ -1247,9 +1251,8 @@ wait_sig (VOID *)
sip_printf ("Got signal %d", sig); sip_printf ("Got signal %d", sig);
int wasdispatched = sig_handle (sig); int wasdispatched = sig_handle (sig);
dispatched |= wasdispatched; dispatched |= wasdispatched;
if (sig == SIGCHLD && !wasdispatched) if (sig == SIGCHLD && wasdispatched)
proc_subproc (PROC_SIGCHLD, 0); dispatched_sigchld = 1;
dispatched |= sig_handle (sig);
goto nextsig; goto nextsig;
} }
} }
@ -1262,6 +1265,8 @@ wait_sig (VOID *)
continue; continue;
} }
if (saw_sigchld && !dispatched_sigchld)
proc_subproc (PROC_CLEARWAIT, 0);
/* Signal completion of signal handling depending on which semaphore /* Signal completion of signal handling depending on which semaphore
* woke up the WaitForMultipleObjects above. * woke up the WaitForMultipleObjects above.
*/ */

View File

@ -18,8 +18,7 @@ enum procstuff
PROC_CHILDSTOPPED = 2, // a child stopped PROC_CHILDSTOPPED = 2, // a child stopped
PROC_CHILDTERMINATED = 3, // a child died PROC_CHILDTERMINATED = 3, // a child died
PROC_CLEARWAIT = 4, // clear all waits - signal arrived PROC_CLEARWAIT = 4, // clear all waits - signal arrived
PROC_WAIT = 5, // setup for wait() for subproc PROC_WAIT = 5 // setup for wait() for subproc
PROC_SIGCHLD = 6 // saw a non-trapped SIGCHLD
}; };
typedef struct struct_waitq typedef struct struct_waitq

View File

@ -103,11 +103,11 @@ muto::release ()
/* FIXME: Need to check that other thread has not exited, too. */ /* FIXME: Need to check that other thread has not exited, too. */
if (!--visits) if (!--visits)
{ {
tid = 0; /* We were the last unlocker. */
InterlockedExchange (&sync, 0); /* Reset trigger. */ InterlockedExchange (&sync, 0); /* Reset trigger. */
/* This thread had incremented waiters but had never decremented it. /* This thread had incremented waiters but had never decremented it.
Decrement it now. If it is >= 0 then there are possibly other Decrement it now. If it is >= 0 then there are possibly other
threads waiting for the lock, so trigger bruteforce. */ threads waiting for the lock, so trigger bruteforce. */
tid = 0; /* We were the last unlocker. */
if (InterlockedDecrement (&waiters) >= 0) if (InterlockedDecrement (&waiters) >= 0)
(void) SetEvent (bruteforce); /* Wake up one of the waiting threads */ (void) SetEvent (bruteforce); /* Wake up one of the waiting threads */
} }

View File

@ -37,6 +37,7 @@ public:
/* Return true if caller thread owns the lock. */ /* Return true if caller thread owns the lock. */
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);}
}; };
/* Use a statically allocated buffer as the storage for a muto */ /* Use a statically allocated buffer as the storage for a muto */