Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2007-02-22 15:34:55 +0300
committerChristopher Faylor <me@cgf.cx>2007-02-22 15:34:55 +0300
commit39fc0d36aefea70fa97addbeaf1f8e9ac0fa8232 (patch)
tree7348ac2619d9f419119ca4d8f2c4b8531947ce2d /winsup/cygwin/thread.cc
parentbd8f891e8ac6ec88bc72cd8c446b6ccba5750821 (diff)
* dcrt0.cc (child_info_fork::alloc_stack_hard_way): Change sense of guard test.
Increase size of stack reserved and increase size before the current stack pointer. Use pointers when doing arithmetic. (dll_crt0_1): Initialize exception handler when we notice we're the child of a fork from non-main thread. * fork.cc (frok::parent): Make argument volatile. (frok::child): Ditto. (lock_signals): New class. (lock_pthread): Ditto. (hold_everhthing): Ditto. (frok::parent): Move atforkprepare and atforkparent to lock_pthread class. (fork): Make ischild boolean. Use hold_everything variable within limited scope to set various mutexes in such a way as to avoid deadlocks. * thread.h (pthread_mutex::tid): New variable, active when debugging for tracking thread id of owner. (pthread_mutex::set_owner): Set tid when debugging. * thread.cc (pthread_mutex::pthread_mutex): Clear tid. (pthread_mutex::_unlock): Ditto when unlocking. (pthread_mutex::fixup_after_fork): Set tid to special value after forking since owner is unknown.
Diffstat (limited to 'winsup/cygwin/thread.cc')
-rw-r--r--winsup/cygwin/thread.cc33
1 files changed, 24 insertions, 9 deletions
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index fc29fc19a..936d9a55c 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -1,9 +1,7 @@
/* thread.cc: Locking and threading module functions
- Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Red Hat, Inc.
-
- Originally written by Marco Fuykschot <marco@ddi.nl>
- Substantialy enhanced by Robert Collins <rbtcollins@hotmail.com>
+ Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+ 2006, 2007 Red Hat, Inc.
This file is part of Cygwin.
@@ -1599,7 +1597,11 @@ pthread_mutex::pthread_mutex (pthread_mutexattr *attr) :
verifyable_object (PTHREAD_MUTEX_MAGIC),
lock_counter (0),
win32_obj_id (NULL), recursion_counter (0),
- condwaits (0), owner (NULL), type (PTHREAD_MUTEX_ERRORCHECK),
+ condwaits (0), owner (NULL),
+#ifdef DEBUGGING
+ tid (0),
+#endif
+ type (PTHREAD_MUTEX_ERRORCHECK),
pshared (PTHREAD_PROCESS_PRIVATE)
{
win32_obj_id = ::CreateSemaphore (&sec_none_nih, 0, LONG_MAX, NULL);
@@ -1680,6 +1682,9 @@ pthread_mutex::_unlock (pthread_t self)
if (--recursion_counter == 0)
{
owner = NULL;
+#ifdef DEBUGGING
+ tid = 0;
+#endif
if (InterlockedDecrement ((long *)&lock_counter))
// Another thread is waiting
::ReleaseSemaphore (win32_obj_id, 1, NULL);
@@ -1713,11 +1718,21 @@ pthread_mutex::_fixup_after_fork ()
api_fatal ("pthread_mutex::_fixup_after_fork () doesn'tunderstand PROCESS_SHARED mutex's");
if (owner == NULL)
- /* mutex has no owner, reset to initial */
- lock_counter = 0;
+ {
+ /* mutex has no owner, reset to initial */
+ lock_counter = 0;
+#ifdef DEBUGGING
+ tid = 0;
+#endif
+ }
else if (lock_counter != 0)
- /* All waiting threads are gone after a fork */
- lock_counter = 1;
+ {
+ /* All waiting threads are gone after a fork */
+ lock_counter = 1;
+#ifdef DEBUGGING
+ tid = 0xffffffff; /* Don't know the tid after a fork */
+#endif
+ }
win32_obj_id = ::CreateSemaphore (&sec_none_nih, 0, LONG_MAX, NULL);
if (!win32_obj_id)