* cygheap.h (cygheap_fdenum::cygheap_fdenum): Record locked state or suffer

deadlocks.
(class locked_process): Move to another header.
* sync.h (lock_process): Define here.
* cygtls.cc (_cygtls::fixup_after_fork): Reset spinning state as well as
stacklock state.
* dcrt0.cc (lock_process::locker): Define.
(dtable::lock_cs): Delete.
* dtable.cc (dtable_init): Eliminate call to init_lock().
(dtable::fixup_after_fork): Ditto.
(dtable::init_lock): Delete definition.
* dtable.h (dtable::init_lock): Delete declaration.
(dtable::lock): Use process lock rather than dtable-specific lock.
(dtable::unlock): Ditto.
* sigproc.cc (sigproc_init): Minor change to debugging output.
* times.cc (utime_worker): Use build_fh_pc rather than reinterpreting the posix
path name again.  Return any error from path_conv immediately.
This commit is contained in:
Christopher Faylor 2005-10-23 23:47:45 +00:00
parent c2c020d1fb
commit 82c925af80
9 changed files with 87 additions and 67 deletions

View File

@ -1,3 +1,25 @@
2005-10-23 Christopher Faylor <cgf@timesys.com>
* cygheap.h (cygheap_fdenum::cygheap_fdenum): Record locked state or
suffer deadlocks.
(class locked_process): Move to another header.
* sync.h (lock_process): Define here.
* cygtls.cc (_cygtls::fixup_after_fork): Reset spinning state as well
as stacklock state.
* dcrt0.cc (lock_process::locker): Define.
(dtable::lock_cs): Delete.
* dtable.cc (dtable_init): Eliminate call to init_lock().
(dtable::fixup_after_fork): Ditto.
(dtable::init_lock): Delete definition.
* dtable.h (dtable::init_lock): Delete declaration.
(dtable::lock): Use process lock rather than dtable-specific lock.
(dtable::unlock): Ditto.
* sigproc.cc (sigproc_init): Minor change to debugging output.
* times.cc (utime_worker): Use build_fh_pc rather than reinterpreting
the posix path name again. Return any error from path_conv immediately.
2005-10-22 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::connect): Don't restrict
@ -252,7 +274,6 @@
(pinfo::lock): Delete.
(pinfo::unlock): Delete.
* winsup.h (get_exit_lock): Delete declaration.
2005-10-03 Corinna Vinschen <corinna@vinschen.de>

View File

@ -398,6 +398,7 @@ class cygheap_fdenum : public cygheap_fdmanip
public:
cygheap_fdenum (int start_fd = -1, bool lockit = false)
{
locked = lockit;
if (lockit)
cygheap->fdtab.lock ();
this->start_fd = fd = start_fd < 0 ? -1 : start_fd;
@ -415,27 +416,6 @@ class cygheap_fdenum : public cygheap_fdmanip
}
};
class lock_process
{
bool skip_unlock;
public:
lock_process (bool exiting = false)
{
cygheap->fdtab.lock ();
skip_unlock = exiting;
if (exiting && exit_state < ES_SET_MUTO)
{
exit_state = ES_SET_MUTO;
muto::set_exiting_thread ();
}
}
~lock_process ()
{
if (!skip_unlock)
cygheap->fdtab.unlock ();
}
};
class child_info;
void __stdcall cygheap_fixup_in_child (bool);
extern "C" {

View File

@ -150,7 +150,7 @@ _cygtls::fixup_after_fork ()
pop ();
sig = 0;
}
stacklock = 0;
stacklock = spinning = 0;
locals.exitsock = INVALID_SOCKET;
wq.thread_ev = NULL;
}

View File

