* dll_init.h (class dll_list): Reorder functions to avoid compiler "can't

inline" warnings.
* security.h (class cygsid): Ditto.
* sigproc.cc (get_proc_lock): Ditto.
* sigproc.h (class sigframe): Ditto.
* sync.h (class muto): Ditto.
* fhandler.h (fhandler_base::get_guard): Actually MAKE virtual as previously
indicated.
* pipe.cc (make_pipe): Remove extraneous set_errno.
* syscalls.cc (_open): Ditto.
* select.cc (peek_pipe): Need to check that there is still something to read
from the pipe after acquiring the mutex since another process/thread could have
eaten the input before we got to acquiring the lock.  (Thanks to Nick Duffek
for this inspiration.)
This commit is contained in:
Christopher Faylor 2001-11-03 03:32:27 +00:00
parent 01432054cb
commit 243a041bd0
10 changed files with 87 additions and 58 deletions

View File

@ -1,3 +1,23 @@
2001-11-02 Egor Duda <deo@logos-m.ru>
* dll_init.h (class dll_list): Reorder functions to avoid compiler
"can't inline" warnings.
* security.h (class cygsid): Ditto.
* sigproc.cc (get_proc_lock): Ditto.
* sigproc.h (class sigframe): Ditto.
* sync.h (class muto): Ditto.
2001-11-02 Christopher Faylor <cgf@redhat.com>
* fhandler.h (fhandler_base::get_guard): Actually MAKE virtual as
previously indicated.
* pipe.cc (make_pipe): Remove extraneous set_errno.
* syscalls.cc (_open): Ditto.
* select.cc (peek_pipe): Need to check that there is still something to
read from the pipe after acquiring the mutex since another
process/thread could have eaten the input before we got to acquiring
the lock. (Thanks to Nick Duffek for this inspiration.)
2001-11-01 Christopher Faylor <cgf@redhat.com>
* fhandler.h: Change Windows 'BOOL's to c++ 'bool's for all variables.

View File

@ -73,12 +73,6 @@ public:
void detach (dll *);
void init ();
void load_after_fork (HANDLE, dll *);
dll *istart (dll_type t)
{
hold_type = t;
hold = &start;
return inext ();
}
dll *inext ()
{
while ((hold = hold->next))
@ -86,6 +80,12 @@ public:
break;
return hold;
}
dll *istart (dll_type t)
{
hold_type = t;
hold = &start;
return inext ();
}
};
extern dll_list dlls;

View File

@ -371,7 +371,7 @@ class fhandler_base
rabuf = NULL;
}
void operator delete (void *);
HANDLE get_guard () const {return NULL;}
virtual HANDLE get_guard () const {return NULL;}
};
class fhandler_socket: public fhandler_base

View File

@ -133,13 +133,11 @@ make_pipe (int fildes[2], unsigned int psize, int mode)
int res = -1;
cygheap_fdnew fdr;
if (fdr < 0)
/* saw an error */;
else
if (fdr >= 0)
{
cygheap_fdnew fdw (fdr, false);
if (fdw < 0)
set_errno (ENMFILE);
/* out of fds? */;
else if (!CreatePipe (&r, &w, sa, psize))
__seterrno ();
else

View File

@ -39,6 +39,15 @@ class cygsid {
}
public:
inline operator const PSID () { return psid; }
inline const PSID operator= (cygsid &nsid)
{ return assign (nsid); }
inline const PSID operator= (const PSID nsid)
{ return assign (nsid); }
inline const PSID operator= (const char *nsidstr)
{ return getfromstr (nsidstr); }
inline cygsid () : psid ((PSID) sbuf) {}
inline cygsid (const PSID nsid) { *this = nsid; }
inline cygsid (const char *nstrsid) { *this = nstrsid; }
@ -54,13 +63,6 @@ public:
char *string (char *nsidstr) const;
inline const PSID operator= (cygsid &nsid)
{ return assign (nsid); }
inline const PSID operator= (const PSID nsid)
{ return assign (nsid); }
inline const PSID operator= (const char *nsidstr)
{ return getfromstr (nsidstr); }
inline BOOL operator== (const PSID nsid) const
{
if (!psid || !nsid)
@ -77,8 +79,6 @@ public:
inline BOOL operator!= (const char *nsidstr) const
{ return !(*this == nsidstr); }
inline operator const PSID () { return psid; }
void debug_print (const char *prefix = NULL) const
{
char buf[256];

View File

@ -389,7 +389,7 @@ peek_pipe (select_record *s, int ignra)
fhandler_base *fh = s->fh;
HANDLE h;
HANDLE guard_mutex = s->fh->get_guard ();
HANDLE guard_mutex = fh->get_guard ();
set_handle_or_return_if_not_open (h, s);
/* Don't perform complicated tests if we don't need to. */
@ -438,12 +438,23 @@ peek_pipe (select_record *s, int ignra)
select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ());
n = -1;
}
else if (n && guard_mutex
&& WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0)
else if (n && guard_mutex)
{
select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (),
guard_mutex);
n = 0;
if (WaitForSingleObject (guard_mutex, 0) != WAIT_OBJECT_0)
{
select_printf ("%s, couldn't get mutex %p, %E", fh->get_name (),
guard_mutex);
n = 0;
}
/* Now that we have the mutex, make sure that no one else has snuck
in and grabbed the data that we originally saw. */
if (!PeekNamedPipe (h, NULL, 0, NULL, (DWORD *) &n, NULL))
{
select_printf ("%s, PeekNamedPipe failed, %E", fh->get_name ());
n = -1;
}
if (n <= 0)
ReleaseMutex (guard_mutex); /* Oops. We lost the race. */
}
if (n < 0)

