* dcrt0.cc (dll_crt0_1): Add call to pthread::initMainThread to
initialize mainthread when it is safe to call new.
* init.cc (dll_entry): Change call to store reents in tls key.
* thread.cc (_reent_clib) : Change call to get reents from tls
key.
(_reent_winsup): Ditto.
(MTinterface::Init): Key handling changed. Remove initialization
of member variables.
(MTinterface::fixup_after_fork): Reinitialize mainthread object
after fork. Reset threadount to 1.
(pthread::initMainThread): Create mainthread object dynamically.
and initialize with valid handles.
(pthread::self): Remove calls to create thread objects.
(pthread::setTlsSelfPointer): Change call to store thread self
handle in tls key.
(pthread::getTlsSelfPointer): New static method.
(pthread::exit): Remove setTlsSelfPointer call.
(pthread::initCurrentThread): New method.
(pthread::thread_init_wrapper): Change call to store thread self
handle in tls key.
(pthread::join): Check for a valid joiner.
(pthreadNull::pthreadNull): Mark Null object as detached.
(pthreadNull::exit): Terminate thread via ExitThread.
* thread.h (pthread::initMainThread): Change parameter in function
call.
(pthread::getTlsSelfPointer): New static method.
(pthread::initCurrentThread): New method.
(MTinterface::reent_key): Remove.
(MTinterface::thread_self_dwTlsIndex): Ditto..
(MTinterface::indexallocated): Ditto.
(MTinterface::mainthread): Ditto.
(MTinterface::reent_key): New member.
(MTinterface::thread_self_key): Ditto.
(MTinterface::MTinterface): Initialize all members.
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.
Rename _pid() to pid() throughout.
* Makefile.in: Compile some objects with -fomit-frame-pointer.
* cygwin.din: Reverse aliasing for _kill.
* syscalls.cc (_getpid_r): New function, implemented for newlib compatibility.
* shared.cc (open_shared): Remove reserving of memory since previous change
eliminate the need for this hack.
* thread.cc (pthread_key::keys): Copy on fork. Add a comment explaining
why.
(pthreadNull::_instance): Copy on fork. Absolutely no state exists
in pthreadNull.
* thread.cc (pthread_mutex::initMutex): Use the wrapper init call.
(pthread_mutex::nativeMutex::init): Implement.
(pthread_mutex::nativeMutex::lock): Ditto.
(pthread_mutex::nativeMutex::unlock): Ditto.
(pthread_mutex::init): Use the wrapper lock and unlockcalls.
* thread.h (pthread_mutex): Move mutexInitializationLock into a
nativeMutex wrapper class.
* pthread.cc (pthread_mutex_init): Use new pthread_mutex::init.
* thread.cc: Change __pthread_mutex_init to pthread_mutex::init
throughout.
(MTinterface::Init): Initialise pthread_mutex support.
(pthread_mutex::mutexInitializationLock): Instantiate.
(pthread_mutex::initMutex): New method.
(__pthread_cond_dowait): Don't dereference untrusted pointers.
Use the new pthread_mutex::init method.
(__pthread_condattr_init): Don't dereference untrusted pointers.
(__pthread_mutex_init): Rename to pthread_mutex::init.
Lock and release mutexInitializationLock to prevent races on
mutex initialisation.
* thread.h (pthread_mutex::initMutex): New method, initialise
pthread_mutex supporting state on process initialisation.
(pthread_mutex::init): Initialise a single mutex.
(pthread_mutex::mutexInitializationLock): A win32 mutex for
syncronising pthread mutex initialisation.
(__pthread_mutex_init): Remove this.
* thread.cc (pthread_key::run_destructor): Run_destructor is not
const as it needs to set the key value.
* thread.h (pthread_key::run_destructor): Ditto.
2002-09-27 Robert Collins <rbtcollins@hotmail.com>
* thread.cc (pthread_key::run_destructor): Follow opengroup algorithm.
I.e. only run the destructor NON-NULL key values, and reset the key
to NULL before running the destructor. Reported by Thomas Pfaff.
already taken care of that.
* fhandler_console.cc (fhandler_console::open): Initialize handles to NULL.
(fhandler_console::close): Ditto. GNUify non-GNU formatted functions calls
throughout.
* pthread.cc: Use class::call for converted pthread and semaphore
calls.
* thread.cc: Convert various __pthread_call and __sem_call to
pthread::call and sem::call throughout.
* pthread.h (__pthread_cancel): Convert to pthread::cancel.
(__pthread_join): Convert to pthread::join.
(__pthread_detach): Convert to pthread::detach.
(__pthread_create): Convert to pthread::create.
(__pthread_once): Convert to pthread::once.
(__pthread_atfork): Convert to pthread::atfork.
(__pthread_suspend): Convert to pthread::suspend.
(__pthread_continue): Convert to pthread::resume.
(__sem_init): Convert to semaphore::init.
(__sem_destroy): Convert to semaphore::destroy.
(__sem_wait): Convert to semaphore::wait.
(__sem_trywait): Convert to semaphore::trywait.
(__sem_post): Convert to semaphore::post.
* thread.cc: Finish the removal of the separate pthread_key
destructor list.
Remove all pthread_key_destructor and pthread_key_destructor_list
references throughout.
(pthread::exit): Call the new pthread_key interface to activate
destructors.
(pthread_key::keys): Change into a list.
(pthread_key::saveAKey): New method, used via forEach.
(pthread_key::restoreAKey): Ditto.
(pthread_key::destroyAKey): Ditto.
(pthread_key::fixup_before_fork): Use the List::forEach functionality.
(pthread_key::fixup_after_fork): Ditto.
(pthread_key::runAllDestructors): New method implementation.
(pthread_key::pthread_key): Use List::Insert rather than custom list
code.
(pthread_key::~pthread_key): Use List::Remove for the same reason.
* thread.h: Remove all pthread_key_destructor and
pthread_key_destructor_list references throughout.
(List): Move the interface above pthread_key in the header.
Use atomic operations during insert and delete.
(List::forEach): A generic interface for doing something on each node.
(pthread_key::runAllDestructors): New method, run all destructors.
(pthread_key::fork_buf): Make private.
(pthread_key::run_destructor): Ditto.
(pthread_key::saveAKey): New method for clearer source.
(pthread_key::restoreAKey): Ditto.
(pthread_key::destroyAKey): Ditto.
(MTinterface::destructors): Remove.
* thread.cc: Partial refactoring of pthread_key destructor
handling. Loosely based on Thomas Pfaff's work.
(pthread_key_destructor_list::Insert): Remove.
(pthread_key_destructor_list::Pop): Remove.
(pthread_key_destructor_list::IterateNull): Call the key's
run_destructor method.
(pthread_key::pthread_key): Initialize new member.
(pthread_key::get): Mark as const for correctness.
(pthread_key::run_destructor): Implement.
* thread.h (pthread_key::get): Mark as const for correctness.
(pthread_key::run_destructor): Declare.
(List): New template class that implements a generic list.
(pthread_key_destructor_list): Inherit from List, and remove
now duplicate functions.
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.
This work inspires by Thomas Pfaff's pthread_fork patch (1).
* fork.cc (fork_child): Remove MTinterface fixup call, it's
adsorbed by pthread::atforkchild.
Rename __pthread_atforkchild to pthread::atforkchild to give
access to private members.
(fork_parent): Rename __pthread_atforkparent to
pthread::atforkparent to give it access to private members.
Ditto for __pthread_atforkprepare.
* thread.cc: Fix some formatting problems throughout.
(MTinterface::fixup_before_fork): Implement.
(MTinterface::fixup_after_fork): Fix pthread_keys.
(pthread_key::keys): Implement.
(pthread_key::fixup_before_fork): Ditto.
(pthread_key::fixup_after_fork): Ditto.
(pthread_key::pthread_key): Add to pthread_key::keys.
(pthread_key::~pthread_key): Remove from pthread_key::keys.
(pthread_key::saveKeyToBuffer): Implement.
(pthread_key::recreateKeyFromBuffer): Ditto.
(pthread::atforkprepare): Prepare all MT classes for fork.
(pthread::atforkchild): And fix them up afterwards.
* thread.h (pthread_key): Buffer the key value during
fork in fork_buf.
List the keys needing to be fixed up in a linked list with
head pthread_key::keys.
(pthread): Move atfork cygwin internal calls into the class.
(MTInterface): Provide a fixup_before_fork for objecst that
need to save state.
(__pthread_atforkprepare): Remove.
(__pthread_atforkparent): Remove.
(__pthread_atforkchild): Remove.
* init.cc (dll_entry): On thread detach, if the thread hasn't
exit()ed, do so.
* pthread.cc (pthread_getsequence_np): Remove the
__pthread_getsequence_np wrapper. This requires errno.h.
* thread.cc (pthread::self): Instantiate a new pthread object
when called and none exists. return a NULL object if instantiation
fails.
(pthread::precreate): Factor out common code.
(pthread::postcreate): Ditto.
(pthread::create): Ditto.
(pthread::exit): Remove the TLS value when we exit to prevent
double exits.
(MTinterface::Init): Bugfix - don't mark the TLS index as created
if one was not allocated.
Apply Extract Method to move pthread specific initialisation into
pthread.
(pthread::initMainThread): Extracted method from MTinterface::Init.
(pthread::setTlsSelfPointer): Extracted method from various pthread
calls, to make reading those functions easier.
(pthread::setThreadIdtoCurrent): Ditto.
(pthread::cancel_self): Bring into the .cc file, it's only used
within the class.
(pthread::getThreadId): Ditto.
(pthread::thread_init_wrapper): Apply Extract Method to the TLS
setting logic.
(pthread::isGoodObject): Extracted method from various pthread
wrapper calls, for clarity of reading.
(pthread::getsequence_np): Converted from __pthread_getsquence_np.
(__pthread_create): Apply Extract Method to the object validation.
(__pthread_cancel): Ditto.
(__pthread_join): Ditto.
(__pthread_detach): Ditto.
(__pthread_suspend): Ditto.
(__pthread_continue): Ditto.
(__pthread_getschedparam): Ditto.
(__pthread_getsequence_np): Remove.
(__pthread_setschedparam): Apply Extract Method to the object
validation.
(pthreadNull::getNullpthread): New method, return the pthreadNull
object.
(pthreadNull::pthreadNull): Private constructor to prevent accidental
use.
(pthreadNull::~pthreadNull): Prevent compile warnings.
(pthreadNull::create): Override pthread behaviour.
(pthreadNull::exit): Ditto.
(pthreadNull::cancel): Ditto.
(pthreadNull::testcancel): Ditto.
(pthreadNull::setcancelstate): Ditto.
(pthreadNull::setcanceltype): Ditto.
(pthreadNull::push_cleanup_handler): Ditto.
(pthreadNull::pop_cleanup_handler): Ditto.
(pthreadNull::getsequence_np): Ditto.
(pthreadNull::_instance): Ditto.
* thread.h (pthread): Declare pre- and post-create.
Move GetThreadId to private scope and rename to getThreadId.
Move setThreadIdtoCurrent to private scope.
Make create virtual.
Make ~pthread virtual.
Declare initMainThread.
Declare isGoodObject.
Make exit virtual.
Make cancel virtual.
Make testcancel virtual.
Make setcancelstate virtual.
Make setcanceltype virtual.
Make push_cleanup_handler virtual.
Make pop_cleanup_handler virtual.
Declare getsequence_np.
Declare setTlsSelfPointer.
(pthreadNull): New null object class for pthread.
(__pthread_getsequence_np): Remove.
* thread.h (pthread::cleanup_stack): Renamed cleanup_handlers to
cleanup_stack.
* thread.cc (pthread::pthread): Ditto.
(pthread::create): Fixed mutex verification.
(pthread::push_cleanup_handler): Renamed cleanup_handlers to
cleanup_stack.
Mutex calls removed, used InterlockedExchangePointer instead.
(pthread::pop_cleanup_handler): Renamed cleanup_handlers to
cleanup_stack.
(pthread::pop_all_cleanup_handlers): Ditto.
(__pthread_once): Check state first and return if already done.
(__pthread_join): DEADLOCK test reverted to __pthread_equal
call.
(__pthread_detach): Unlock mutex before deletion.
(cygheap_user::env_logsrv): Verify env_domain is valid.
* environ.cc: Include child_info.h and keep spenvs[] sorted.
(environ_init): Check child_proc_info instead of myself->ppid_handle.
* cygwin.din: Add _pthread_cleanup_push and _pthread_cleanup_pop.
* pthread.cc: Change __pthread_self to pthread::self() thruoghout.
(_pthread_cleanup_push): New function.
(_pthread_cleanup_pop): Ditto.
* thread.cc: Thanks to Thomas Pfaff for the pthread cleanup_push,_pop
patch, this work is derived from that.
Change __pthread_self to pthread::self() thruoghout.
(__pthread_self): Rename to pthread::self.
(pthread::self): New method.
(pthread::pthread): Initialize new member.
(pthread::push_cleanup_handler): New method.
(pthread::pop_cleanup_handler): New method.
(pthread::pop_all_cleanup_handlers): New method.
(__pthread_exit): Pop all cleanup handlers.
* thread.h (pthread::push_cleanup_handler): Declare.
(pthread::pop_cleanup_handler): Ditto.
(pthread::pop_all_cleanup_handlers): Ditto.
(pthread::self): New static method.
(__pthread_exit): Give C++ linkage.
(__pthread_join): Ditto.
(__pthread_detach): Ditto.
(__pthread_self): Remove.
2002-04-24 Thomas Pfaff <tpfaff@gmx.net>
* include/pthread.h (__pthread_cleanup_handler): New structure
(pthread_cleanup_push): Rewritten .
(pthread_cleanup_pop): Ditto.
(_pthread_cleanup_push): New prototype.
(_pthread_cleanup_pop) Ditto.
2002-04-24 Thomas Pfaff <tpfaff@gmx.net>
* thread.cc (thread_init_wrapper): Check if thread is already joined.
(__pthread_join): Set joiner first.
(__pthread_detach): Ditto.
* fhandler.h (fhandler_proc::fill_filebuf): Take a pinfo argument.
* fhandler_proc.cc (fhandler_proc::get_proc_fhandler): Simplify search for
given pid.
(fhandler_proc::readdir): Assume that pid exists if it shows up in the winpid
list.
* fhandler_process.cc (fhandler_process::open): Simplify search for given pid.
Call fill_filebuf with pinfo argument.
(fhandler_process::fill_filebuf): Pass pinfo here and assume that it exists.
* pinfo.h (pinfo::remember): Define differently if sigproc.h is not included.
* dll_init.cc (dll_list::detach): Don't run destructor on exit.
where appropriate, throughout. Remove unneeded exceptions.h, where
appropriate, throughout. Remove unneeded perprocess.h, where appropriate,
throughout.
* thread.cc (__pthread_cond_dowait): Fix a race on signalling from a
thread woken by the same condition variable it's signalling on. Thanks
to Michael Beach for the report and test case.
* thread.cc (pthread_cond::Signal): Use a separate flag for signal detection
and broadcast semantics.
(__pthread_cond_dowait): Ditto.
* thread.h (pthread_cond): New flag for testing when a waiter has woken.