/tmp/cvs610a0efc.1
This commit is contained in:
parent
eceee297d5
commit
e9259cb240
@ -1,3 +1,19 @@
|
|||||||
|
2002-04-18 Thomas Pfaff <tpfaff@gmx.net>
|
||||||
|
|
||||||
|
* thread.h (pthread::joiner): New member.
|
||||||
|
* thread.cc (pthread::pthread): Initialize joiner to NULL
|
||||||
|
(pthread::create): Increment of thread counter moved from
|
||||||
|
__pthread_create to this location.
|
||||||
|
(__pthread_create): Increment thread counter removed.
|
||||||
|
(thread_init_wrapper): Set joiner to self when thread was created
|
||||||
|
detached.
|
||||||
|
(__pthread_exit): delete thread when it is detached and not
|
||||||
|
joined.
|
||||||
|
(__pthread_join): Check for deadlock and delete thread when it has
|
||||||
|
terminated.
|
||||||
|
(__pthread_detach): Set joiner to self when thread state
|
||||||
|
changed to detached.
|
||||||
|
|
||||||
2002-06-05 Corinna Vinschen <corinna@vinschen.de>
|
2002-06-05 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* grp.cc (read_etc_group): When emulating nonexisting group file on
|
* grp.cc (read_etc_group): When emulating nonexisting group file on
|
||||||
|
@ -344,7 +344,7 @@ MTinterface::fixup_after_fork (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0),
|
pthread::pthread ():verifyable_object (PTHREAD_MAGIC), win32_obj_id (0),
|
||||||
cancelstate (0), canceltype (0)
|
cancelstate (0), canceltype (0), joiner(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,6 +381,7 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
|
|||||||
magic = 0;
|
magic = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
InterlockedIncrement (&MT_INTERFACE->threadcount);
|
||||||
/*FIXME: set the priority appropriately for system contention scope */
|
/*FIXME: set the priority appropriately for system contention scope */
|
||||||
if (attr.inheritsched == PTHREAD_EXPLICIT_SCHED)
|
if (attr.inheritsched == PTHREAD_EXPLICIT_SCHED)
|
||||||
{
|
{
|
||||||
@ -908,6 +909,10 @@ thread_init_wrapper (void *_arg)
|
|||||||
/*the OS doesn't check this for <= 64 Tls entries (pre win2k) */
|
/*the OS doesn't check this for <= 64 Tls entries (pre win2k) */
|
||||||
TlsSetValue (MT_INTERFACE->thread_self_dwTlsIndex, thread);
|
TlsSetValue (MT_INTERFACE->thread_self_dwTlsIndex, thread);
|
||||||
|
|
||||||
|
// if thread is detached force cleanup on exit
|
||||||
|
if (thread->attr.joinable == PTHREAD_CREATE_DETACHED)
|
||||||
|
thread->joiner = __pthread_self();
|
||||||
|
|
||||||
#ifdef _CYG_THREAD_FAILSAFE
|
#ifdef _CYG_THREAD_FAILSAFE
|
||||||
if (_REENT == _impure_ptr)
|
if (_REENT == _impure_ptr)
|
||||||
system_printf ("local storage for thread isn't setup correctly");
|
system_printf ("local storage for thread isn't setup correctly");
|
||||||
@ -945,7 +950,6 @@ __pthread_create (pthread_t *thread, const pthread_attr_t *attr,
|
|||||||
*thread = NULL;
|
*thread = NULL;
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
}
|
}
|
||||||
InterlockedIncrement (&MT_INTERFACE->threadcount);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1491,11 +1495,16 @@ __pthread_attr_destroy (pthread_attr_t *attr)
|
|||||||
void
|
void
|
||||||
__pthread_exit (void *value_ptr)
|
__pthread_exit (void *value_ptr)
|
||||||
{
|
{
|
||||||
class pthread *thread = __pthread_self ();
|
pthread_t thread = __pthread_self ();
|
||||||
|
|
||||||
MT_INTERFACE->destructors.IterateNull ();
|
MT_INTERFACE->destructors.IterateNull ();
|
||||||
|
|
||||||
thread->return_ptr = value_ptr;
|
// cleanup if thread is in detached state and not joined
|
||||||
|
if( __pthread_equal(&thread->joiner, &thread ) )
|
||||||
|
delete thread;
|
||||||
|
else
|
||||||
|
thread->return_ptr = value_ptr;
|
||||||
|
|
||||||
if (InterlockedDecrement (&MT_INTERFACE->threadcount) == 0)
|
if (InterlockedDecrement (&MT_INTERFACE->threadcount) == 0)
|
||||||
exit (0);
|
exit (0);
|
||||||
else
|
else
|
||||||
@ -1505,6 +1514,8 @@ __pthread_exit (void *value_ptr)
|
|||||||
int
|
int
|
||||||
__pthread_join (pthread_t *thread, void **return_val)
|
__pthread_join (pthread_t *thread, void **return_val)
|
||||||
{
|
{
|
||||||
|
pthread_t joiner = __pthread_self();
|
||||||
|
|
||||||
/*FIXME: wait on the thread cancellation event as well - we are a cancellation point*/
|
/*FIXME: wait on the thread cancellation event as well - we are a cancellation point*/
|
||||||
if (verifyable_object_isvalid (thread, PTHREAD_MAGIC) != VALID_OBJECT)
|
if (verifyable_object_isvalid (thread, PTHREAD_MAGIC) != VALID_OBJECT)
|
||||||
return ESRCH;
|
return ESRCH;
|
||||||
@ -1512,15 +1523,26 @@ __pthread_join (pthread_t *thread, void **return_val)
|
|||||||
if ((*thread)->attr.joinable == PTHREAD_CREATE_DETACHED)
|
if ((*thread)->attr.joinable == PTHREAD_CREATE_DETACHED)
|
||||||
{
|
{
|
||||||
if (return_val)
|
if (return_val)
|
||||||
*return_val = NULL;
|
*return_val = NULL;
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if( __pthread_equal(thread, &joiner ) )
|
||||||
|
{
|
||||||
|
if (return_val)
|
||||||
|
*return_val = NULL;
|
||||||
|
return EDEADLK;
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
|
(*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
|
||||||
|
(*thread)->joiner = joiner;
|
||||||
WaitForSingleObject ((*thread)->win32_obj_id, INFINITE);
|
WaitForSingleObject ((*thread)->win32_obj_id, INFINITE);
|
||||||
if (return_val)
|
if (return_val)
|
||||||
*return_val = (*thread)->return_ptr;
|
*return_val = (*thread)->return_ptr;
|
||||||
|
// cleanup
|
||||||
|
delete (*thread);
|
||||||
} /*End if */
|
} /*End if */
|
||||||
|
|
||||||
pthread_testcancel ();
|
pthread_testcancel ();
|
||||||
@ -1536,11 +1558,13 @@ __pthread_detach (pthread_t *thread)
|
|||||||
|
|
||||||
if ((*thread)->attr.joinable == PTHREAD_CREATE_DETACHED)
|
if ((*thread)->attr.joinable == PTHREAD_CREATE_DETACHED)
|
||||||
{
|
{
|
||||||
(*thread)->return_ptr = NULL;
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
|
(*thread)->attr.joinable = PTHREAD_CREATE_DETACHED;
|
||||||
|
// force cleanup on exit
|
||||||
|
(*thread)->joiner = *thread;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +239,7 @@ public:
|
|||||||
void *return_ptr;
|
void *return_ptr;
|
||||||
bool suspended;
|
bool suspended;
|
||||||
int cancelstate, canceltype;
|
int cancelstate, canceltype;
|
||||||
|
pthread_t joiner;
|
||||||
// int joinable;
|
// int joinable;
|
||||||
|
|
||||||
DWORD GetThreadId ()
|
DWORD GetThreadId ()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user