blob: a0b3b509cdf90c4393d5a708e62f09aecee2609f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/*
* exit.c
*
* Description:
* This translation unit implements routines associated with exiting from
* a thread.
*/
#include "pthread.h"
void
pthread_exit(void * value)
{
/* The semantics are such that additional tasks must be done for
strict POSIX conformance. We must add code here later which
deals with executing cleanup handlers and such. For now, the
following is mostly correct: */
int t;
t = _pthread_getthreadindex(pthread_self());
handler = _pthread_threads_table[t]->cleanupstack->first;
/* Run all the cleanup handlers */
while (handler != NULL) {
void (* func)(void *);
void * arg;
_pthread_cleanup_node_t * next;
func = handler->routine;
arg = handler->arg;
_pthread_threads_table[t]->cleanupstack->first = next = handler->next;
free(handler);
(void) func(arg);
}
/* CRITICAL SECTION */
pthread_mutex_lock(&_pthread_count_mutex);
free(_pthread_threads_table[t]->attr);
_pthread_threads_table[t]->thread = NULL;
pthread_mutex_unlock(&_pthread_count_mutex);
/* END CRITICAL SECTION */
_endthreadex((DWORD) value);
}
|