1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #include <errno.h> |
---|
6 | #include <limits.h> |
---|
7 | #include <pthread.h> |
---|
8 | #include <string.h> |
---|
9 | |
---|
10 | #include <rtems/system.h> |
---|
11 | #include <rtems/score/thread.h> |
---|
12 | #include <rtems/score/wkspace.h> |
---|
13 | #include <rtems/posix/key.h> |
---|
14 | |
---|
15 | /*PAGE |
---|
16 | * |
---|
17 | * _POSIX_Keys_Run_destructors |
---|
18 | * |
---|
19 | * 17.1.1 Thread-Specific Data Key Create, P1003.1c/Draft 10, p. 163 |
---|
20 | * |
---|
21 | * NOTE: This is the routine executed when a thread exits to |
---|
22 | * run through all the keys and do the destructor action. |
---|
23 | */ |
---|
24 | |
---|
25 | void _POSIX_Keys_Run_destructors( |
---|
26 | Thread_Control *thread |
---|
27 | ) |
---|
28 | { |
---|
29 | unsigned32 index; |
---|
30 | unsigned32 pthread_index; |
---|
31 | unsigned32 pthread_class; |
---|
32 | unsigned32 iterations; |
---|
33 | boolean are_all_null; |
---|
34 | POSIX_Keys_Control *the_key; |
---|
35 | void *value; |
---|
36 | |
---|
37 | pthread_index = _Objects_Get_index( thread->Object.id ); |
---|
38 | pthread_class = _Objects_Get_class( thread->Object.id ); |
---|
39 | |
---|
40 | iterations = 0; |
---|
41 | |
---|
42 | for ( ; ; ) { |
---|
43 | |
---|
44 | are_all_null = TRUE; |
---|
45 | |
---|
46 | for ( index=1 ; index <= _POSIX_Keys_Information.maximum ; index++ ) { |
---|
47 | |
---|
48 | the_key = (POSIX_Keys_Control *) |
---|
49 | _POSIX_Keys_Information.local_table[ index ]; |
---|
50 | |
---|
51 | if ( the_key && the_key->is_active && the_key->destructor ) { |
---|
52 | value = the_key->Values[ pthread_class ][ pthread_index ]; |
---|
53 | if ( value ) { |
---|
54 | (*the_key->destructor)( value ); |
---|
55 | if ( the_key->Values[ pthread_class ][ pthread_index ] ) |
---|
56 | are_all_null = FALSE; |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | if ( are_all_null == TRUE ) |
---|
62 | return; |
---|
63 | |
---|
64 | iterations++; |
---|
65 | |
---|
66 | /* |
---|
67 | * The standard allows one to not do this and thus go into an infinite |
---|
68 | * loop. It seems rude to unnecessarily lock up a system. |
---|
69 | * |
---|
70 | * Reference: 17.1.1.2 P1003.1c/Draft 10, p. 163, line 99. |
---|
71 | */ |
---|
72 | |
---|
73 | if ( iterations >= PTHREAD_DESTRUCTOR_ITERATIONS ) |
---|
74 | return; |
---|
75 | } |
---|
76 | } |
---|