@ -47,8 +47,8 @@ HANDLE NO_COPY hMainProc = (HANDLE) -1;
HANDLE NO_COPY hMainThread;
HANDLE NO_COPY hProcToken;
HANDLE NO_COPY hProcImpToken;
muto NO_COPY dtable::lock_cs; /* This should be in dtable.cc but it causes inexplicable
errors there. */
muto NO_COPY lock_process::locker;
bool display_title;
bool strip_title_path;
@ -636,6 +636,7 @@ get_cygwin_startup_info ()
void __stdcall
dll_crt0_0 ()
{
lock_process::init ();
init_console_handler (TRUE);
_impure_ptr = _GLOBAL_REENT;
_impure_ptr->_stdin = &_impure_ptr->__sf[0];

View File

@ -47,8 +47,6 @@ dtable_init ()
{
if (!cygheap->fdtab.size)
cygheap->fdtab.extend (NOFILE_INCR);
cygheap->fdtab.init_lock ();
}
void __stdcall
@ -60,12 +58,6 @@ set_std_handle (int fd)
SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ());
}
void
dtable::init_lock ()
{
lock_cs.init ("lock_cs");
}
int
dtable::extend (int howmuch)
{
@ -687,7 +679,6 @@ dtable::fixup_after_exec ()
{
first_fd_for_open = 0;
fhandler_base *fh;
cygheap->fdtab.init_lock ();
for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL)
{
@ -713,7 +704,6 @@ void
dtable::fixup_after_fork (HANDLE parent)
{
fhandler_base *fh;
cygheap->fdtab.init_lock ();
for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL)
{

View File

@ -20,7 +20,6 @@ class fhandler_fifo;
#define BFH_OPTS (PC_NULLEMPTY | PC_FULL | PC_POSIX)
class dtable
{
static muto lock_cs;
fhandler_base **fds;
#ifdef NEWVFORK
fhandler_base **fds_on_hold;
@ -31,9 +30,8 @@ class dtable
static const int initial_archetype_size = 8;
int first_fd_for_open;
int cnt_need_fixup_before;
void lock () {lock_cs.acquire ();}
void unlock () {lock_cs.release ();}
void init_lock ();
void lock () {lock_process::locker.acquire ();}
void unlock () {lock_process::locker.release ();}
public:
size_t size;

View File

@ -485,7 +485,7 @@ sigproc_init ()
hwait_sig->zap_h ();
global_sigs[SIGSTOP].sa_flags = SA_RESTART | SA_NODEFER;
sigproc_printf ("process/signal handling enabled(%x)", myself->process_state);
sigproc_printf ("process/signal handling enabled, state %p", myself->process_state);
}
/* Called on process termination to terminate signal and process threads.

View File

@ -44,4 +44,28 @@ public:
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
};
class lock_process
{
bool skip_unlock;
static muto locker;
public:
static void init () {locker.init ("lock_process");}
lock_process (bool exiting = false)
{
locker.acquire ();
skip_unlock = exiting;
if (exiting && exit_state < ES_SET_MUTO)
{
exit_state = ES_SET_MUTO;
muto::set_exiting_thread ();
}
}
~lock_process ()
{
if (!skip_unlock)
locker.release ();
}
friend class dtable;
};
#endif /*_SYNC_H*/

View File

@ -445,36 +445,42 @@ static int
utimes_worker (const char *path, const struct timeval *tvp, int nofollow)
{
int res = -1;
path_conv win32 (path, nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW);
fhandler_base *fh = NULL;
bool fromfd = false;
path_conv win32 (path, PC_POSIX | (nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW));
cygheap_fdenum cfd;
while (cfd.next () >= 0)
if (cfd->get_access () & (FILE_WRITE_ATTRIBUTES | GENERIC_WRITE)
&& strcmp (cfd->get_win32_name (), win32) == 0)
{
fh = cfd;
fromfd = true;
break;
}
if (!fh)
{
if (!(fh = build_fh_name (path, NULL, PC_SYM_FOLLOW)))
goto error;
if (fh->error ())
if (win32.error)
set_errno (win32.error);
else
{
debug_printf ("got %d error from build_fh_name", fh->error ());
set_errno (fh->error ());
fhandler_base *fh = NULL;
bool fromfd = false;
cygheap_fdenum cfd;
while (cfd.next () >= 0)
if (cfd->get_access () & (FILE_WRITE_ATTRIBUTES | GENERIC_WRITE)
&& strcmp (cfd->get_win32_name (), win32) == 0)
{
fh = cfd;
fromfd = true;
break;
}
if (!fh)
{
if (!(fh = build_fh_pc (win32)))
goto error;
if (fh->error ())
{
debug_printf ("got %d error from build_fh_name", fh->error ());
set_errno (fh->error ());
}
}
res = fh->utimes (tvp);
if (!fromfd)
delete fh;
}
}
res = fh->utimes (tvp);
if (!fromfd)
delete fh;
error:
syscall_printf ("%d = utimes (%s, %p)", res, path, tvp);