From c729f22799bcd93a8524619242ce34a2d4fc6edd Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 4 Sep 2001 20:48:45 +0000 Subject: [PATCH] * thread.cc (InterlockedExchangePointer): Don't define if it already exists. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/dtable.cc | 37 +++++++++++++++++++------------------ winsup/cygwin/thread.cc | 2 ++ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 2140aec7f..95d999fa9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +Tue Sep 4 16:48:14 2001 Christopher Faylor + + * thread.cc (InterlockedExchangePointer): Don't define if it already + exists. + Tue Sep 4 22:14:00 2001 Corinna Vinschen * uname.cc (uname): Eliminate os specific retrieving of x86 diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index bde0f37ac..8e4d40bed 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -33,14 +33,14 @@ details. */ #include "cygheap.h" static DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, - STD_ERROR_HANDLE}; + STD_ERROR_HANDLE}; /* Set aside space for the table of fds */ void dtable_init (void) { if (!cygheap->fdtab.size) - cygheap->fdtab.extend(NOFILE_INCR); + cygheap->fdtab.extend (NOFILE_INCR); } void __stdcall @@ -68,7 +68,7 @@ dtable::extend (int howmuch) if (howmuch <= 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 */ 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 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 out = GetStdHandle (STD_OUTPUT_HANDLE); @@ -136,7 +136,7 @@ stdio_init (void) int dtable::find_unused_handle (int start) { - AssertResourceOwner(LOCK_FD_LIST, READ_LOCK); + AssertResourceOwner (LOCK_FD_LIST, READ_LOCK); do { @@ -221,7 +221,7 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin, DWORD myaccess) { 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); res->init (handle, myaccess, bin); return fd; @@ -384,7 +384,7 @@ dtable::dup2 (int oldfd, int newfd) goto done; } - SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup"); + SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup"); if (newfd < 0) { @@ -408,7 +408,7 @@ dtable::dup2 (int oldfd, int newfd) if ((fds[newfd]->get_device () & FH_DEVMASK) == FH_SOCKET) inc_need_fixup_before (); - ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup"); + ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup"); MALLOC_CHECK; if ((res = newfd) <= 2) @@ -477,15 +477,15 @@ dtable::select_except (int fd, select_record *s) void 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; for (size_t i = 0; i < size; i++) 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); } - ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork"); + ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork"); } void @@ -496,7 +496,7 @@ dtable::fixup_before_exec (DWORD target_proc_id) for (size_t i = 0; i < size; i++) 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); } 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 ()) { - debug_printf ("fd %d(%s)", i, fh->get_name ()); + debug_printf ("fd %d (%s)", i, fh->get_name ()); fh->fixup_after_fork (parent); } } @@ -543,10 +543,10 @@ int dtable::vfork_child_dup () { 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; - SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup"); for (size_t i = 0; i < size; i++) if (not_open (i)) continue; @@ -561,15 +561,16 @@ dtable::vfork_child_dup () fds_on_hold = fds; fds = newtable; + out: - ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup"); + ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup"); return 1; } void 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 (); fhandler_base **deleteme = fds; @@ -577,7 +578,7 @@ dtable::vfork_parent_restore () fds_on_hold = NULL; cfree (deleteme); - ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore"); + ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore"); return; } diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index be7505fe4..543d727c6 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1150,7 +1150,9 @@ __pthread_atforkchild (void) /*FIXME: implement InterlockExchangePointer and get rid of the silly typecasts below */ +#ifndef InterlockedExchangePointer #define InterlockedExchangePointer InterlockedExchange +#endif /*Register a set of functions to run before and after fork. *prepare calls are called in LI-FC order.