Commit Graph

40 Commits

Author SHA1 Message Date
Christopher Faylor c350feda20 * cygthread.cc (cygthread::stub): Revert previous change and again subsume
cygthread::stub2.  Just return from function now since ExitThread is guaranteed
by automatic _threadinfo wrapper.  Define as per ThreadProc convention.
(cygthread::stub2): Remove.
(cygthread::simplestub): Perform similar operations to cygthread::stub.
(cygthread::simplestub2): Remove.
* cygthread.h (cygthread::stub): Declare as per ThreadProc convention.
(cygthread::stub2): Remove declaration.
(cygthread::simplestub): Declare as per ThreadProc convention.
(cygthread::simplestub2): Remove declaration.
* cygtls.h (_threadinfo::call): Define first argument as per ThreadProc
convention.
(_threadinfo::call2): Ditto.
(_tlsbase): Define as char * pointer.
(_tlstop): New definition.
(_main_tls): Define here.
* dcrt0.cc (alloc_stack): Revert previous change which called init_thread since
information would be overwritten by fork later anyway.
(dll_crt0_1): Use _tlsbase and _tlstop for setting stack bottom, top.
* exceptions.cc: Move _main_tls declaration to cygtls.h.
(_threadinfo::call): Define first argument as per ThreadProc convention.
(_threadinfo::call2): Call ExitThread with thread function return value.
(_threadinfo::init_thread): Don't initialize cygtls to zero if input arg is
NULL.
* fork.cc (fork_child): Reset _main_tls here.  Reinitialize parts of _my_tls
after copying data from parent.
* init.cc (threadfunc_fe): New function.  Front-end for all threads created in
cygwin processes.
(munge_threadfunc): New function.
(dll_entry): Call munge_threadfunc to force the call of a thread wrapper.
* thread.cc (pthread::thread_init_wrapper): Perform similar operations to
cygthread::stub.
(pthread::thread_init_wrapper2): Remove.
* thread.h (pthread::thread_init_wrapper): Declare as per ThreadProc
convention.
(pthread::thread_init_wrapper2): Remove declaration.
* window.cc (Winmain): Just return from function now since ExitThread is
guaranteed by automatic _threadinfo wrapper.
2003-12-14 07:09:22 +00:00
Christopher Faylor aeab6ea658 * cygthread.cc (cygthread::stub2): Remove myself from the list of threads
monitored by signals since this thread will never call raise or sigwait.
(cygthread::simplestub2): Ditto.  Set ev here.
(cygthread::cygthread): Don't set ev here for freerange thread.
2003-12-05 05:29:17 +00:00
Christopher Faylor d1eb7a4615 * cygthread.cc (cygthread::stub): Properly establish _threadinfo environment.
(cygthread::stub2): New function.
(cygthread::simplestub): Ditto.
(cygthread::simplestub2): New function.
* cygthread.h (cygthread::stub2): Declare new function.
(cygthread::simplestub2): Ditto.
* cygtls.h (_threadinfo::call): Declare new function.
(_threadinfo::call2): Ditto.
* dcrt0.cc (dll_crt0_1): Accommodate new _threadinfo::init which doesn't return
pointer to tls.
(_dll_crt0): Remove obsolete DECLARE_TLS_STORAGE.
(dll_crt0): Ditto.
* exceptions.cc (_threadinfo::call): New function.
(_threadinfo::call2): Ditto.
(_threadinfo::init): Don't return pointer.
* thread.cc (pthread::thread_init_wrapper): Properly establish _threadinfo
environment.
(pthread::thread_init_wrapper2): New function.
* thread.h (pthread::thread_init_wrapper): Remove noreturn attribute
(pthread::thread_init_wrapper2): Declare new function.
* winbase.h: Remove obsolete code.
2003-12-03 05:21:55 +00:00
Christopher Faylor ef4d65ba95 * cygthread.cc (cygthread::freerange): Set inuse count. Avoid setting ev from
h as h would be NULL at this point.
(cygthread::operator new): Issue debugging info when overflowing the thread
pool.
(cygthread::cygthread): Set ev from h here after h has been initialized.
2003-11-07 18:21:05 +00:00
Christopher Faylor c433f4617f Throughout, remove "include <errno.h>" from files which already include
cygerrno.h.
* include/cygwin/config.h (__DYNAMIC_REENT__): Define.
* include/cygwin/version.h: Bump API minor version.
* cygwin.din: Export __getreent
* cygerrno.h: Include errno.h.  Fix places where _impure_ptr is used directly
to store the errno value.
* debug.cc (__set_errno): Ditto.
* errno.cc: Remove _RRENT_ONLY define to get errno.cc compiled.
* signal.cc: Rename _reent_clib to _REENT throughout.
* thread.h (reent_clib): Remove prototype.
* thread.cc (reent_clib): Rename reent_clib to __getreent.  Return _impure_ptr
until MTinterface is initialized.
(reent_winsup): Fix a possible SEGV when _r == NULL.  Return NULL instead.
* MTinterface::fixup_after_fork: Switch reent back to _impure_ptr to keep
signal handling running when fork is called from a thread other than the
mainthread.
2003-06-16 03:24:13 +00:00
Christopher Faylor 979233a51a * cygthread.cc (cygthread::terminate_thread): Change system_printf to
debug_printf.
2003-06-05 19:18:33 +00:00
Christopher Faylor 3786526ea8 * cygthread.h (cygthread::terminate_thread): Mark private.
* cygthread.cc (cygthread::terminate_thread): Deallocate free_range thread
stuff.
2003-06-02 21:22:02 +00:00
Christopher Faylor 9508ebc53d * cygthread.cc (cygthread::detach): Prioritize waiting for I/O completion over
waiting for signal delivery.
2003-05-09 17:56:58 +00:00
Christopher Faylor 73afb2abb0 * cygthread.cc (cygthread::stub): Initialize stack pointer earlier.
(cygthread::simplestub): Initialize stack pointer.
(cygthread::terminate_thread): Account for possibility that stack pointer has
not been set.  Issue warnings for unusual conditions.
2003-04-11 02:16:17 +00:00
Christopher Faylor e5d6d53590 * cygthread.h: Change 'avail' cygthread element to 'inuse' throughout.
* cygthread.cc: Ditto.
(cygthread::stub): Don't initialize already initialized events.
(cygthread::freerange): Don't create thread here.
(cygthread::cygthread): Create thread here.  Die if thread not created.
(cygthread::operator new): Simplify.  Just grab a thread structure from the
pool.  Don't try to start the thread.
(cygthread::terminate_thread): Don't close event handles.  Just reuse them.
Call MEM_RELEASE rather than MEM_DECOMMIT (from Joe Buehler).
2003-04-10 05:27:34 +00:00
Christopher Faylor 9dbe3289ee * cygthread.h (cygthread::avail): Make LONG for easier use with Interlocked*
functions.
* cygthread.cc (cygthread::init): Eliminate unneeded muto.
(cygthread::operator new): Don't lock.  Instead change use of avail variable
into tri-state: available (1), not available (-1), uninitialized (0).
(cygthread::terminate_thread): Set avail to uninitialized.
(cygthread::detach): Eliminate local 'avail'.  Always set avail to 1 unless
signalled.
* cygthread.cc (cygthread::operator new): Be more defensive when messing with
2003-04-04 18:52:11 +00:00
Christopher Faylor 8aed2a11a8 add comments 2003-04-04 06:03:52 +00:00
Christopher Faylor b410f1680f * cygthread.cc (operator new): Be more defensive when messing with threads that
are marked "unavailable".
2003-04-04 05:58:06 +00:00
Christopher Faylor d99c61760e * external.cc (check_ntsec): New function.
(cygwin_internal): Add CW_CHECK_NTSEC handling to call check_ntsec() from
applications.
* include/cygwin/version.h: Bump API minor number.
* include/sys/cygwin.h (cygwin_getinfo_types): Add CW_CHECK_NTSEC.
* cygthread.cc (cygthread::new): Add more defensive debugging.
2003-04-02 23:01:11 +00:00
Christopher Faylor 0e7a60fef9 * cygthread::detach: Improve error message. 2003-02-27 15:09:31 +00:00
Corinna Vinschen e136dbc297 Split ChangeLog, create ChangeLog-2002.
Fix copyright dates.
2003-01-10 12:32:49 +00:00
Christopher Faylor d5223b2b0a * cygthread.cc (cygthread::cygthread): Be more noisy about odd condition.
* miscfuncs.cc (low_priority_sleep): Sleep in regular priority if that's what
we're currently running at.
2003-01-10 03:13:45 +00:00
Christopher Faylor a8eb76e3e1 * cygthread.cc (cygthread::detach): Set errno with set_sig_errno so that EINTR
is properly restored after signal.
2002-12-25 17:43:37 +00:00
Christopher Faylor 8bce0d723c Throughout, change fhandler_*::read and fhandler_*::raw_read to void functions
whose second arguments are both the lenght and the return value.
* fhandler.cc (fhandler_base::read): Rework slightly to use second argument as
input/output.  Tweak CRLF stuff.
(fhandler_base::readv): Accommodate fhandler_*::read changes.
* cygthread.h (cygthread::detach): Declare as taking optional handle argument.
(cygthread::detach): When given a handle argument, wait for the handle to be
signalled before waiting for thread to detach.  Return true when signal
detected.
2002-12-14 04:01:32 +00:00
Christopher Faylor 1d380f593a * cygthread.h (cygthread::stack_ptr): New element.
(cygthread::detach): Accept a "wait_for_signal" argument.
(cygthread::terminate_thread): New function.
* cygthread.cc (cygthread::stub): Set stack pointer argument.
(cygthread::terminate_thread): New function.  Forcibly terminate thread.
(cygthread::detach): Optionally wait for signals and kill thread when signal
arrives.
* exceptions.cc (signal_exit): Set signal_arrived prior to exiting to wake up
anything blocking on signals.
* fhandler.h (fhandler_base::set_r_no_interrupt): Change to accept bool
argument.
(fhandler_pipe::ready_for_read): Declare.
* pipe.cc (pipeargs): New structure.
(read_pipe): New thread stub wrapper for normal pipe read.
(fhandler_pipe::read): Modify to call reader in a cygthread, terminating on
signal, as appropriate.
* select.cc (fhandler_pipe::ready_for_read): Define new function.
2002-12-11 04:00:04 +00:00
Christopher Faylor c0a02a4b42 * miscfuncs.cc (low_priority_sleep): New function. Use throughout where code
is supposed to be giving up time slice.
* fhandler_console.cc (fhandler_console::read): Switch button 2/3 output escape
sequences to be consistent with xterm.
2002-11-13 19:36:12 +00:00
Christopher Faylor d525130f04 * cygthread.cc (cygthread::exiting): New variable.
(cygthread::initialized): Delete.
(cygthread::stub): Use exiting variable to determine when to exit.
(cygthread::runner): Delete.
(cygthread_protect): New variable.
(cygthread::init): Don't start runner thread.  Initialize muto for list
protection.
(cygthread::freerange): Return pointer to cygthread.
(cygthread::operator new): Change logic to start threads on an as-needed basis.
(cygthread::detach): Don't zero id.
(cygthread::terminate): Don't kill any executing threads.  Just set exiting
flag.
* cygthread.h (cygthread): Reflect above changes.
* dcrt0.cc (dll_crt0_1): Move cygthread initialization later.
* fork.cc (fork_child): Do fdtab fixup after dll fixup or (apparently) winsock
may allocate memory in dll load address.
2002-10-22 20:16:31 +00:00
Christopher Faylor 5ec14fe40a Change _function() to function() throughout.
* cygwin.din: Remove last vestiges (?) of newlib wrappers.
* cygthread.cc (cygthread::detach): Always wait for event or suffer an
apparently inavoidable race.
* dcrt0.cc (dll_crt0_1): Allocate threads after stack has been relocated.
* debub.cc (lock_debug): Don't acquire lock on exit.
* fork.cc (fork_child): Recreate mmaps before doing anything else since Windows
has a habit of using blocks of memory in the child that could previously have
been occupied by shared memory in the parent.
* mmap.cc (fhandler_disk_file::fixup_mmap_after_fork): Issue error here and
provide some details about what went wrong.
(fixup_mmaps_after_fork): Remove error message.
* shared.cc (open_shared): Move warning message so that more detail is
possible.
* sigproc.cc (sigproc_init): Initialize sync_proc_subproc to avoid a race.
(sigproc_terminate): Specifically wait for process thread to terminate.
2002-10-21 01:00:58 +00:00
Christopher Faylor ccefaab1d5 * cygthread.cc (cygthread::stub): Fix typo.
(cygthread::terminate): Don't zero thread handle prior to using it.
2002-10-20 18:17:43 +00:00
Christopher Faylor 824166e620 * cygthread.cc: Bump number of cygthreads up to accommodate applications which
use ttys.
2002-10-19 00:35:20 +00:00
Christopher Faylor 969203ce91 * cygthread.cc (cygthread::stub): Reintroduce clearing of __name but do it
before SetEvent to eliminate a race.
(cygthread::terminate): Accumulate list of threads to check for termination and
call WaitForMultipleObjects on list rather than waiting for each thread
individually.
* sigproc.cc (subproc_init): Zap hwait_subproc thread handle since it is no
longer used.
* spawn.cc (spawn_guts): Fix so that cygthread::terminate is *really* called
only for exec.
2002-10-14 03:51:44 +00:00
Christopher Faylor a7a5d0ba37 * cygthread.cc (cygthread::stub): Don't zero __name here. That introduces a
race.
2002-10-14 02:37:49 +00:00
Christopher Faylor 3f5046a540 * cygthread.cc (cygthread::stub): Don't create event for long-running threads.
Initialize thread_sync event here which is used to Suspend using an event
rather than relying on SuspendThread/ResumeThread.
(cygthread::init): Save handle to runner thread for future termination.
(cygthread::cygthread): Only resume thread when it is actually suspended.
Otherwise signal thread completion event.
(cygthread::terminate): Forcibly terminate runner thread and any helper
threads.  Call DisableThreadLibrary calls if execing.
* cygthread.h (cygthread::thread_sync): Declare.
* dcrt0.cc (do_exit): Eliminate calls to obsolete window_terminate and
shared_terminate.
* exceptions.cc (events_terminate): Don't bother closing title_mutex since it
is going away anyway.
* pinfo.cc (_pinfo::exit): Call cygthread::terminate to ensure that threads are
shut down before process exit or otherwise strange races seem to occur.
* shared.cc (shared_terminate): Eliminate.
* shared.h (shared_terminate): Eliminate declaration.
* winsup.h (window_terminate): Eliminate declaration.
* spawn.cc (spawn_guts): Call cygthread::terminate early in process if execing.
Call DisableThreadLibrary calls if execing.
* window.cc (Winmain): Call ExitThread to force exit.
(window_terminate): Eliminate.
* dcrt0.cc (do_exit): Track exit state more closely.
2002-10-13 18:16:33 +00:00
Christopher Faylor c4ec64d76b * cygthread.cc (cygthread::stub): Don't create an event for "cygself" threads.
Assume that they exit via an ExitThread call.
* cygthread.h (cygthread::SetThreadPriority): New function.
(cygthread::zap_h): New function.
* dcrt0.cc (do_exit): Move cygthread::terminate earlier and establish
exit_state guard.
* fhandler.h (fhandler_tty_master::output_thread): Delete.
* fhandler_tty.cc (fhandler_tty_master::init): Set priority for threads via
method.  Zap handles when done.  Don't treat process_output specially.
(process_output): Call ExitThread directly.
(fhandler_tty_master::fixup_after_fork): Don't worry about output_thread.
(fhandler_tty_master::fixup_after_exec): Ditto.
* sigproc.cc (proc_terminate): Don't detach from hwait_subproc.  Just let it
exit.
(sigproc_init): Close thread handle after initialization.
(wait_sig): Use GetCurrentThread() as SetThreadPriority call rather than
*event* handle.  Call ExitThread directly on termination.
(wait_subproc): Call ExitThread directly on termination.
* tty.cc (tty_list::terminate): Don't attempt t detach from output_thread.
2002-10-09 05:55:40 +00:00
Christopher Faylor 7da53596cf * cygheap.cc (dup_now): Make fatal error a little more informative.
(cygheap_setup_for_child): Detect when default size of shared region is less
than the current size and allocate that much.
(_cbrk): Just return NULL on inability to allocate.
(_cmalloc): Ditto.
* cygheap.h (CYGHEAPSIZE): Change size to reflect newer, tinier fhandler sizes.
* spawn.cc (av::error): New element, reflects potential errno from cmalloc.
(av::~av): Don't free NULL pointers.
(av::replace0_maybe): Detect out-of-memory conditions.
(av::dup_maybe): Ditto.
(av::dup_all): Ditto.
(av::unshift): Ditto.
(spawn_guts): Set errno and return if argv creation ran into problems.
* fhandler.h (fhandler_union): Change member names to something safer.
* fhandler_console.cc (fhandler_console::get_tty_stuff): Always set
fhandler_console::dev_state regardless of whether shared region is initialized.
* cygthread.cc (cygthread::runner): Use ExitThread rather than return
(planning for future).
2002-10-09 04:08:05 +00:00
Christopher Faylor 09663d31bb * cygthread.cc (cygthread::stub): Very minor cleanup.
(cygthread::stub): Report overflows in cygwin thread pool when DEBUGGING is on
and special environment variable is not set.
(cygthread::terminate): Set event only when event actually exists.
* exceptions.cc (signal_exit): Set priority of main thread to low before
setting current thread to high.
2002-10-06 01:01:58 +00:00
Christopher Faylor aea1f301fc * cygthread.h (cygthread::terminate): Declare new function.
(cygthread::initialized): Change to 'int'.
* cygthread.cc (cygthread::stub): Exit thread if initialized < 0.
(cygthread::new): Ditto.
(cygthread::runner): Ditto.  Set initialized using xor to preserve sign.
(cygthread::terminate): New function.
* dcrt0.cc (do_exit): Call cygthread::terminate.
2002-09-29 02:19:35 +00:00
Christopher Faylor 5bf785a017 * cygthread.cc (cygthread::initialized): Avoid copying on fork or some threads
may not end up in the pool.
(cygthread::new): Avoid race when checking for initialized.  Add debugging
code.
* fhandler.cc (fhandler_base::raw_read): Add case for ERROR_INVALID_HANDLE due
to Win95 directories.
(fhandler_base::open): Handle errors due to Win95 directories.
(fhandler_base::close): Add get_nohandle () test.
(fhandler_base::set_close_on_exec): Ditto.
(fhandler_base::fork_fixup): Ditto.
(fhandler_base::lock): Change error code to Posix EINVAL.
(fhandler_base::dup): If get_nohandle (), set new value to INVALID_HANDLE_VALUE
instead of NULL.
* fhandler_disk_file.cc (fhandler_disk_file::fstat): Call fstat_by_name if
get_nohandle ().  Remove extraneous element from strpbrk.
(fhandler_disk_file::open): Remove test for Win95 directory.
* fhandler_random.cc (fhandler_dev_random::open): Add set_nohandle ().
* fhandler_clipboard.cc (fhandler_dev_clipboard::open): Ditto.
* fhandler_zero.cc (fhandler_dev_zero::open): Ditto.
(fhandler_dev_zero::close): Delete.
* fhandler.h (class fhandler_dev_zero): Ditto.
2002-09-19 03:30:20 +00:00
Christopher Faylor d4d59223ed * cygthread.cc (hthreads): Remove unneeded global.
(cygthread::simplestub): New static member function.
(cygthread::runner): Don't set hthreads.
(cygthread::freerange): New member function.
(cygthread::operator new): Call freerange if all cygwin slots are used up.
(cygthread::exit_thread): Don't mess with event if freerange thread.
(cygthread::detach): Ditto.
* cygthread.h (class cygthread): Declare new member functions and variables.
2002-08-29 03:33:50 +00:00
Christopher Faylor 5ffec1d16d * cygthread.cc (cygthread::cygthread): Close another race. 2002-08-11 19:31:24 +00:00
Christopher Faylor 1524ae42cf * cygthread.cc (cygthread::stub): Accept flag to pass info structure to thread
function.
(cygthread::operator new): Add defense debugging output.
(cygthread::cygthread): Add debugging output.  Set name after thread has been
awakened to avoid a race.
(cygthread::exit_thread): Use handle operator rather than using ev directly.
(cygthread::exit_thread): Reorganize to provide debugging.  Set __name to NULL.
* cygthread.h (cygself): Define.
* fhandler_tty.cc (fhandler_tty_master::init): Use cygself as argument so that
invoked thread can access its own info.
(process_output): Derive cygthread info of thread from thread argument.
* sigproc.cc (sigproc_init): Use cygself as argument so that invoked thread can
access its own info.
(wait_sig): Derive cygthread info of thread from thread argument.
2002-08-06 05:08:55 +00:00
Christopher Faylor 8d0bc156ef * cygthread.cc (cygthread::stub): Change event creation to manual reset. Set
__name after calling SetEvent to prevent races.
(cygthread::detach): Always reset event here to prevent races.
2002-08-05 16:15:46 +00:00
Christopher Faylor 6b2a9a2fdf * cygthread.cc (cygthread::exit_thread): Define new method.
* cygthread.h (cygthread::exit_thread): Declare new method.
* fhandler.h (fhandler_tty_master::hThread): Delete.
(fhandler_tty_master::output_thread): Define.
* fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Adjust
constructor.
(fhandler_tty_master::init): Use cygthread rather than handle.
(process_output): Use cygthread method to exit.
(fhandler_tty_master::fixup_after_fork): Set output_thread to NULL after fork.
(fhandler_tty_master::fixup_after_exec): Set output_thread to NULL after
spawn/exec.
* tty.cc (tty_list::terminate): Detach from output_thread using cygthread
method.
2002-08-02 02:10:24 +00:00
Christopher Faylor 92655eab17 * cygthread.cc: Remove cruft. 2002-08-01 16:27:29 +00:00
Christopher Faylor b6bd703781 * Makefile.in (DLL_OFILES): Add cygthread.o.
* dcrt0.cc (dll_crt0_1): Eliminate various thread initialization functions in
favor of new cygthread class.
* debug.cc: Remove thread manipulation functions.
* debug.h: Ditto.
* external.cc (cygwin_internal): Use cygthread method for determining thread
name.  Remove capability for setting thread name.
* fhandler_console.cc (fhandler_console::read): Use cygthread method rather
than iscygthread function.
* fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Use cygthread
methods to create threads.
(fhandler_tty_common::__acquire_output_mutex): Use cygthread method to retrieve
thread name.
* select.cc (pipeinf): Use cygthread pointer rather than handle.
(start_thread_pipe): Ditto.
(pipe_cleanup): Ditto.
(serialinf): Ditto.
(start_thread_serial): Ditto.
(serial_cleanup): Ditto.
(socketinf): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Ditto.
* sigproc.cc (hwait_sig): Ditto.
(hwait_subproc): Ditto.
(proc_terminate): Ditto.
(sigproc_terminate): Ditto.
(sigproc_init): Initialize cygthread hwait_sig pointer.
(subproc_init): Initialize cygthread hwait_subproc pointer.
(wait_sig): Rely on cygthread HANDLE operator.
* strace.cc (strace::vsprntf): Use cygthread::name rather than threadname.
* window.cc (gethwnd): Use cygthread method to initialize thread.
2002-08-01 16:20:31 +00:00