From 82c925af80cb4493cc15861c18fea64c57c2ee60 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 23 Oct 2005 23:47:45 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 23 ++++++++++++++- winsup/cygwin/cygheap.h | 22 +-------------- winsup/cygwin/cygtls.cc | 2 +- winsup/cygwin/dcrt0.cc | 5 ++-- winsup/cygwin/dtable.cc | 10 ------- winsup/cygwin/dtable.h | 6 ++-- winsup/cygwin/sigproc.cc | 2 +- winsup/cygwin/sync.h | 24 ++++++++++++++++ winsup/cygwin/times.cc | 60 ++++++++++++++++++++++------------------ 9 files changed, 87 insertions(+), 67 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 69a7d39d3..fc05c6219 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,25 @@ +2005-10-23 Christopher Faylor + + * 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 * 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 diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index d9301d415..ad4511e5c 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -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" { diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index 579e981f2..da72fc2ec 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -150,7 +150,7 @@ _cygtls::fixup_after_fork () pop (); sig = 0; } - stacklock = 0; + stacklock = spinning = 0; locals.exitsock = INVALID_SOCKET; wq.thread_ev = NULL; } diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 03df872c0..7599986bf 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -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]; diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 05d9037ab..6f3da436d 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -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) { diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index e34a3ecf4..5e136ab9b 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -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; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 297c89375..5e1a2edee 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -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. diff --git a/winsup/cygwin/sync.h b/winsup/cygwin/sync.h index 441892a08..f8019a8fe 100644 --- a/winsup/cygwin/sync.h +++ b/winsup/cygwin/sync.h @@ -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*/ diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index 1c28c51e3..4ceb093ef 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -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);