* thread.cc (InterlockedExchangePointer): Don't define if it already exists.

This commit is contained in:
Christopher Faylor 2001-09-04 20:48:45 +00:00
parent 37f75da24d
commit c729f22799
3 changed files with 26 additions and 18 deletions

View File

@ -1,3 +1,8 @@
Tue Sep 4 16:48:14 2001 Christopher Faylor <cgf@cygnus.com>
* thread.cc (InterlockedExchangePointer): Don't define if it already
exists.
Tue Sep 4 22:14:00 2001 Corinna Vinschen <corinna@vinschen.de> Tue Sep 4 22:14:00 2001 Corinna Vinschen <corinna@vinschen.de>
* uname.cc (uname): Eliminate os specific retrieving of x86 * uname.cc (uname): Eliminate os specific retrieving of x86

View File

@ -33,14 +33,14 @@ details. */
#include "cygheap.h" #include "cygheap.h"
static DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, static DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
STD_ERROR_HANDLE}; STD_ERROR_HANDLE};
/* Set aside space for the table of fds */ /* Set aside space for the table of fds */
void void
dtable_init (void) dtable_init (void)
{ {
if (!cygheap->fdtab.size) if (!cygheap->fdtab.size)
cygheap->fdtab.extend(NOFILE_INCR); cygheap->fdtab.extend (NOFILE_INCR);
} }
void __stdcall void __stdcall
@ -68,7 +68,7 @@ dtable::extend (int howmuch)
if (howmuch <= 0) if (howmuch <= 0)
return 0; return 0;
/* Try to allocate more space for fd table. We can't call realloc() /* Try to allocate more space for fd table. We can't call realloc ()
here to preserve old table if memory allocation fails */ here to preserve old table if memory allocation fails */
if (!(newfds = (fhandler_base **) ccalloc (HEAP_ARGV, new_size, sizeof newfds[0]))) if (!(newfds = (fhandler_base **) ccalloc (HEAP_ARGV, new_size, sizeof newfds[0])))
@ -100,7 +100,7 @@ stdio_init (void)
Also, always set them even if we're to pick up our parent's fds Also, always set them even if we're to pick up our parent's fds
in case they're missed. */ in case they're missed. */
if (!myself->ppid_handle && NOTSTATE(myself, PID_CYGPARENT)) if (!myself->ppid_handle && NOTSTATE (myself, PID_CYGPARENT))
{ {
HANDLE in = GetStdHandle (STD_INPUT_HANDLE); HANDLE in = GetStdHandle (STD_INPUT_HANDLE);
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE); HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
@ -136,7 +136,7 @@ stdio_init (void)
int int
dtable::find_unused_handle (int start) dtable::find_unused_handle (int start)
{ {
AssertResourceOwner(LOCK_FD_LIST, READ_LOCK); AssertResourceOwner (LOCK_FD_LIST, READ_LOCK);
do do
{ {
@ -221,7 +221,7 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
DWORD myaccess) DWORD myaccess)
{ {
if (fd == -1) if (fd == -1)
fd = cygheap->fdtab.find_unused_handle(); fd = cygheap->fdtab.find_unused_handle ();
fhandler_base *res = cygheap->fdtab.build_fhandler (fd, name, handle); fhandler_base *res = cygheap->fdtab.build_fhandler (fd, name, handle);
res->init (handle, myaccess, bin); res->init (handle, myaccess, bin);
return fd; return fd;
@ -384,7 +384,7 @@ dtable::dup2 (int oldfd, int newfd)
goto done; goto done;
} }
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup"); SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
if (newfd < 0) if (newfd < 0)
{ {
@ -408,7 +408,7 @@ dtable::dup2 (int oldfd, int newfd)
if ((fds[newfd]->get_device () & FH_DEVMASK) == FH_SOCKET) if ((fds[newfd]->get_device () & FH_DEVMASK) == FH_SOCKET)
inc_need_fixup_before (); inc_need_fixup_before ();
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup"); ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
MALLOC_CHECK; MALLOC_CHECK;
if ((res = newfd) <= 2) if ((res = newfd) <= 2)
@ -477,15 +477,15 @@ dtable::select_except (int fd, select_record *s)
void void
dtable::fixup_before_fork (DWORD target_proc_id) dtable::fixup_before_fork (DWORD target_proc_id)
{ {
SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork"); SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork");
fhandler_base *fh; fhandler_base *fh;
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL) if ((fh = fds[i]) != NULL)
{ {
debug_printf ("fd %d(%s)", i, fh->get_name ()); debug_printf ("fd %d (%s)", i, fh->get_name ());
fh->fixup_before_fork_exec (target_proc_id); fh->fixup_before_fork_exec (target_proc_id);
} }
ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork"); ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork");
} }
void void
@ -496,7 +496,7 @@ dtable::fixup_before_exec (DWORD target_proc_id)
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL && !fh->get_close_on_exec ()) if ((fh = fds[i]) != NULL && !fh->get_close_on_exec ())
{ {
debug_printf ("fd %d(%s)", i, fh->get_name ()); debug_printf ("fd %d (%s)", i, fh->get_name ());
fh->fixup_before_fork_exec (target_proc_id); fh->fixup_before_fork_exec (target_proc_id);
} }
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_exec"); ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_exec");
@ -533,7 +533,7 @@ dtable::fixup_after_fork (HANDLE parent)
{ {
if (fh->get_close_on_exec () || fh->get_need_fork_fixup ()) if (fh->get_close_on_exec () || fh->get_need_fork_fixup ())
{ {
debug_printf ("fd %d(%s)", i, fh->get_name ()); debug_printf ("fd %d (%s)", i, fh->get_name ());
fh->fixup_after_fork (parent); fh->fixup_after_fork (parent);
} }
} }
@ -543,10 +543,10 @@ int
dtable::vfork_child_dup () dtable::vfork_child_dup ()
{ {
fhandler_base **newtable; fhandler_base **newtable;
newtable = (fhandler_base **) ccalloc (HEAP_ARGV, size, sizeof(fds[0])); SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
newtable = (fhandler_base **) ccalloc (HEAP_ARGV, size, sizeof (fds[0]));
int res = 1; int res = 1;
SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
if (not_open (i)) if (not_open (i))
continue; continue;
@ -561,15 +561,16 @@ dtable::vfork_child_dup ()
fds_on_hold = fds; fds_on_hold = fds;
fds = newtable; fds = newtable;
out: out:
ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup"); ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
return 1; return 1;
} }
void void
dtable::vfork_parent_restore () dtable::vfork_parent_restore ()
{ {
SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore"); SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
close_all_files (); close_all_files ();
fhandler_base **deleteme = fds; fhandler_base **deleteme = fds;
@ -577,7 +578,7 @@ dtable::vfork_parent_restore ()
fds_on_hold = NULL; fds_on_hold = NULL;
cfree (deleteme); cfree (deleteme);
ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore"); ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
return; return;
} }

View File

@ -1150,7 +1150,9 @@ __pthread_atforkchild (void)
/*FIXME: implement InterlockExchangePointer and get rid of the silly typecasts below /*FIXME: implement InterlockExchangePointer and get rid of the silly typecasts below
*/ */
#ifndef InterlockedExchangePointer
#define InterlockedExchangePointer InterlockedExchange #define InterlockedExchangePointer InterlockedExchange
#endif
/*Register a set of functions to run before and after fork. /*Register a set of functions to run before and after fork.
*prepare calls are called in LI-FC order. *prepare calls are called in LI-FC order.