tty.
+Fri May 4 16:37:30 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * exceptions.cc (ctrl_c_handler): Always send signal to process if it
+ has no tty.
+
2001-05-04 Egor Duda <deo@logos-m.ru>
* fhandler_socket.cc (set_connect_secret): Use /dev/urandom to
{
HANDLE h;
- while (InterlockedIncrement (&here))
+ while (ilockincr (&here))
{
- InterlockedDecrement (&here);
+ ilockdecr (&here);
Sleep (0);
}
else
api_fatal ("could not load %s, %E", dll_name);
- InterlockedDecrement (&here);
+ ilockdecr (&here);
return 0;
}
details. */
#include "winsup.h"
+#include <string.h>
#include <errno.h>
#include <fhandler.h>
#include <assert.h>
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. */
{
/* 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. */
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;
}
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;
}
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,
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
/* CYGNUS LOCAL */
#include "winsup.h"
+#include <string.h>
#define lint
-#include <windows.h>
#define USG_COMPAT
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))
wsock_started = 1;
}
}
- InterlockedDecrement (&here);
+ ilockdecr (&here);
}
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;
}
__SIGFLUSH = -2,
__SIGSTRACE = -1,
__SIGUNUSED = 0,
- __SIGOFFSET = 3
+ __SIGOFFSET = 2
};
#define PSIZE 63
#include "winsup.h"
#include "regexp.h"
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
#include <stdlib.h>
-#include <string.h>
#include "regmagic.h"
/*
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
-#include "winsup.h"
+#define WIN32_LEAN_AND_MEAN
#include <shlobj.h>
+#include "winsup.h"
#include <ctype.h>
#include <sys/types.h>
#include <sys/mount.h>
void __stdcall
sig_clear (int sig)
{
- (void) InterlockedExchange (myself->getsigtodo (sig), 0L);
+ (void) ilockexch (myself->getsigtodo (sig), 0L);
return;
}
/* 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.
*/
void __stdcall
sig_set_pending (int sig)
{
- (void) InterlockedIncrement (myself->getsigtodo (sig));
+ (void) ilockincr (myself->getsigtodo (sig));
return;
}
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;
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;
}
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
+#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int __small_sprintf (char *dst, const char *fmt,...);
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)
{
/* 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.
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))
{
goto gotit;
break;
default:
- InterlockedDecrement (&waiters);
+ ilockdecr (&waiters);
return 0; /* failed. */
}
}
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 */
}
muto::reset ()
{
visits = sync = tid = 0;
- InterlockedExchange (&waiters, -1);
+ ilockexch (&waiters, -1);
if (bruteforce)
{
CloseHandle (bruteforce);
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;
}
*thread = NULL;
return EAGAIN;
}
- InterlockedIncrement (&MT_INTERFACE->threadcount);
+ ilockincr (&MT_INTERFACE->threadcount);
return 0;
}
/*
* 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.
* 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.
*/
/* 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.
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)
{
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)
{
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;
}
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);
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;
}
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;
}
#define __INSIDE_CYGWIN__
+#include "interlock.h"
+
#define alloca __builtin_alloca
#define strlen __builtin_strlen
#define strcmp __builtin_strcmp
#include <sys/types.h>
#include <sys/strace.h>
-#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)])