View File

@ -179,6 +179,29 @@ wait_for_me ()
}
}
/* Get the sync_proc_subproc muto to control access to
* children, zombie arrays.
* Attempt to handle case where process is exiting as we try to grab
* the mutex.
*/
static BOOL
get_proc_lock (DWORD what, DWORD val)
{
Static int lastwhat = -1;
if (!sync_proc_subproc)
return FALSE;
if (sync_proc_subproc->acquire (WPSP))
{
lastwhat = what;
return TRUE;
}
if (!sync_proc_subproc)
return FALSE;
system_printf ("Couldn't aquire sync_proc_subproc for(%d,%d), %E, last %d",
what, val, lastwhat);
return TRUE;
}
static BOOL __stdcall
proc_can_be_signalled (_pinfo *p)
{
@ -939,29 +962,6 @@ getsem (_pinfo *p, const char *str, int init, int max)
return h;
}
/* Get the sync_proc_subproc muto to control access to
* children, zombie arrays.
* Attempt to handle case where process is exiting as we try to grab
* the mutex.
*/
static BOOL
get_proc_lock (DWORD what, DWORD val)
{
Static int lastwhat = -1;
if (!sync_proc_subproc)
return FALSE;
if (sync_proc_subproc->acquire (WPSP))
{
lastwhat = what;
return TRUE;
}
if (!sync_proc_subproc)
return FALSE;
system_printf ("Couldn't aquire sync_proc_subproc for(%d,%d), %E, last %d",
what, val, lastwhat);
return TRUE;
}
/* Remove a zombie from zombies by swapping it with the last child in the list.
*/
static void __stdcall

View File

@ -73,9 +73,6 @@ public:
if (!oframe)
t.get_winapi_lock ();
}
sigframe (): st (NULL) {}
sigframe (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0)) {init (t, ebp);}
inline void init (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0))
{
if (!t.frame && t.id == GetCurrentThreadId ())
@ -83,6 +80,9 @@ public:
else
st = NULL;
}
sigframe (): st (NULL) {}
sigframe (sigthread &t, DWORD ebp = (DWORD) __builtin_frame_address (0)) {init (t, ebp);}
~sigframe ()
{
unregister ();

View File

@ -22,14 +22,16 @@ class muto
public:
class muto *next;
const char *name;
muto() {}
/* The real constructor. */
muto(int inh, const char *name);
void *operator new (size_t, void *p) {return p;}
void *operator new (size_t) {return ::new muto; }
void operator delete (void *) {;} /* can't handle allocated mutos
currently */
muto() {}
/* The real constructor. */
muto(int inh, const char *name);
~muto ();
int acquire (DWORD ms = INFINITE) __attribute__ ((regparm(1))); /* Acquire the lock. */
int release (); /* Release the lock. */

View File

@ -499,9 +499,7 @@ _open (const char *unix_path, int flags, ...)
fhandler_base *fh;
cygheap_fdnew fd;
if (fd < 0)
set_errno (ENMFILE);
else
if (fd >= 0)
{
path_conv pc;
if (!(fh = cygheap->fdtab.build_fhandler_from_name (fd, unix_path,