1 |
/* Thread termination. |
/* Thread termination. |
2 |
Copyright (C) 2000,02 Free Software Foundation, Inc. |
Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. |
3 |
This file is part of the GNU C Library. |
This file is part of the GNU C Library. |
4 |
|
|
5 |
The GNU C Library is free software; you can redistribute it and/or |
The GNU C Library is free software; you can redistribute it and/or |
35 |
struct __pthread *self = _pthread_self (); |
struct __pthread *self = _pthread_self (); |
36 |
struct __pthread_cancelation_handler **handlers; |
struct __pthread_cancelation_handler **handlers; |
37 |
int oldstate; |
int oldstate; |
38 |
|
int need_dealloc; |
39 |
|
|
40 |
/* Run any cancelation handlers. According to POSIX, the |
/* Run any cancelation handlers. According to POSIX, the |
41 |
cancellation cleanup handlers should be called with cancellation |
cancellation cleanup handlers should be called with cancellation |
70 |
if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending) |
if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending) |
71 |
status = PTHREAD_CANCELED; |
status = PTHREAD_CANCELED; |
72 |
|
|
73 |
|
__pthread_thread_dealloc (self); |
74 |
|
|
75 |
switch (self->state) |
switch (self->state) |
76 |
{ |
{ |
77 |
default: |
default: |
78 |
assert (! "This cannot happen!"); |
assert (! "Consistency error: unexpected self->state"); |
79 |
|
abort (); |
80 |
break; |
break; |
81 |
|
|
82 |
case PTHREAD_DETACHED: |
case PTHREAD_DETACHED: |
86 |
deallocate our own stack. However, it will eventually be |
deallocate our own stack. However, it will eventually be |
87 |
reused when this thread structure is recycled. */ |
reused when this thread structure is recycled. */ |
88 |
__pthread_mutex_unlock (&self->state_lock); |
__pthread_mutex_unlock (&self->state_lock); |
89 |
__pthread_dealloc (self); |
need_dealloc = 1; |
90 |
|
|
91 |
break; |
break; |
92 |
|
|
103 |
waiting to join us. */ |
waiting to join us. */ |
104 |
pthread_cond_broadcast (&self->state_cond); |
pthread_cond_broadcast (&self->state_cond); |
105 |
__pthread_mutex_unlock (&self->state_lock); |
__pthread_mutex_unlock (&self->state_lock); |
106 |
|
need_dealloc = 0; |
107 |
|
|
108 |
break; |
break; |
109 |
} |
} |
113 |
This means that before freeing any resources, such a thread |
This means that before freeing any resources, such a thread |
114 |
should make sure that this thread is really halted. */ |
should make sure that this thread is really halted. */ |
115 |
|
|
116 |
__pthread_thread_halt (self); |
__pthread_thread_halt (self, need_dealloc); |
117 |
|
|
118 |
/* NOTREACHED */ |
/* NOTREACHED */ |
119 |
abort (); |
abort (); |