File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -213,30 +213,29 @@ int pthread_setcancelstate(int state, int *oldstate)
213
213
int pthread_cancel (pthread_t pthread )
214
214
{
215
215
struct posix_thread * thread = (struct posix_thread * ) pthread ;
216
+ int cancel_state ;
216
217
217
218
if (thread == NULL || thread -> state == PTHREAD_TERMINATED ) {
218
219
return ESRCH ;
219
220
}
220
221
221
222
pthread_mutex_lock (& thread -> cancel_lock );
222
223
thread -> cancel_pending = 1 ;
224
+ cancel_state = thread -> cancel_state ;
225
+ pthread_mutex_unlock (& thread -> cancel_lock );
223
226
224
- if (thread -> cancel_state == PTHREAD_CANCEL_ENABLE ) {
227
+ if (cancel_state == PTHREAD_CANCEL_ENABLE ) {
228
+ pthread_mutex_lock (& thread -> state_lock );
225
229
if (thread -> state == PTHREAD_DETACHED ) {
226
230
thread -> state = PTHREAD_TERMINATED ;
227
- pthread_mutex_unlock (& thread -> cancel_lock );
228
231
} else {
229
232
thread -> retval = PTHREAD_CANCELED ;
230
- pthread_mutex_unlock (& thread -> cancel_lock );
231
- pthread_mutex_lock (& thread -> state_lock );
232
233
thread -> state = PTHREAD_EXITED ;
233
234
pthread_cond_broadcast (& thread -> state_cond );
234
- pthread_mutex_unlock (& thread -> state_lock );
235
235
}
236
+ pthread_mutex_unlock (& thread -> state_lock );
236
237
237
238
k_thread_abort ((k_tid_t ) thread );
238
- } else {
239
- pthread_mutex_unlock (& thread -> cancel_lock );
240
239
}
241
240
242
241
return 0 ;
You can’t perform that action at this time.
0 commit comments