From 17743fbc49ebb23300e0a36d8c5a27ed63e2bf41 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 4 May 2001 20:39:38 +0000 Subject: * exceptions.cc (ctrl_c_handler): Always send signal to process if it has no tty. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/autoload.cc | 6 +++--- winsup/cygwin/cygheap.cc | 1 + winsup/cygwin/debug.cc | 4 ++-- winsup/cygwin/environ.cc | 2 +- winsup/cygwin/exceptions.cc | 10 +++++----- winsup/cygwin/localtime.c | 2 +- winsup/cygwin/net.cc | 6 +++--- winsup/cygwin/path.cc | 14 +++++--------- winsup/cygwin/pinfo.h | 2 +- winsup/cygwin/regexp/regexp.c | 2 +- winsup/cygwin/shortcut.c | 3 ++- winsup/cygwin/sigproc.cc | 12 ++++++------ winsup/cygwin/smallprint.c | 1 + winsup/cygwin/sync.cc | 14 +++++++------- winsup/cygwin/thread.cc | 34 +++++++++++++++++----------------- winsup/cygwin/winsup.h | 21 ++------------------- 17 files changed, 63 insertions(+), 76 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f1f92af..3031f49 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +Fri May 4 16:37:30 2001 Christopher Faylor + + * exceptions.cc (ctrl_c_handler): Always send signal to process if it + has no tty. + 2001-05-04 Egor Duda * fhandler_socket.cc (set_connect_secret): Use /dev/urandom to diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 633d91a..995563a 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -70,9 +70,9 @@ std_dll_init (HANDLE &dll_handle, const char *dll_name, LONG &here) { HANDLE h; - while (InterlockedIncrement (&here)) + while (ilockincr (&here)) { - InterlockedDecrement (&here); + ilockdecr (&here); Sleep (0); } @@ -83,7 +83,7 @@ std_dll_init (HANDLE &dll_handle, const char *dll_name, LONG &here) else api_fatal ("could not load %s, %E", dll_name); - InterlockedDecrement (&here); + ilockdecr (&here); return 0; } diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index bfba14e..61de33e 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -9,6 +9,7 @@ details. */ #include "winsup.h" +#include #include #include #include diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc index bd58e47..4ddc8b8 100644 --- a/winsup/cygwin/debug.cc +++ b/winsup/cygwin/debug.cc @@ -87,7 +87,7 @@ thread_stub (VOID *arg) exception_list except_entry; /* Give up our slot in the start_buf array */ - (void) InterlockedExchange (&((thread_start *) arg)->notavail, 0); + (void) ilockexch (&((thread_start *) arg)->notavail, 0); /* Initialize this thread's ability to respond to things like SIGSEGV or SIGFPE. */ @@ -112,7 +112,7 @@ makethread (LPTHREAD_START_ROUTINE start, LPVOID param, DWORD flags, { /* Search the start_buf array for an empty slot to use */ for (info = start_buf; info < start_buf + NTHREADS; info++) - if (!InterlockedExchange (&info->notavail, 1)) + if (!ilockexch (&info->notavail, 1)) goto out; /* Should never hit here, but be defensive anyway. */ diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index cf2e759..d542d73 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -114,7 +114,7 @@ getwinenv (const char *env, const char *in_posix) if (!cur_environ () || !(val = in_posix ?: getenv(we->name))) debug_printf ("can't set native for %s since no environ yet", we->name); - else if (!envcache || !we->posix || strcmp (val, we->posix)) + else if (!envcache || !we->posix || strcmp (val, we->posix) != 0) we->add_cache (val); return we; } diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 96a2d59..9f37b00 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -632,11 +632,11 @@ bool sigthread::get_winapi_lock (int test) { if (test) - return !InterlockedExchange (&winapi_lock, 1); + return !ilockexch (&winapi_lock, 1); /* Need to do a busy loop because we can't block or a potential SuspendThread will hang. */ - while (InterlockedExchange (&winapi_lock, 1)) + while (ilockexch (&winapi_lock, 1)) Sleep (1); return 1; } @@ -645,7 +645,7 @@ void sigthread::release_winapi_lock () { /* Assumes that we have the lock. */ - InterlockedExchange (&winapi_lock, 0); + ilockexch (&winapi_lock, 0); } static void __stdcall interrupt_setup (int sig, void *handler, DWORD retaddr, @@ -892,8 +892,8 @@ ctrl_c_handler (DWORD type) tty_min *t = cygwin_shared->tty.get_tty (myself->ctty); /* Ignore this if we're not the process group lead since it should be handled *by* the process group leader. */ - if (!t->getpgid () || t->getpgid () != myself->pid || - (GetTickCount () - t->last_ctrl_c) < MIN_CTRL_C_SLOP) + if (t->getpgid () && (t->getpgid () != myself->pid || + (GetTickCount () - t->last_ctrl_c) < MIN_CTRL_C_SLOP)) return TRUE; else /* Otherwise we just send a SIGINT to the process group and return TRUE (to indicate diff --git a/winsup/cygwin/localtime.c b/winsup/cygwin/localtime.c index 9e4a3c2..be2b136 100644 --- a/winsup/cygwin/localtime.c +++ b/winsup/cygwin/localtime.c @@ -6,8 +6,8 @@ /* CYGNUS LOCAL */ #include "winsup.h" +#include #define lint -#include #define USG_COMPAT diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 5684887..235ea7e 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -1931,9 +1931,9 @@ wsock_init () static LONG NO_COPY here = -1L; static int NO_COPY wsock_started = 0; - while (InterlockedIncrement (&here)) + while (ilockincr (&here)) { - InterlockedDecrement (&here); + ilockdecr (&here); Sleep (0); } if (!wsock_started && (wsock32_handle || ws2_32_handle)) @@ -1960,6 +1960,6 @@ wsock_init () wsock_started = 1; } } - InterlockedDecrement (&here); + ilockdecr (&here); } diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 3814039..053fab2 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2837,17 +2837,13 @@ hash_path_name (unsigned long hash, const char *name) if (name[1] == ':') { char *nn, *newname = (char *) alloca (strlen (name) + 2); - nn = strncpy (newname, name, 2); - if (isupper (*nn)) - *newname = cyg_tolower (*nn); - *(nn += 2) = '\0'; + nn = newname; + *nn = isupper (*name) ? cyg_tolower (*name) : *name; + *++nn = ':'; name += 2; if (*name != '\\') - { - *nn = '\\'; - *++nn = '\0'; - } - strcpy (nn, name); + *++nn = '\\'; + strcpy (++nn, name); name = newname; goto hashit; } diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index 89ed546..6e54845 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -15,7 +15,7 @@ enum __SIGFLUSH = -2, __SIGSTRACE = -1, __SIGUNUSED = 0, - __SIGOFFSET = 3 + __SIGOFFSET = 2 }; #define PSIZE 63 diff --git a/winsup/cygwin/regexp/regexp.c b/winsup/cygwin/regexp/regexp.c index 7bcd954..2f60d64 100644 --- a/winsup/cygwin/regexp/regexp.c +++ b/winsup/cygwin/regexp/regexp.c @@ -39,9 +39,9 @@ #include "winsup.h" #include "regexp.h" #include +#include #include #include -#include #include "regmagic.h" /* diff --git a/winsup/cygwin/shortcut.c b/winsup/cygwin/shortcut.c index b47cec5..2f7c1e1 100644 --- a/winsup/cygwin/shortcut.c +++ b/winsup/cygwin/shortcut.c @@ -10,8 +10,9 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -#include "winsup.h" +#define WIN32_LEAN_AND_MEAN #include +#include "winsup.h" #include #include #include diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index a44e316..0d2c4f7 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -473,7 +473,7 @@ proc_terminate (void) void __stdcall sig_clear (int sig) { - (void) InterlockedExchange (myself->getsigtodo (sig), 0L); + (void) ilockexch (myself->getsigtodo (sig), 0L); return; } @@ -696,7 +696,7 @@ sig_send (_pinfo *p, int sig, DWORD ebp, bool exception) /* Increment the sigtodo array to signify which signal to assert. */ - (void) InterlockedIncrement (p->getsigtodo (sig)); + (void) ilockincr (p->getsigtodo (sig)); /* Notify the process that a signal has arrived. */ @@ -783,7 +783,7 @@ out: void __stdcall sig_set_pending (int sig) { - (void) InterlockedIncrement (myself->getsigtodo (sig)); + (void) ilockincr (myself->getsigtodo (sig)); return; } @@ -1137,7 +1137,7 @@ wait_sig (VOID *) int dispatched_sigchld = 0; for (int sig = -__SIGOFFSET; sig < NSIG; sig++) { - while (InterlockedDecrement (myself->getsigtodo (sig)) >= 0) + while (ilockdecr (myself->getsigtodo (sig)) >= 0) { if (sig == SIGCHLD) saw_sigchld = 1; @@ -1171,14 +1171,14 @@ wait_sig (VOID *) dispatched_sigchld = 1; /* Need to decrement again to offset increment below since we really do want to decrement in this case. */ - InterlockedDecrement (myself->getsigtodo (sig)); + ilockdecr (myself->getsigtodo (sig)); goto nextsig; /* FIXME: shouldn't this allow the loop to continue? */ } } nextsig: /* Decremented too far. */ - if (InterlockedIncrement (myself->getsigtodo (sig)) > 0) + if (ilockincr (myself->getsigtodo (sig)) > 0) saw_pending_signals = 1; } diff --git a/winsup/cygwin/smallprint.c b/winsup/cygwin/smallprint.c index ac90df3..54ae9b0 100644 --- a/winsup/cygwin/smallprint.c +++ b/winsup/cygwin/smallprint.c @@ -12,6 +12,7 @@ details. */ #include #include #include +#define WIN32_LEAN_AND_MEAN #include int __small_sprintf (char *dst, const char *fmt,...); diff --git a/winsup/cygwin/sync.cc b/winsup/cygwin/sync.cc index 5aa798e..85162f4 100644 --- a/winsup/cygwin/sync.cc +++ b/winsup/cygwin/sync.cc @@ -58,7 +58,7 @@ muto::~muto () be handled correctly. Note: The goal here is to minimize, as much as possible, calls to the - OS. Hence the use of InterlockedIncrement, etc., rather than (much) more + OS. Hence the use of ilockincr, etc., rather than (much) more expensive OS mutexes. */ int muto::acquire (DWORD ms) @@ -69,7 +69,7 @@ muto::acquire (DWORD ms) { /* Increment the waiters part of the class. Need to do this first to avoid potential races. */ - LONG was_waiting = InterlockedIncrement (&waiters); + LONG was_waiting = ilockincr (&waiters); /* This is deceptively simple. Basically, it allows multiple attempts to lock the same muto to succeed without attempting to manipulate sync. @@ -82,7 +82,7 @@ muto::acquire (DWORD ms) case, it is possible for a thread which is going to wait for bruteforce to wake up immediately. It will then attempt to grab sync but will fail and go back to waiting. */ - while (tid != this_tid && (was_waiting || InterlockedExchange (&sync, 1) != 0)) + while (tid != this_tid && (was_waiting || ilockexch (&sync, 1) != 0)) { switch (WaitForSingleObject (bruteforce, ms)) { @@ -90,7 +90,7 @@ muto::acquire (DWORD ms) goto gotit; break; default: - InterlockedDecrement (&waiters); + ilockdecr (&waiters); return 0; /* failed. */ } } @@ -117,11 +117,11 @@ muto::release () if (!--visits) { tid = 0; /* We were the last unlocker. */ - (void) InterlockedExchange (&sync, 0); /* Reset trigger. */ + (void) ilockexch (&sync, 0); /* Reset trigger. */ /* This thread had incremented waiters but had never decremented it. Decrement it now. If it is >= 0 then there are possibly other threads waiting for the lock, so trigger bruteforce. */ - if (InterlockedDecrement (&waiters) >= 0) + if (ilockdecr (&waiters) >= 0) (void) SetEvent (bruteforce); /* Wake up one of the waiting threads */ } @@ -133,7 +133,7 @@ void muto::reset () { visits = sync = tid = 0; - InterlockedExchange (&waiters, -1); + ilockexch (&waiters, -1); if (bruteforce) { CloseHandle (bruteforce); diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index deedcae..a040b4b 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -412,7 +412,7 @@ pthread_cond::BroadCast () if (!verifyable_object_isvalid (mutex, PTHREAD_MUTEX_MAGIC)) return; PulseEvent (win32_obj_id); - while (InterlockedDecrement (&waiting) != 0) + while (ilockdecr (&waiting) != 0) PulseEvent (win32_obj_id); mutex = NULL; } @@ -798,7 +798,7 @@ __pthread_create (pthread_t * thread, const pthread_attr_t * attr, *thread = NULL; return EAGAIN; } - InterlockedIncrement (&MT_INTERFACE->threadcount); + ilockincr (&MT_INTERFACE->threadcount); return 0; } @@ -1073,7 +1073,7 @@ __pthread_testcancel (void) /* * Races in pthread_atfork: * We are race safe in that any additions to the lists are made via - * InterlockedExchangePointer. + * ilockexch. * However, if the user application doesn't perform syncronisation of some sort * It's not guaranteed that a near simultaneous call to pthread_atfork and fork * will result in the new atfork handlers being calls. @@ -1084,7 +1084,7 @@ __pthread_testcancel (void) * will result in an indeterminate order for parent and child calls (what gets inserted * first isn't guaranteed.) * - * There is one potential race... Does the result of InterlockedExchangePointer + * There is one potential race... Does the result of ilockexch * get committed to the return location _before_ any context switches can occur? * If yes, we're safe, if no, we're not. */ @@ -1123,7 +1123,7 @@ __pthread_atforkchild (void) /* FIXME: implement InterlockExchangePointer and get rid of the silly typecasts below */ -#define InterlockedExchangePointer InterlockedExchange +/*#define ilockexch ilockExchange */ /* Register a set of functions to run before and after fork. * prepare calls are called in LI-FC order. @@ -1165,7 +1165,7 @@ __pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(voi if (prepcb) { prepcb->cb = prepare; - prepcb->next=(callback *)InterlockedExchangePointer ((LONG *) &MT_INTERFACE->pthread_prepare, (long int) prepcb); + prepcb->next=(callback *)ilockexch ((LONG *) &MT_INTERFACE->pthread_prepare, (long int) prepcb); } if (parentcb) { @@ -1174,7 +1174,7 @@ __pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(voi while (*t) t = &(*t)->next; /* t = pointer to last next in the list */ - parentcb->next=(callback *)InterlockedExchangePointer ((LONG *) t, (long int) parentcb); + parentcb->next=(callback *)ilockexch ((LONG *) t, (long int) parentcb); } if (childcb) { @@ -1183,7 +1183,7 @@ __pthread_atfork (void (*prepare)(void), void (*parent)(void), void (*child)(voi while (*t) t = &(*t)->next; /* t = pointer to last next in the list */ - childcb->next=(callback *)InterlockedExchangePointer ((LONG *) t, (long int) childcb); + childcb->next=(callback *)ilockexch ((LONG *) t, (long int) childcb); } return 0; } @@ -1351,7 +1351,7 @@ __pthread_exit (void *value_ptr) MT_INTERFACE->destructors.IterateNull (); thread->return_ptr = value_ptr; - if (InterlockedDecrement (&MT_INTERFACE->threadcount) == 0) + if (ilockdecr (&MT_INTERFACE->threadcount) == 0) exit (0); else ExitThread (0); @@ -1626,15 +1626,15 @@ __pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mutex, if ((*cond)->waiting) if ((*cond)->mutex && ((*cond)->mutex != (*themutex))) return EINVAL; - InterlockedIncrement (&((*cond)->waiting)); + ilockincr (&((*cond)->waiting)); (*cond)->mutex = (*themutex); - InterlockedIncrement (&((*themutex)->condwaits)); + ilockincr (&((*themutex)->condwaits)); rv = (*cond)->TimedWait (abstime->tv_sec * 1000); (*cond)->mutex->Lock (); - if (InterlockedDecrement (&((*cond)->waiting)) == 0) + if (ilockdecr (&((*cond)->waiting)) == 0) (*cond)->mutex = NULL; - InterlockedDecrement (&((*themutex)->condwaits)); + ilockdecr (&((*themutex)->condwaits)); return rv; } @@ -1657,15 +1657,15 @@ __pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex) if ((*cond)->waiting) if ((*cond)->mutex && ((*cond)->mutex != (*themutex))) return EINVAL; - InterlockedIncrement (&((*cond)->waiting)); + ilockincr (&((*cond)->waiting)); (*cond)->mutex = (*themutex); - InterlockedIncrement (&((*themutex)->condwaits)); + ilockincr (&((*themutex)->condwaits)); rv = (*cond)->TimedWait (INFINITE); (*cond)->mutex->Lock (); - if (InterlockedDecrement (&((*cond)->waiting)) == 0) + if (ilockdecr (&((*cond)->waiting)) == 0) (*cond)->mutex = NULL; - InterlockedDecrement (&((*themutex)->condwaits)); + ilockdecr (&((*themutex)->condwaits)); return rv; } diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 81ec231..0cb6665 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -14,6 +14,8 @@ details. */ #define __INSIDE_CYGWIN__ +#include "interlock.h" + #define alloca __builtin_alloca #define strlen __builtin_strlen #define strcmp __builtin_strcmp @@ -33,25 +35,6 @@ details. */ #include #include -#undef strchr -#define strchr cygwin_strchr -extern "C" inline __stdcall char * strchr(const char * s, int c) -{ -register char * __res; -__asm__ __volatile__( - "movb %%al,%%ah\n" - "1:\tmovb (%1),%%al\n\t" - "cmpb %%ah,%%al\n\t" - "je 2f\n\t" - "incl %1\n\t" - "testb %%al,%%al\n\t" - "jne 1b\n\t" - "xorl %1,%1\n" - "2:\tmovl %1,%0\n\t" - :"=a" (__res), "=r" (s) - :"0" (c), "1" (s)); -return __res; -} extern char case_folded_lower[]; #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)]) -- cgit v1.1